Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow abstract classes to be implemented in NoSingleInterfaceImplementerRule #135

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
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
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
Loading