9
9
use function implode ;
10
10
use function sprintf ;
11
11
12
- /** @api */
12
+ /**
13
+ * @api
14
+ * @template-covariant T of RuleError
15
+ */
13
16
class RuleErrorBuilder
14
17
{
15
18
@@ -86,11 +89,18 @@ public static function getRuleErrorTypes(): array
86
89
];
87
90
}
88
91
92
+ /**
93
+ * @return self<RuleError>
94
+ */
89
95
public static function message (string $ message ): self
90
96
{
91
97
return new self ($ message );
92
98
}
93
99
100
+ /**
101
+ * @phpstan-this-out self<T&LineRuleError>
102
+ * @return self<T&LineRuleError>
103
+ */
94
104
public function line (int $ line ): self
95
105
{
96
106
$ this ->properties ['line ' ] = $ line ;
@@ -99,6 +109,10 @@ public function line(int $line): self
99
109
return $ this ;
100
110
}
101
111
112
+ /**
113
+ * @phpstan-this-out self<T&FileRuleError>
114
+ * @return self<T&FileRuleError>
115
+ */
102
116
public function file (string $ file ): self
103
117
{
104
118
$ this ->properties ['file ' ] = $ file ;
@@ -107,6 +121,10 @@ public function file(string $file): self
107
121
return $ this ;
108
122
}
109
123
124
+ /**
125
+ * @phpstan-this-out self<T&TipRuleError>
126
+ * @return self<T&TipRuleError>
127
+ */
110
128
public function tip (string $ tip ): self
111
129
{
112
130
$ this ->tips = [$ tip ];
@@ -115,6 +133,10 @@ public function tip(string $tip): self
115
133
return $ this ;
116
134
}
117
135
136
+ /**
137
+ * @phpstan-this-out self<T&TipRuleError>
138
+ * @return self<T&TipRuleError>
139
+ */
118
140
public function addTip (string $ tip ): self
119
141
{
120
142
$ this ->tips [] = $ tip ;
@@ -123,13 +145,19 @@ public function addTip(string $tip): self
123
145
return $ this ;
124
146
}
125
147
148
+ /**
149
+ * @phpstan-this-out self<T&TipRuleError>
150
+ * @return self<T&TipRuleError>
151
+ */
126
152
public function discoveringSymbolsTip (): self
127
153
{
128
154
return $ this ->tip ('Learn more at https://phpstan.org/user-guide/discovering-symbols ' );
129
155
}
130
156
131
157
/**
132
158
* @param list<string> $reasons
159
+ * @phpstan-this-out self<T&TipRuleError>
160
+ * @return self<T&TipRuleError>
133
161
*/
134
162
public function acceptsReasonsTip (array $ reasons ): self
135
163
{
@@ -140,6 +168,10 @@ public function acceptsReasonsTip(array $reasons): self
140
168
return $ this ;
141
169
}
142
170
171
+ /**
172
+ * @phpstan-this-out self<T&IdentifierRuleError>
173
+ * @return self<T&IdentifierRuleError>
174
+ */
143
175
public function identifier (string $ identifier ): self
144
176
{
145
177
$ this ->properties ['identifier ' ] = $ identifier ;
@@ -150,6 +182,8 @@ public function identifier(string $identifier): self
150
182
151
183
/**
152
184
* @param mixed[] $metadata
185
+ * @phpstan-this-out self<T&MetadataRuleError>
186
+ * @return self<T&MetadataRuleError>
153
187
*/
154
188
public function metadata (array $ metadata ): self
155
189
{
@@ -159,16 +193,23 @@ public function metadata(array $metadata): self
159
193
return $ this ;
160
194
}
161
195
196
+ /**
197
+ * @phpstan-this-out self<T&NonIgnorableRuleError>
198
+ * @return self<T&NonIgnorableRuleError>
199
+ */
162
200
public function nonIgnorable (): self
163
201
{
164
202
$ this ->type |= self ::TYPE_NON_IGNORABLE ;
165
203
166
204
return $ this ;
167
205
}
168
206
207
+ /**
208
+ * @return T
209
+ */
169
210
public function build (): RuleError
170
211
{
171
- /** @var class-string<RuleError > $className */
212
+ /** @var class-string<T > $className */
172
213
$ className = sprintf ('PHPStan \\Rules \\RuleErrors \\RuleError%d ' , $ this ->type );
173
214
if (!class_exists ($ className )) {
174
215
throw new ShouldNotHappenException (sprintf ('Class %s does not exist. ' , $ className ));
0 commit comments