Skip to content

Commit a946292

Browse files
committed
NoopNodeCallback
1 parent 53ddd1a commit a946292

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

src/Analyser/Generator/ExprHandler/AssignHandler.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use PHPStan\Analyser\Generator\GeneratorScope;
3030
use PHPStan\Analyser\Generator\InternalThrowPoint;
3131
use PHPStan\Analyser\Generator\NodeCallbackRequest;
32+
use PHPStan\Analyser\Generator\NoopNodeCallback;
3233
use PHPStan\Analyser\Generator\TypeExprRequest;
3334
use PHPStan\Analyser\Generator\TypeExprResult;
3435
use PHPStan\Analyser\ImpurePoint;
@@ -338,9 +339,7 @@ private function processStmtVarAnnotation(GeneratorScope $scope, Node\Stmt $stmt
338339
yield new NodeCallbackRequest(new VarTagChangedExpressionTypeNode($varTag, $variableNode), $scope);
339340
}
340341

341-
// todo NoopExprAnalysisRequest
342-
$variableNodeResult = yield new ExprAnalysisRequest($stmt, $variableNode, $scope, ExpressionContext::createDeep(), static function () {
343-
});
342+
$variableNodeResult = yield new ExprAnalysisRequest($stmt, $variableNode, $scope, ExpressionContext::createDeep(), new NoopNodeCallback());
344343

345344
$assignVarGen = $scope->assignVariable(
346345
$name,
@@ -640,14 +639,12 @@ private function processAssignVar(
640639
}
641640

642641
if (!$varType->isArray()->yes() && !(new ObjectType(ArrayAccess::class))->isSuperTypeOf($varType)->no()) {
643-
// todo NoopExprAnalysisRequest
644642
$throwPoints = array_merge($throwPoints, (yield new ExprAnalysisRequest(
645643
$stmt,
646644
new MethodCall($var, 'offsetSet'),
647645
$scope,
648646
$context,
649-
static function (): void {
650-
},
647+
new NoopNodeCallback(),
651648
))->throwPoints);
652649
}
653650

@@ -758,14 +755,12 @@ static function (): void {
758755
$scope = $assignExprGen->getReturn();
759756
// simulate dynamic property assign by __set to get throw points
760757
if (!$propertyHolderType->hasMethod('__set')->no()) {
761-
// todo NoopExprAnalysisRequest
762758
$throwPoints = array_merge($throwPoints, (yield new ExprAnalysisRequest(
763759
$stmt,
764760
new MethodCall($var->var, '__set'),
765761
$scope,
766762
$context,
767-
static function (): void {
768-
},
763+
new NoopNodeCallback(),
769764
))->throwPoints);
770765
}
771766
}
@@ -975,8 +970,7 @@ static function (GeneratorScope $scope): Generator {
975970
}
976971

977972
// 1. eval root expr
978-
$varResult = yield new ExprAnalysisRequest($stmt, $var, $scope, $context->enterDeep(), static function () {
979-
}); // todo Noop...
973+
$varResult = yield new ExprAnalysisRequest($stmt, $var, $scope, $context->enterDeep(), new NoopNodeCallback());
980974
$hasYield = $varResult->hasYield;
981975
$throwPoints = $varResult->throwPoints;
982976
$impurePoints = $varResult->impurePoints;

src/Analyser/Generator/GeneratorNodeScopeResolver.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ static function (Node $node, Scope $scope) use ($alternativeNodeCallback, $nodeC
256256
throw new ShouldNotHappenException('Pending fibers with an empty stack should be about synthetic nodes');
257257
}
258258

259-
// todo NoopExprAnalysisRequest
259+
// todo problem with noop callback
260260
$this->processStmtNodes(
261261
$fibersStorage,
262262
$exprAnalysisResultStorage,
@@ -352,7 +352,12 @@ private function analyseStmt(Stmt $stmt, GeneratorScope $scope, StatementContext
352352
*/
353353
private function analyseExpr(ExprAnalysisResultStorage $storage, Stmt $stmt, Expr $expr, GeneratorScope $scope, ExpressionContext $context, ?callable $alternativeNodeCallback): Generator
354354
{
355-
if ($storage->findExprAnalysisResult($expr) !== null) {
355+
$foundExprAnalysisResult = $storage->findExprAnalysisResult($expr);
356+
if ($foundExprAnalysisResult !== null) {
357+
if ($alternativeNodeCallback instanceof NoopNodeCallback) {
358+
return $foundExprAnalysisResult;
359+
}
360+
356361
throw new ShouldNotHappenException(sprintf('Expr %s on line %d has already been analysed', $this->exprPrinter->printExpr($expr), $expr->getStartLine()));
357362
}
358363

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Analyser\Generator;
4+
5+
use PhpParser\Node;
6+
use PHPStan\Analyser\Scope;
7+
8+
final class NoopNodeCallback
9+
{
10+
11+
/**
12+
* @param callable(Node, Scope): void $nodeCallback
13+
*/
14+
public function __invoke(Node $node, Scope $scope, callable $nodeCallback): void
15+
{
16+
}
17+
18+
}

0 commit comments

Comments
 (0)