Skip to content

Commit

Permalink
Scope::getFunctionCallStack - keep after entering anonymous function
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 7, 2024
1 parent 9be1376 commit be279db
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -2926,7 +2926,7 @@ public function enterAnonymousFunction(
true,
[],
[],
[],
$this->inFunctionCallsStack,
false,
$this,
$this->nativeTypesPromoted,
Expand Down Expand Up @@ -3105,7 +3105,7 @@ public function enterArrowFunction(Expr\ArrowFunction $arrowFunction, ?array $ca
true,
[],
[],
[],
$this->inFunctionCallsStack,
$scope->afterExtractCall,
$scope->parentScope,
$this->nativeTypesPromoted,
Expand Down
8 changes: 8 additions & 0 deletions tests/PHPStan/Rules/ScopeFunctionCallStackRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public function testRule(): void
"var_dump\nprint_r\nsleep",
7,
],
[
"var_dump\nprint_r\nsleep",
10,
],
[
"var_dump\nprint_r\nsleep",
13,
],
]);
}

Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Rules/data/scope-function-call-stack.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
function (): void
{
var_dump(print_r(sleep(throw new \Exception())));

var_dump(print_r(function () {
sleep(throw new \Exception());
}));

var_dump(print_r(fn () => sleep(throw new \Exception())));
};

0 comments on commit be279db

Please sign in to comment.