1010use PhpParser \Node \Expr \Variable ;
1111use PhpParser \Node \FunctionLike ;
1212use PhpParser \Node \Identifier ;
13- use PhpParser \Node \Name ;
1413use PhpParser \Node \NullableType ;
1514use PhpParser \Node \Param ;
1615use PhpParser \Node \Stmt \Class_ ;
2120use PHPStan \PhpDocParser \Ast \PhpDoc \ParamTagValueNode ;
2221use PHPStan \Reflection \ClassReflection ;
2322use PHPStan \Type \MixedType ;
24- use PHPStan \Type \Type ;
2523use PHPStan \Type \TypeCombinator ;
2624use Rector \BetterPhpDocParser \PhpDocInfo \PhpDocInfoFactory ;
2725use Rector \Contract \Rector \ConfigurableRectorInterface ;
@@ -389,18 +387,18 @@ private function shouldSkipPropertyOrParam(Property $property, Param $param): bo
389387
390388 private function shouldRemoveNullFromForPromotedParamType (Property $ property , Param $ param ): bool
391389 {
392- if ($ property ->type === null || $ param ->type === null ) {
390+ if (! $ property ->type instanceof Node || ! $ param ->type instanceof Node ) {
393391 return false ;
394392 }
395393
396- if ($ param ->default !== null && $ this ->valueResolver ->isNull ($ param ->default )) {
394+ if ($ param ->default instanceof Expr && $ this ->valueResolver ->isNull ($ param ->default )) {
397395 return false ;
398396 }
399397
400398 $ propertyType = $ this ->staticTypeMapper ->mapPhpParserNodePHPStanType ($ property ->type );
401- $ propertyTypeWithoutNull = TypeCombinator::removeNull ($ propertyType );
399+ $ type = TypeCombinator::removeNull ($ propertyType );
402400
403- if (! $ this ->typeComparator ->areTypesEqual ($ propertyTypeWithoutNull , $ propertyType )) {
401+ if (! $ this ->typeComparator ->areTypesEqual ($ type , $ propertyType )) {
404402 return false ;
405403 }
406404
@@ -412,20 +410,20 @@ private function shouldRemoveNullFromForPromotedParamType(Property $property, Pa
412410
413411 private function shouldUsePropertyTypeForPromotedParam (Property $ property , Param $ param ): bool
414412 {
415- if ($ property ->type === null ) {
413+ if (! $ property ->type instanceof Node ) {
416414 return false ;
417415 }
418416
419- if ($ param ->type === null ) {
417+ if (! $ param ->type instanceof Node ) {
420418 return true ;
421419 }
422420
423421 $ propertyType = $ this ->staticTypeMapper ->mapPhpParserNodePHPStanType ($ property ->type );
424- $ propertyTypeWithoutNull = TypeCombinator::removeNull ($ propertyType );
422+ $ type = TypeCombinator::removeNull ($ propertyType );
425423
426424 $ paramType = $ this ->staticTypeMapper ->mapPhpParserNodePHPStanType ($ param ->type );
427425 $ paramTypeWithoutNull = TypeCombinator::removeNull ($ paramType );
428426
429- return $ this ->typeComparator ->areTypesEqual ($ propertyTypeWithoutNull , $ paramTypeWithoutNull );
427+ return $ this ->typeComparator ->areTypesEqual ($ type , $ paramTypeWithoutNull );
430428 }
431429}
0 commit comments