4
4
5
5
use PhpParser \Node ;
6
6
use PHPStan \Analyser \Scope ;
7
+ use PHPStan \PhpDoc \ResolvedPhpDocBlock ;
8
+ use PHPStan \PhpDocParser \Ast \PhpDoc \PhpDocTagNode ;
7
9
use PHPStan \Reflection \ClassReflection ;
8
- use PHPStan \Reflection \ReflectionProvider ;
9
10
use PHPStan \ShouldNotHappenException ;
10
11
11
12
final class ConfigEntityConfigExportRule extends DeprecatedAnnotationsRuleBase
@@ -18,13 +19,13 @@ protected function getExpectedInterface(): string
18
19
19
20
protected function doProcessNode (ClassReflection $ reflection , Node \Stmt \Class_ $ node , Scope $ scope ): array
20
21
{
21
- $ annotation = $ reflection ->getResolvedPhpDoc ();
22
+ $ phpDoc = $ reflection ->getResolvedPhpDoc ();
22
23
// Plugins should always be annotated, but maybe this class is missing its
23
24
// annotation since it swaps an existing one.
24
- if ($ annotation === null ) {
25
+ if ($ phpDoc === null || ! $ this -> isAnnotated ( $ phpDoc ) ) {
25
26
return [];
26
27
}
27
- $ hasMatch = preg_match ('/config_export\s?=\s?{/ ' , $ annotation ->getPhpDocString ());
28
+ $ hasMatch = preg_match ('/config_export\s?=\s?{/ ' , $ phpDoc ->getPhpDocString ());
28
29
if ($ hasMatch === false ) {
29
30
throw new ShouldNotHappenException ('Unexpected error when trying to run match on phpDoc string. ' );
30
31
}
@@ -35,4 +36,16 @@ protected function doProcessNode(ClassReflection $reflection, Node\Stmt\Class_ $
35
36
}
36
37
return [];
37
38
}
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
+ }
38
51
}
0 commit comments