1010use PhpParser \Node \Expr \Cast \String_ as CastString_ ;
1111use PhpParser \Node \Expr \FuncCall ;
1212use PhpParser \Node \Expr \MethodCall ;
13+ use PhpParser \Node \Expr \PropertyFetch ;
1314use PhpParser \Node \Expr \Ternary ;
1415use PhpParser \Node \Expr \Variable ;
1516use PhpParser \Node \Scalar \Int_ ;
1920use PHPStan \Analyser \Scope ;
2021use PHPStan \Reflection \Native \ExtendedNativeParameterReflection ;
2122use PHPStan \Reflection \ParametersAcceptor ;
23+ use PHPStan \Reflection \ReflectionProvider ;
2224use PHPStan \Type \ErrorType ;
2325use PHPStan \Type \MixedType ;
2426use PHPStan \Type \NullType ;
27+ use PHPStan \Type \ObjectType ;
2528use PHPStan \Type \Type ;
2629use PHPStan \Type \UnionType ;
2730use Rector \NodeAnalyzer \PropertyFetchAnalyzer ;
@@ -35,6 +38,7 @@ public function __construct(
3538 private ValueResolver $ valueResolver ,
3639 private NodeTypeResolver $ nodeTypeResolver ,
3740 private PropertyFetchAnalyzer $ propertyFetchAnalyzer ,
41+ private ReflectionProvider $ reflectionProvider ,
3842 ) {
3943 }
4044
@@ -116,6 +120,10 @@ public function convertIfNull(
116120
117121 private function shouldSkipValue (Expr $ expr , Scope $ scope , bool $ isTrait , string $ targetType ): bool
118122 {
123+ if ($ this ->isPropertyFetchOnClassWithMagicGet ($ expr )) {
124+ return true ;
125+ }
126+
119127 $ type = $ this ->nodeTypeResolver ->getType ($ expr );
120128 if ($ type ->isString ()->yes () && $ targetType === 'string ' ) {
121129 return true ;
@@ -153,6 +161,24 @@ private function shouldSkipValue(Expr $expr, Scope $scope, bool $isTrait, string
153161 return $ this ->shouldSkipTrait ($ expr , $ type , $ isTrait );
154162 }
155163
164+ private function isPropertyFetchOnClassWithMagicGet (Expr $ expr ): bool
165+ {
166+ if (! $ expr instanceof PropertyFetch) {
167+ return false ;
168+ }
169+
170+ $ varType = $ this ->nodeTypeResolver ->getType ($ expr ->var );
171+ if (! $ varType instanceof ObjectType) {
172+ return false ;
173+ }
174+
175+ if (! $ this ->reflectionProvider ->hasClass ($ varType ->getClassName ())) {
176+ return false ;
177+ }
178+
179+ return $ this ->reflectionProvider ->getClass ($ varType ->getClassName ())->hasMethod ('__get ' );
180+ }
181+
156182 private function isValidUnionType (Type $ type ): bool
157183 {
158184 if (! $ type instanceof UnionType) {
0 commit comments