@@ -26,6 +26,9 @@ class RuleErrorBuilder
26
26
/** @var mixed[] */
27
27
private array $ properties ;
28
28
29
+ /** @var list<string> */
30
+ private array $ tips = [];
31
+
29
32
private function __construct (string $ message )
30
33
{
31
34
$ this ->properties ['message ' ] = $ message ;
@@ -106,7 +109,15 @@ public function file(string $file): self
106
109
107
110
public function tip (string $ tip ): self
108
111
{
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 ;
110
121
$ this ->type |= self ::TYPE_TIP ;
111
122
112
123
return $ this ;
@@ -122,15 +133,11 @@ public function discoveringSymbolsTip(): self
122
133
*/
123
134
public function acceptsReasonsTip (array $ reasons ): self
124
135
{
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 );
131
138
}
132
139
133
- return $ this -> tip ( implode ( "\n" , array_map ( static fn ( string $ reason ) => sprintf ( ' • %s ' , $ reason ), $ reasons ))) ;
140
+ return $ this ;
134
141
}
135
142
136
143
public function identifier (string $ identifier ): self
@@ -172,6 +179,14 @@ public function build(): RuleError
172
179
$ ruleError ->{$ propertyName } = $ value ;
173
180
}
174
181
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
+
175
190
return $ ruleError ;
176
191
}
177
192
0 commit comments