Skip to content

Commit c149cae

Browse files
authored
Merge pull request #200 from Pasqualle/Pasqualle-ConfigEntityConfigExportRule
Update ConfigEntityConfigExportRule.php
2 parents 548fa7c + 7ab4ba4 commit c149cae

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/Rules/Deprecations/ConfigEntityConfigExportRule.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
use PhpParser\Node;
66
use PHPStan\Analyser\Scope;
7+
use PHPStan\PhpDoc\ResolvedPhpDocBlock;
8+
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
79
use PHPStan\Reflection\ClassReflection;
8-
use PHPStan\Reflection\ReflectionProvider;
910
use PHPStan\ShouldNotHappenException;
1011

1112
final class ConfigEntityConfigExportRule extends DeprecatedAnnotationsRuleBase
@@ -18,13 +19,13 @@ protected function getExpectedInterface(): string
1819

1920
protected function doProcessNode(ClassReflection $reflection, Node\Stmt\Class_ $node, Scope $scope): array
2021
{
21-
$annotation = $reflection->getResolvedPhpDoc();
22+
$phpDoc = $reflection->getResolvedPhpDoc();
2223
// Plugins should always be annotated, but maybe this class is missing its
2324
// annotation since it swaps an existing one.
24-
if ($annotation === null) {
25+
if ($phpDoc === null || !$this->isAnnotated($phpDoc)) {
2526
return [];
2627
}
27-
$hasMatch = preg_match('/config_export\s?=\s?{/', $annotation->getPhpDocString());
28+
$hasMatch = preg_match('/config_export\s?=\s?{/', $phpDoc->getPhpDocString());
2829
if ($hasMatch === false) {
2930
throw new ShouldNotHappenException('Unexpected error when trying to run match on phpDoc string.');
3031
}
@@ -35,4 +36,16 @@ protected function doProcessNode(ClassReflection $reflection, Node\Stmt\Class_ $
3536
}
3637
return [];
3738
}
39+
40+
private function isAnnotated(ResolvedPhpDocBlock $phpDoc): bool
41+
{
42+
foreach ($phpDoc->getPhpDocNodes() as $docNode) {
43+
foreach ($docNode->children as $childNode) {
44+
if (($childNode instanceof PhpDocTagNode) && $childNode->name === '@ConfigEntityType') {
45+
return true;
46+
}
47+
}
48+
}
49+
return false;
50+
}
3851
}

0 commit comments

Comments
 (0)