@@ -26,6 +26,9 @@ class RuleErrorBuilder
2626 /** @var mixed[] */
2727 private array $ properties ;
2828
29+ /** @var list<string> */
30+ private array $ tips = [];
31+
2932 private function __construct (string $ message )
3033 {
3134 $ this ->properties ['message ' ] = $ message ;
@@ -106,7 +109,15 @@ public function file(string $file): self
106109
107110 public function tip (string $ tip ): self
108111 {
109- $ this ->properties ['tip ' ] = $ tip ;
112+ $ this ->tips = [$ tip ];
113+ $ this ->type |= self ::TYPE_TIP ;
114+
115+ return $ this ;
116+ }
117+
118+ public function addTip (string $ tip ): self
119+ {
120+ $ this ->tips [] = $ tip ;
110121 $ this ->type |= self ::TYPE_TIP ;
111122
112123 return $ this ;
@@ -122,15 +133,11 @@ public function discoveringSymbolsTip(): self
122133 */
123134 public function acceptsReasonsTip (array $ reasons ): self
124135 {
125- if (count ($ reasons ) === 0 ) {
126- return $ this ;
127- }
128-
129- if (count ($ reasons ) === 1 ) {
130- return $ this ->tip ($ reasons [0 ]);
136+ foreach ($ reasons as $ reason ) {
137+ $ this ->addTip ($ reason );
131138 }
132139
133- return $ this -> tip ( implode ( "\n" , array_map ( static fn ( string $ reason ) => sprintf ( ' • %s ' , $ reason ), $ reasons ))) ;
140+ return $ this ;
134141 }
135142
136143 public function identifier (string $ identifier ): self
@@ -172,6 +179,14 @@ public function build(): RuleError
172179 $ ruleError ->{$ propertyName } = $ value ;
173180 }
174181
182+ if (count ($ this ->tips ) > 0 ) {
183+ if (count ($ this ->tips ) === 1 ) {
184+ $ ruleError ->tip = $ this ->tips [0 ];
185+ } else {
186+ $ ruleError ->tip = implode ("\n" , array_map (static fn (string $ tip ) => sprintf ('• %s ' , $ tip ), $ this ->tips ));
187+ }
188+ }
189+
175190 return $ ruleError ;
176191 }
177192
0 commit comments