Skip to content

Commit

Permalink
Revert "Fix $this/self docblock compare removed on on-final class, as…
Browse files Browse the repository at this point in the history
… it can refer to child this type (rectorphp#1246)"

This reverts commit a2c2979
  • Loading branch information
simPod committed Jan 16, 2022
1 parent ca696bc commit 5330572
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 36 deletions.
21 changes: 1 addition & 20 deletions packages/NodeTypeResolver/TypeComparator/TypeComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
namespace Rector\NodeTypeResolver\TypeComparator;

use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\ArrayType;
use PHPStan\Type\BooleanType;
use PHPStan\Type\Constant\ConstantBooleanType;
Expand All @@ -23,7 +21,6 @@
use PHPStan\Type\TypeTraverser;
use PHPStan\Type\UnionType;
use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
use Rector\NodeTypeResolver\PHPStan\TypeHasher;
use Rector\StaticTypeMapper\StaticTypeMapper;
Expand Down Expand Up @@ -108,7 +105,7 @@ public function arePhpParserAndPhpStanPhpDocTypesEqual(
return false;
}

return $this->isThisTypeInFinalClass($phpStanDocType, $phpParserNodeType, $node);
return true;
}

public function isSubtype(Type $checkedType, Type $mainType): bool
Expand Down Expand Up @@ -269,20 +266,4 @@ private function areTypesSameWithLiteralTypeInPhpDoc(
&& $phpParserNodeType->isSuperTypeOf($phpStanDocType)
->yes();
}

private function isThisTypeInFinalClass(Type $phpStanDocType, Type $phpParserNodeType, Node $node): bool
{
// special case for non-final $this/self compare; in case of interface/abstract class, it can be another $this
if ($phpStanDocType instanceof ThisType && $phpParserNodeType instanceof ThisType) {
$scope = $node->getAttribute(AttributeKey::SCOPE);
if ($scope instanceof Scope) {
$classReflection = $scope->getClassReflection();
if ($classReflection instanceof ClassReflection) {
return $classReflection->isFinal();
}
}
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,3 @@ final class SkipUnionSelfThisFinalClass
return $this;
}
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\FunctionLike\UnionTypesRector\Fixture;

final class SkipUnionSelfThisFinalClass
{
public function withFromId(int $fromId): self
{
return $this;
}
}

?>

0 comments on commit 5330572

Please sign in to comment.