@@ -3593,17 +3593,10 @@ public function invalidateExpression(Expr $expressionToInvalidate, bool $require
3593
3593
$ nodeFinder = new NodeFinder ();
3594
3594
foreach (array_keys ($ moreSpecificTypeHolders ) as $ exprString ) {
3595
3595
$ 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 ) {
3600
3598
continue ;
3601
3599
}
3602
- if (!$ expr instanceof Node \Stmt \Expression) {
3603
- throw new ShouldNotHappenException ();
3604
- }
3605
-
3606
- $ exprExpr = $ expr ->expr ;
3607
3600
if ($ exprExpr instanceof PropertyFetch) {
3608
3601
$ propertyReflection = $ this ->propertyReflectionFinder ->findPropertyReflectionFromNode ($ exprExpr , $ this );
3609
3602
if ($ propertyReflection !== null ) {
@@ -3659,6 +3652,20 @@ public function invalidateExpression(Expr $expressionToInvalidate, bool $require
3659
3652
);
3660
3653
}
3661
3654
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
+
3662
3669
public function invalidateMethodsOnExpression (Expr $ expressionToInvalidate ): self
3663
3670
{
3664
3671
$ exprStringToInvalidate = $ this ->getNodeKey ($ expressionToInvalidate );
0 commit comments