Skip to content

Commit

Permalink
Fix parent interfaces not recognized as extended
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosas authored Nov 23, 2024
1 parent 3af2ffb commit 55154db
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
5 changes: 4 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

## 0.10.11
## 0.10.20
* Fix parent interfaces not recognized as extended.

## 0.10.19
* Add `IsTrait` and `IsNotTrait` selectors.
* Add `IsException`, `IsError`, and `IsThrowable` selectors.

Expand Down
10 changes: 9 additions & 1 deletion src/Rule/Extractor/Relation/AllParentsExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ public function getNodeType(): string
*/
protected function extractNodeClassNames(Node $node, Scope $scope): array
{
$classReflection = $node->getClassReflection();
if ($node->getClassReflection()->isInterface()) {
return array_map(
static fn (ClassReflection $c) => $c->getName(),
$classReflection->getInterfaces()
);
}

return array_map(
static fn (ClassReflection $c) => $c->getName(),
$node->getClassReflection()->getParents()
$classReflection->getParents()
);
}
}
12 changes: 11 additions & 1 deletion src/Rule/Extractor/Relation/ParentExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Node\InClassNode;
use PHPStan\Reflection\ClassReflection;

trait ParentExtractor
{
Expand All @@ -19,7 +20,16 @@ public function getNodeType(): string
*/
protected function extractNodeClassNames(Node $node, Scope $scope): array
{
$parent = $node->getClassReflection()->getParentClass();
$classReflection = $node->getClassReflection();

if ($node->getClassReflection()->isInterface()) {
return array_map(
static fn (ClassReflection $c) => $c->getName(),
$classReflection->getImmediateInterfaces()
);
}

$parent = $classReflection->getParentClass();

return $parent === null ? [] : [$parent->getName()];
}
Expand Down

0 comments on commit 55154db

Please sign in to comment.