22
33namespace PHPStan \Rules ;
44
5+ use PhpParser \Node ;
56use PHPStan \Analyser \Error ;
67use PHPStan \ShouldNotHappenException ;
78use function array_map ;
@@ -25,6 +26,7 @@ final class RuleErrorBuilder
2526 private const TYPE_IDENTIFIER = 16 ;
2627 private const TYPE_METADATA = 32 ;
2728 private const TYPE_NON_IGNORABLE = 64 ;
29+ private const TYPE_FIXABLE_NODE = 128 ;
2830
2931 private int $ type ;
3032
@@ -50,9 +52,9 @@ public static function getRuleErrorTypes(): array
5052 RuleError::class,
5153 [
5254 [
53- 'message ' ,
54- 'string ' ,
55- 'string ' ,
55+ 'message ' , // property name
56+ 'string ' , // native type
57+ 'string ' , // PHPDoc type
5658 ],
5759 ],
5860 ],
@@ -115,6 +117,16 @@ public static function getRuleErrorTypes(): array
115117 NonIgnorableRuleError::class,
116118 [],
117119 ],
120+ self ::TYPE_FIXABLE_NODE => [
121+ FixableNodeRuleError::class,
122+ [
123+ [
124+ 'newNodeCallable ' ,
125+ null ,
126+ 'callable(\PhpParser\Node): \PhpParser\Node ' ,
127+ ],
128+ ],
129+ ],
118130 ];
119131 }
120132
@@ -254,6 +266,20 @@ public function nonIgnorable(): self
254266 return $ this ;
255267 }
256268
269+ /**
270+ * @internal Experimental
271+ * @param callable(Node): Node $cb
272+ * @phpstan-this-out self<T&FixableNodeRuleError>
273+ * @return self<T&FixableNodeRuleError>
274+ */
275+ public function fixNode (callable $ cb ): self
276+ {
277+ $ this ->properties ['newNodeCallable ' ] = $ cb ;
278+ $ this ->type |= self ::TYPE_FIXABLE_NODE ;
279+
280+ return $ this ;
281+ }
282+
257283 /**
258284 * @return T
259285 */
0 commit comments