Skip to content

Commit

Permalink
Allow abstract classes to be implemented in NoSingleInterfaceImplemen…
Browse files Browse the repository at this point in the history
…terRule (#135)
  • Loading branch information
TomasVotruba committed Jun 2, 2024
1 parent 3c9b05f commit b22fabb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Collector/ImplementedInterfaceCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ public function getNodeType(): string

/**
* @param Class_ $node
* @return string[]
* @return string[]|null
*/
public function processNode(Node $node, Scope $scope): array
public function processNode(Node $node, Scope $scope): ?array
{
$implementedInterfaceNames = [];

// skip abstract classes, as they can enforce child implementations
if ($node->isAbstract()) {
return null;
}

foreach ($node->implements as $implement) {
$implementedInterfaceNames[] = $implement->toString();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Symplify\PHPStanRules\Tests\Rules\NoSingleInterfaceImplementerRule\Fixture;

abstract class AllowAbstract implements SimpleInterface
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function testRule(array $filePaths, array $expectedErrorMessagesWithLines
public static function provideData(): Iterator
{
yield [[__DIR__ . '/Fixture/SimpleInterface.php'], []];
yield [[__DIR__ . '/Fixture/AllowAbstract.php', __DIR__ . '/Fixture/SimpleInterface.php'], []];

yield [
[
Expand Down

0 comments on commit b22fabb

Please sign in to comment.