Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 58ebacf

Browse files
schlndhondrejmirtes
authored andcommitted
fix fn() => __FUNCTION__ and __METHOD__
1 parent a06d509 commit 58ebacf

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

‎src/Analyser/MutatingScope.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3181,7 +3181,7 @@ private function enterArrowFunctionWithoutReflection(Expr\ArrowFunction $arrowFu
31813181
$arrowFunctionScope->nativeExpressionTypes,
31823182
$arrowFunctionScope->conditionalExpressions,
31833183
$arrowFunctionScope->inClosureBindScopeClasses,
3184-
null,
3184+
newTrivialParametersAcceptor(),
31853185
true,
31863186
[],
31873187
[],

‎tests/PHPStan/Analyser/NodeScopeResolverTest.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,7 @@ public function dataFileAsserts(): iterable
11231123

11241124
if (PHP_VERSION_ID >= 70400) {
11251125
yield from $this->gatherAssertTypes(__DIR__ . '/data/arrow-function-argument-type.php');
1126+
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Functions/data/bug-anonymous-function-method-constant.php');
11261127
}
11271128

11281129
yield from $this->gatherAssertTypes(__DIR__ . '/data/closure-argument-type.php');

‎tests/PHPStan/Rules/Functions/ArrowFunctionReturnTypeRuleTest.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,13 @@ public function testBugSpaceship(): void
6565
$this->analyse([__DIR__ . '/data/bug-spaceship.php'], []);
6666
}
6767

68+
public function testBugFunctionMethodConstants(): void
69+
{
70+
if (PHP_VERSION_ID < 70400) {
71+
$this->markTestSkipped('Test requires PHP 7.4.');
72+
}
73+
74+
$this->analyse([__DIR__ . '/data/bug-anonymous-function-method-constant.php'], []);
75+
}
76+
6877
}

‎tests/PHPStan/Rules/Functions/ClosureReturnTypeRuleTest.php‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PHPStan\Rules\Rule;
77
use PHPStan\Rules\RuleLevelHelper;
88
use PHPStan\Testing\RuleTestCase;
9+
use const PHP_VERSION_ID;
910

1011
/**
1112
* @extends RuleTestCase<ClosureReturnTypeRule>
@@ -128,4 +129,13 @@ public function testBug7220(): void
128129
$this->analyse([__DIR__ . '/data/bug-7220.php'], []);
129130
}
130131

132+
public function testBugFunctionMethodConstants(): void
133+
{
134+
if (PHP_VERSION_ID < 70400) {
135+
$this->markTestSkipped('Test requires PHP 7.4.');
136+
}
137+
138+
$this->analyse([__DIR__ . '/data/bug-anonymous-function-method-constant.php'], []);
139+
}
140+
131141
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php declare(strict_types = 1); // lint >= 7.4
2+
3+
namespace BugAnonymousFunctionMethodConstant;
4+
5+
$a = fn() => __FUNCTION__;
6+
$b = fn() => __METHOD__;
7+
8+
$c = function() { return __FUNCTION__; };
9+
$d = function() { return __METHOD__; };
10+
11+
\PHPStan\Testing\assertType("'{closure}'", $a());
12+
\PHPStan\Testing\assertType("'{closure}'", $b());
13+
\PHPStan\Testing\assertType("'{closure}'", $c());
14+
\PHPStan\Testing\assertType("'{closure}'", $d());

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /