Skip to content

Commit

Permalink
InterfaceAncestorsRule - refactoring to use virtual InClassNode
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jul 8, 2021
1 parent fb23cb8 commit 1443c5e
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/Rules/Generics/InterfaceAncestorsRule.php
Original file line number Diff line number Diff line change
@@ -4,14 +4,15 @@

use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Node\InClassNode;
use PHPStan\PhpDoc\Tag\ExtendsTag;
use PHPStan\PhpDoc\Tag\ImplementsTag;
use PHPStan\Rules\Rule;
use PHPStan\Type\FileTypeMapper;
use PHPStan\Type\Type;

/**
* @implements \PHPStan\Rules\Rule<\PhpParser\Node\Stmt\Interface_>
* @implements \PHPStan\Rules\Rule<InClassNode>
*/
class InterfaceAncestorsRule implements Rule
{
@@ -31,19 +32,24 @@ public function __construct(

public function getNodeType(): string
{
return Node\Stmt\Interface_::class;
return InClassNode::class;
}

public function processNode(Node $node, Scope $scope): array
{
if (!isset($node->namespacedName)) {
throw new \PHPStan\ShouldNotHappenException();
$originalNode = $node->getOriginalNode();
if (!$originalNode instanceof Node\Stmt\Interface_) {
return [];
}
if (!$scope->isInClass()) {
return [];
}
$classReflection = $scope->getClassReflection();

$interfaceName = (string) $node->namespacedName;
$interfaceName = $classReflection->getName();
$extendsTags = [];
$implementsTags = [];
$docComment = $node->getDocComment();
$docComment = $originalNode->getDocComment();
if ($docComment !== null) {
$resolvedPhpDoc = $this->fileTypeMapper->getResolvedPhpDoc(
$scope->getFile(),
@@ -57,7 +63,7 @@ public function processNode(Node $node, Scope $scope): array
}

$extendsErrors = $this->genericAncestorsCheck->check(
$node->extends,
$originalNode->extends,
array_map(static function (ExtendsTag $tag): Type {
return $tag->getType();
}, $extendsTags),

0 comments on commit 1443c5e

Please sign in to comment.