Skip to content

Commit be279db

Browse files
committed
Scope::getFunctionCallStack - keep after entering anonymous function
1 parent 9be1376 commit be279db

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/Analyser/MutatingScope.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,7 +2926,7 @@ public function enterAnonymousFunction(
29262926
true,
29272927
[],
29282928
[],
2929-
[],
2929+
$this->inFunctionCallsStack,
29302930
false,
29312931
$this,
29322932
$this->nativeTypesPromoted,
@@ -3105,7 +3105,7 @@ public function enterArrowFunction(Expr\ArrowFunction $arrowFunction, ?array $ca
31053105
true,
31063106
[],
31073107
[],
3108-
[],
3108+
$this->inFunctionCallsStack,
31093109
$scope->afterExtractCall,
31103110
$scope->parentScope,
31113111
$this->nativeTypesPromoted,

tests/PHPStan/Rules/ScopeFunctionCallStackRuleTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ public function testRule(): void
2727
"var_dump\nprint_r\nsleep",
2828
7,
2929
],
30+
[
31+
"var_dump\nprint_r\nsleep",
32+
10,
33+
],
34+
[
35+
"var_dump\nprint_r\nsleep",
36+
13,
37+
],
3038
]);
3139
}
3240

tests/PHPStan/Rules/data/scope-function-call-stack.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,10 @@
55
function (): void
66
{
77
var_dump(print_r(sleep(throw new \Exception())));
8+
9+
var_dump(print_r(function () {
10+
sleep(throw new \Exception());
11+
}));
12+
13+
var_dump(print_r(fn () => sleep(throw new \Exception())));
814
};

0 commit comments

Comments
 (0)