Skip to content

Commit f3c3b44

Browse files
committed
MutatingScope - extract exprStringToExpr
1 parent 32353a9 commit f3c3b44

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/Analyser/MutatingScope.php

+16-9
Original file line numberDiff line numberDiff line change
@@ -3593,17 +3593,10 @@ public function invalidateExpression(Expr $expressionToInvalidate, bool $require
35933593
$nodeFinder = new NodeFinder();
35943594
foreach (array_keys($moreSpecificTypeHolders) as $exprString) {
35953595
$exprString = (string) $exprString;
3596-
3597-
try {
3598-
$expr = $this->parser->parseString('<?php ' . $exprString . ';')[0];
3599-
} catch (ParserErrorsException) {
3596+
$exprExpr = $this->exprStringToExpr($exprString);
3597+
if ($exprExpr === null) {
36003598
continue;
36013599
}
3602-
if (!$expr instanceof Node\Stmt\Expression) {
3603-
throw new ShouldNotHappenException();
3604-
}
3605-
3606-
$exprExpr = $expr->expr;
36073600
if ($exprExpr instanceof PropertyFetch) {
36083601
$propertyReflection = $this->propertyReflectionFinder->findPropertyReflectionFromNode($exprExpr, $this);
36093602
if ($propertyReflection !== null) {
@@ -3659,6 +3652,20 @@ public function invalidateExpression(Expr $expressionToInvalidate, bool $require
36593652
);
36603653
}
36613654

3655+
private function exprStringToExpr(string $exprString): ?Expr
3656+
{
3657+
try {
3658+
$expr = $this->parser->parseString('<?php ' . $exprString . ';')[0];
3659+
} catch (ParserErrorsException) {
3660+
return null;
3661+
}
3662+
if (!$expr instanceof Node\Stmt\Expression) {
3663+
throw new ShouldNotHappenException();
3664+
}
3665+
3666+
return $expr->expr;
3667+
}
3668+
36623669
public function invalidateMethodsOnExpression(Expr $expressionToInvalidate): self
36633670
{
36643671
$exprStringToInvalidate = $this->getNodeKey($expressionToInvalidate);

0 commit comments

Comments
 (0)