Skip to content

Commit

Permalink
Skip circular note in RequiredOnlyInAbstractRule (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba authored Jan 31, 2025
1 parent 2a59547 commit 12b7b11
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Rules/Symfony/RequiredOnlyInAbstractRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Symplify\PHPStanRules\Rules\Symfony;

use PhpParser\Comment\Doc;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PHPStan\Analyser\Scope;
Expand Down Expand Up @@ -61,6 +62,10 @@ public function processNode(Node $node, Scope $scope): array
continue;
}

if ($this->hasCircularDocNote($classMethod)) {
continue;
}

if ($class->isAbstract()) {
continue;
}
Expand Down Expand Up @@ -95,4 +100,14 @@ private function shouldSkipClass(Scope $scope): bool

return false;
}

private function hasCircularDocNote(Node $node): bool
{
$docComment = $node->getDocComment();
if (! $docComment instanceof Doc) {
return false;
}

return str_contains($docComment->getText(), 'circular');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Symplify\PHPStanRules\Tests\Rules\Symfony\RequiredOnlyInAbstractRule\Fixture;

final class SkipCircularNote
{
/**
* Avoid circular dependency
* @required
*/
public function someMethod()
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static function provideData(): Iterator
12,
]]];

yield [__DIR__ . '/Fixture/SkipCircularNote.php', []];
yield [__DIR__ . '/Fixture/SkipAbstractClass.php', []];
yield [__DIR__ . '/Fixture/SkipParentDocumentRepository.php', []];
}
Expand Down

0 comments on commit 12b7b11

Please sign in to comment.