Skip to content

Commit 12b7b11

Browse files
authored
Skip circular note in RequiredOnlyInAbstractRule (#167)
1 parent 2a59547 commit 12b7b11

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/Rules/Symfony/RequiredOnlyInAbstractRule.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Symplify\PHPStanRules\Rules\Symfony;
66

7+
use PhpParser\Comment\Doc;
78
use PhpParser\Node;
89
use PhpParser\Node\Stmt\Class_;
910
use PHPStan\Analyser\Scope;
@@ -61,6 +62,10 @@ public function processNode(Node $node, Scope $scope): array
6162
continue;
6263
}
6364

65+
if ($this->hasCircularDocNote($classMethod)) {
66+
continue;
67+
}
68+
6469
if ($class->isAbstract()) {
6570
continue;
6671
}
@@ -95,4 +100,14 @@ private function shouldSkipClass(Scope $scope): bool
95100

96101
return false;
97102
}
103+
104+
private function hasCircularDocNote(Node $node): bool
105+
{
106+
$docComment = $node->getDocComment();
107+
if (! $docComment instanceof Doc) {
108+
return false;
109+
}
110+
111+
return str_contains($docComment->getText(), 'circular');
112+
}
98113
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\PHPStanRules\Tests\Rules\Symfony\RequiredOnlyInAbstractRule\Fixture;
6+
7+
final class SkipCircularNote
8+
{
9+
/**
10+
* Avoid circular dependency
11+
* @required
12+
*/
13+
public function someMethod()
14+
{
15+
}
16+
}

tests/Rules/Symfony/RequiredOnlyInAbstractRule/RequiredOnlyInAbstractRuleTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public static function provideData(): Iterator
2525
12,
2626
]]];
2727

28+
yield [__DIR__ . '/Fixture/SkipCircularNote.php', []];
2829
yield [__DIR__ . '/Fixture/SkipAbstractClass.php', []];
2930
yield [__DIR__ . '/Fixture/SkipParentDocumentRepository.php', []];
3031
}

0 commit comments

Comments
 (0)