Skip to content

Commit d562b27

Browse files
authored
Rectify (#7973)
1 parent e300872 commit d562b27

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use PhpParser\Node\Expr\Variable;
1111
use PhpParser\Node\FunctionLike;
1212
use PhpParser\Node\Identifier;
13-
use PhpParser\Node\Name;
1413
use PhpParser\Node\NullableType;
1514
use PhpParser\Node\Param;
1615
use PhpParser\Node\Stmt\Class_;
@@ -21,7 +20,6 @@
2120
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
2221
use PHPStan\Reflection\ClassReflection;
2322
use PHPStan\Type\MixedType;
24-
use PHPStan\Type\Type;
2523
use PHPStan\Type\TypeCombinator;
2624
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
2725
use 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

Comments
 (0)