Skip to content

Commit 0b2855e

Browse files
committed
Cleanup
1 parent 7a24c23 commit 0b2855e

3 files changed

Lines changed: 17 additions & 39 deletions

File tree

‎src/Analyser/MutatingScope.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ protected function findSettledStoredResult(Expr $node): ?ExpressionResult
14581458
return null;
14591459
}
14601460

1461-
return $this->container->getByType(NodeScopeResolver::class)->findSettledExpressionResult($storage, $node);
1461+
return $storage->findExpressionResult($node);
14621462
}
14631463

14641464
public function getCurrentExpressionResultStorage(): ?ExpressionResultStorage

‎src/Analyser/NodeScopeResolver.php‎

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -204,30 +204,6 @@ public function processNodes(
204204
}
205205
}
206206

207-
/** The stored result an outside asker may consume. */
208-
public function findSettledExpressionResult(ExpressionResultStorage $storage, Expr $expr): ?ExpressionResult
209-
{
210-
return $storage->findExpressionResult($expr);
211-
}
212-
213-
/** An effect-free result carrying eagerly known types, positioned at the given scope. */
214-
protected function createEagerExpressionResult(MutatingScope $scope, Expr $expr, Type $type, Type $nativeType): ExpressionResult
215-
{
216-
return $this->expressionResultFactory->create(
217-
$scope,
218-
beforeScope: $scope,
219-
expr: $expr,
220-
hasYield: false,
221-
isAlwaysTerminating: false,
222-
throwPoints: [],
223-
impurePoints: [],
224-
typeCallback: null,
225-
specifyTypesCallback: SpecifiedTypes::emptySpecifyCallback(),
226-
type: $type,
227-
nativeType: $nativeType,
228-
);
229-
}
230-
231207
public function storeExpressionResult(ExpressionResultStorage $storage, Expr $expr, ExpressionResult $expressionResult): void
232208
{
233209
if (self::$guardNewWorld) {
@@ -506,7 +482,20 @@ public function processExprOnDemand(Expr $expr, MutatingScope $scope, Expression
506482
ExprHandlerRegistry::resolve($expr, $this->container) === null
507483
&& !($expr instanceof Expr\CallLike && $expr->isFirstClassCallable())
508484
) {
509-
return $this->createEagerExpressionResult($scope, $expr, new MixedType(), new MixedType());
485+
$mixed = new MixedType();
486+
return $this->expressionResultFactory->create(
487+
$scope,
488+
beforeScope: $scope,
489+
expr: $expr,
490+
hasYield: false,
491+
isAlwaysTerminating: false,
492+
throwPoints: [],
493+
impurePoints: [],
494+
typeCallback: null,
495+
specifyTypesCallback: SpecifiedTypes::emptySpecifyCallback(),
496+
type: $mixed,
497+
nativeType: $mixed,
498+
);
510499
}
511500

512501
// save/restore, never reset: on-demand walks nest (a typeCallback
@@ -532,18 +521,6 @@ public function processExprOnDemand(Expr $expr, MutatingScope $scope, Expression
532521
}
533522
}
534523

535-
/**
536-
* Processes an expression for an independent analysis pass - a reflection-
537-
* level lazy computation that builds its own scope from scratch (e.g.
538-
* private property type inference from constructor assignments). Such a
539-
* pass legitimately prices real AST nodes outside the file's main walk,
540-
* on a fresh storage of its own.
541-
*/
542-
public function processIndependentPassExpr(Expr $expr, MutatingScope $scope): ExpressionResult
543-
{
544-
return $this->processExprOnDemand($expr, $scope, new ExpressionResultStorage());
545-
}
546-
547524
/**
548525
* The stored ExpressionResult of a node processExprNode() already processed
549526
* into the given storage - the caller asserts the processing order by

‎src/Reflection/Php/PhpClassReflectionExtension.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpParser\Node\Stmt\ClassMethod;
88
use PhpParser\Node\Stmt\Declare_;
99
use PhpParser\Node\Stmt\Namespace_;
10+
use PHPStan\Analyser\ExpressionResultStorage;
1011
use PHPStan\Analyser\NodeScopeResolver;
1112
use PHPStan\Analyser\OutOfClassScope;
1213
use PHPStan\Analyser\PhpDocsResolver;
@@ -1239,7 +1240,7 @@ private function inferAndCachePropertyTypes(
12391240

12401241
// an independent lazy pass on its own scope - never read through
12411242
// Scope::getType(), which is reserved for the file's main walk
1242-
$propertyType = $this->nodeScopeResolver->processIndependentPassExpr($expr->expr, $methodScope)->getType();
1243+
$propertyType = $this->nodeScopeResolver->processExprOnDemand($expr->expr, $methodScope, new ExpressionResultStorage())->getType();
12431244
if ($propertyType instanceof ErrorType || $propertyType instanceof NeverType) {
12441245
continue;
12451246
}

0 commit comments

Comments
 (0)