1717use PHPStan \Reflection \ParametersAcceptorSelector ;
1818use PHPStan \Reflection \ReflectionProvider ;
1919use PHPStan \Type \ObjectType ;
20+ use PHPStan \Type \TypeCombinator ;
2021use Rector \NodeTypeResolver \Node \AttributeKey ;
2122use Rector \Rector \AbstractRector ;
2223use Rector \StaticTypeMapper \Resolver \ClassNameFromObjectTypeResolver ;
@@ -186,12 +187,6 @@ private function refactorThrow(Throw_ $throw, Variable $caughtThrowableVariable)
186187 private function resolveExceptionArgumentPosition (Name $ exceptionName ): ?int
187188 {
188189 $ className = $ this ->getName ($ exceptionName );
189-
190- // is native exception?
191- if (! \str_contains ($ className , '\\' )) {
192- return self ::DEFAULT_EXCEPTION_ARGUMENT_POSITION ;
193- }
194-
195190 if (! $ this ->reflectionProvider ->hasClass ($ className )) {
196191 return self ::DEFAULT_EXCEPTION_ARGUMENT_POSITION ;
197192 }
@@ -211,12 +206,16 @@ private function resolveExceptionArgumentPosition(Name $exceptionName): ?int
211206 $ parameterType = $ extendedParameterReflection ->getType ();
212207 $ className = ClassNameFromObjectTypeResolver::resolve ($ extendedParameterReflection ->getType ());
213208
209+ $ objectType = new ObjectType ('Throwable ' );
214210 if ($ className === null ) {
215- dump ($ parameterType ::class);
211+ $ parameterType = TypeCombinator::removeNull ($ parameterType );
212+ if ($ objectType ->isSuperTypeOf ($ parameterType )->yes ()) {
213+ return $ position ;
214+ }
215+
216216 continue ;
217217 }
218218
219- $ objectType = new ObjectType ('Throwable ' );
220219 if ($ objectType ->isSuperTypeOf ($ parameterType )->no ()) {
221220 continue ;
222221 }
0 commit comments