10
10
use PHPStan \BetterReflection \Reflection \Adapter \ReflectionClass ;
11
11
use PHPStan \BetterReflection \Reflection \Adapter \ReflectionEnum ;
12
12
use PHPStan \Rules \Rule ;
13
+ use PHPStan \Rules \RuleErrorBuilder ;
13
14
use PHPStan \ShouldNotHappenException ;
14
15
use function property_exists ;
15
16
use function sprintf ;
16
17
18
+ /**
19
+ * @implements Rule<ClassMethod>
20
+ */
17
21
class RequireParentConstructCallRule implements Rule
18
22
{
19
23
@@ -22,10 +26,6 @@ public function getNodeType(): string
22
26
return ClassMethod::class;
23
27
}
24
28
25
- /**
26
- * @param ClassMethod $node
27
- * @return string[]
28
- */
29
29
public function processNode (Node $ node , Scope $ scope ): array
30
30
{
31
31
if (!$ scope ->isInClass ()) {
@@ -52,30 +52,30 @@ public function processNode(Node $node, Scope $scope): array
52
52
if ($ this ->callsParentConstruct ($ node )) {
53
53
if ($ classReflection ->getParentClass () === false ) {
54
54
return [
55
- sprintf (
55
+ RuleErrorBuilder:: message ( sprintf (
56
56
'%s::__construct() calls parent constructor but does not extend any class. ' ,
57
57
$ classReflection ->getName ()
58
- ),
58
+ ))-> build () ,
59
59
];
60
60
}
61
61
62
62
if ($ this ->getParentConstructorClass ($ classReflection ) === false ) {
63
63
return [
64
- sprintf (
64
+ RuleErrorBuilder:: message ( sprintf (
65
65
'%s::__construct() calls parent constructor but parent does not have one. ' ,
66
66
$ classReflection ->getName ()
67
- ),
67
+ ))-> build () ,
68
68
];
69
69
}
70
70
} else {
71
71
$ parentClass = $ this ->getParentConstructorClass ($ classReflection );
72
72
if ($ parentClass !== false ) {
73
73
return [
74
- sprintf (
74
+ RuleErrorBuilder:: message ( sprintf (
75
75
'%s::__construct() does not call parent constructor from %s. ' ,
76
76
$ classReflection ->getName (),
77
77
$ parentClass ->getName ()
78
- ),
78
+ ))-> build () ,
79
79
];
80
80
}
81
81
}
0 commit comments