From ecd95882acc9a6b8e9b980926ea0428feb5e4ddc Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 27 Apr 2026 18:20:05 +0700 Subject: [PATCH] Rectify --- ...pertyAssignToConstructorPromotionRector.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php b/rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php index 5d4190cb229..deabb618384 100644 --- a/rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php +++ b/rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php @@ -10,7 +10,6 @@ use PhpParser\Node\Expr\Variable; use PhpParser\Node\FunctionLike; use PhpParser\Node\Identifier; -use PhpParser\Node\Name; use PhpParser\Node\NullableType; use PhpParser\Node\Param; use PhpParser\Node\Stmt\Class_; @@ -21,7 +20,6 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode; use PHPStan\Reflection\ClassReflection; use PHPStan\Type\MixedType; -use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\Contract\Rector\ConfigurableRectorInterface; @@ -389,18 +387,18 @@ private function shouldSkipPropertyOrParam(Property $property, Param $param): bo private function shouldRemoveNullFromForPromotedParamType(Property $property, Param $param): bool { - if ($property->type === null || $param->type === null) { + if (! $property->type instanceof Node || ! $param->type instanceof Node) { return false; } - if ($param->default !== null && $this->valueResolver->isNull($param->default)) { + if ($param->default instanceof Expr && $this->valueResolver->isNull($param->default)) { return false; } $propertyType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($property->type); - $propertyTypeWithoutNull = TypeCombinator::removeNull($propertyType); + $type = TypeCombinator::removeNull($propertyType); - if (! $this->typeComparator->areTypesEqual($propertyTypeWithoutNull, $propertyType)) { + if (! $this->typeComparator->areTypesEqual($type, $propertyType)) { return false; } @@ -412,20 +410,20 @@ private function shouldRemoveNullFromForPromotedParamType(Property $property, Pa private function shouldUsePropertyTypeForPromotedParam(Property $property, Param $param): bool { - if ($property->type === null) { + if (! $property->type instanceof Node) { return false; } - if ($param->type === null) { + if (! $param->type instanceof Node) { return true; } $propertyType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($property->type); - $propertyTypeWithoutNull = TypeCombinator::removeNull($propertyType); + $type = TypeCombinator::removeNull($propertyType); $paramType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($param->type); $paramTypeWithoutNull = TypeCombinator::removeNull($paramType); - return $this->typeComparator->areTypesEqual($propertyTypeWithoutNull, $paramTypeWithoutNull); + return $this->typeComparator->areTypesEqual($type, $paramTypeWithoutNull); } }