Skip to content
Merged

Rectify #7973

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
}
}
Loading