Conditions | 1 |
Paths | 1 |
Total Lines | 357 |
Code Lines | 256 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
38 | public function dataOptions(): array |
||
39 | { |
||
40 | return [ |
||
41 | [ |
||
42 | new CompareTo(1), |
||
43 | [ |
||
44 | 'targetValue' => 1, |
||
45 | 'targetAttribute' => null, |
||
46 | 'incorrectInputMessage' => [ |
||
47 | 'template' => 'The allowed types are integer, float, string, boolean and null.', |
||
48 | 'parameters' => [ |
||
49 | 'targetValue' => 1, |
||
50 | 'targetAttribute' => null, |
||
51 | 'targetValueOrAttribute' => 1, |
||
52 | ], |
||
53 | ], |
||
54 | 'incorrectDataSetTypeMessage' => [ |
||
55 | 'template' => 'The attribute value returned from a custom data set must have a scalar type.', |
||
56 | 'parameters' => [ |
||
57 | 'targetValue' => 1, |
||
58 | 'targetAttribute' => null, |
||
59 | 'targetValueOrAttribute' => 1, |
||
60 | ], |
||
61 | ], |
||
62 | 'message' => [ |
||
63 | 'template' => 'Value must be equal to "{targetValueOrAttribute}".', |
||
64 | 'parameters' => [ |
||
65 | 'targetValue' => 1, |
||
66 | 'targetAttribute' => null, |
||
67 | 'targetValueOrAttribute' => 1, |
||
68 | ], |
||
69 | ], |
||
70 | 'type' => 'string', |
||
71 | 'operator' => '==', |
||
72 | 'skipOnEmpty' => false, |
||
73 | 'skipOnError' => false, |
||
74 | ], |
||
75 | ], |
||
76 | [ |
||
77 | new CompareTo(1, type: CompareTo::TYPE_NUMBER), |
||
78 | [ |
||
79 | 'targetValue' => 1, |
||
80 | 'targetAttribute' => null, |
||
81 | 'incorrectInputMessage' => [ |
||
82 | 'template' => 'The allowed types are integer, float, string, boolean and null.', |
||
83 | 'parameters' => [ |
||
84 | 'targetValue' => 1, |
||
85 | 'targetAttribute' => null, |
||
86 | 'targetValueOrAttribute' => 1, |
||
87 | ], |
||
88 | ], |
||
89 | 'incorrectDataSetTypeMessage' => [ |
||
90 | 'template' => 'The attribute value returned from a custom data set must have a scalar type.', |
||
91 | 'parameters' => [ |
||
92 | 'targetValue' => 1, |
||
93 | 'targetAttribute' => null, |
||
94 | 'targetValueOrAttribute' => 1, |
||
95 | ], |
||
96 | ], |
||
97 | 'message' => [ |
||
98 | 'template' => 'Value must be equal to "{targetValueOrAttribute}".', |
||
99 | 'parameters' => [ |
||
100 | 'targetValue' => 1, |
||
101 | 'targetAttribute' => null, |
||
102 | 'targetValueOrAttribute' => 1, |
||
103 | ], |
||
104 | ], |
||
105 | 'type' => 'number', |
||
106 | 'operator' => '==', |
||
107 | 'skipOnEmpty' => false, |
||
108 | 'skipOnError' => false, |
||
109 | ], |
||
110 | ], |
||
111 | [ |
||
112 | new CompareTo(1, type: CompareTo::TYPE_NUMBER, operator: '>='), |
||
113 | [ |
||
114 | 'targetValue' => 1, |
||
115 | 'targetAttribute' => null, |
||
116 | 'incorrectInputMessage' => [ |
||
117 | 'template' => 'The allowed types are integer, float, string, boolean and null.', |
||
118 | 'parameters' => [ |
||
119 | 'targetValue' => 1, |
||
120 | 'targetAttribute' => null, |
||
121 | 'targetValueOrAttribute' => 1, |
||
122 | ], |
||
123 | ], |
||
124 | 'incorrectDataSetTypeMessage' => [ |
||
125 | 'template' => 'The attribute value returned from a custom data set must have a scalar type.', |
||
126 | 'parameters' => [ |
||
127 | 'targetValue' => 1, |
||
128 | 'targetAttribute' => null, |
||
129 | 'targetValueOrAttribute' => 1, |
||
130 | ], |
||
131 | ], |
||
132 | 'message' => [ |
||
133 | 'template' => 'Value must be greater than or equal to "{targetValueOrAttribute}".', |
||
134 | 'parameters' => [ |
||
135 | 'targetValue' => 1, |
||
136 | 'targetAttribute' => null, |
||
137 | 'targetValueOrAttribute' => 1, |
||
138 | ], |
||
139 | ], |
||
140 | 'type' => 'number', |
||
141 | 'operator' => '>=', |
||
142 | 'skipOnEmpty' => false, |
||
143 | 'skipOnError' => false, |
||
144 | ], |
||
145 | ], |
||
146 | [ |
||
147 | new CompareTo('YES'), |
||
148 | [ |
||
149 | 'targetValue' => 'YES', |
||
150 | 'targetAttribute' => null, |
||
151 | 'incorrectInputMessage' => [ |
||
152 | 'template' => 'The allowed types are integer, float, string, boolean and null.', |
||
153 | 'parameters' => [ |
||
154 | 'targetValue' => 'YES', |
||
155 | 'targetAttribute' => null, |
||
156 | 'targetValueOrAttribute' => 'YES', |
||
157 | ], |
||
158 | ], |
||
159 | 'incorrectDataSetTypeMessage' => [ |
||
160 | 'template' => 'The attribute value returned from a custom data set must have a scalar type.', |
||
161 | 'parameters' => [ |
||
162 | 'targetValue' => 'YES', |
||
163 | 'targetAttribute' => null, |
||
164 | 'targetValueOrAttribute' => 'YES', |
||
165 | ], |
||
166 | ], |
||
167 | 'message' => [ |
||
168 | 'template' => 'Value must be equal to "{targetValueOrAttribute}".', |
||
169 | 'parameters' => [ |
||
170 | 'targetValue' => 'YES', |
||
171 | 'targetAttribute' => null, |
||
172 | 'targetValueOrAttribute' => 'YES', |
||
173 | ], |
||
174 | ], |
||
175 | 'type' => 'string', |
||
176 | 'operator' => '==', |
||
177 | 'skipOnEmpty' => false, |
||
178 | 'skipOnError' => false, |
||
179 | ], |
||
180 | ], |
||
181 | [ |
||
182 | new CompareTo('YES', skipOnEmpty: true), |
||
183 | [ |
||
184 | 'targetValue' => 'YES', |
||
185 | 'targetAttribute' => null, |
||
186 | 'incorrectInputMessage' => [ |
||
187 | 'template' => 'The allowed types are integer, float, string, boolean and null.', |
||
188 | 'parameters' => [ |
||
189 | 'targetValue' => 'YES', |
||
190 | 'targetAttribute' => null, |
||
191 | 'targetValueOrAttribute' => 'YES', |
||
192 | ], |
||
193 | ], |
||
194 | 'incorrectDataSetTypeMessage' => [ |
||
195 | 'template' => 'The attribute value returned from a custom data set must have a scalar type.', |
||
196 | 'parameters' => [ |
||
197 | 'targetValue' => 'YES', |
||
198 | 'targetAttribute' => null, |
||
199 | 'targetValueOrAttribute' => 'YES', |
||
200 | ], |
||
201 | ], |
||
202 | 'message' => [ |
||
203 | 'template' => 'Value must be equal to "{targetValueOrAttribute}".', |
||
204 | 'parameters' => [ |
||
205 | 'targetValue' => 'YES', |
||
206 | 'targetAttribute' => null, |
||
207 | 'targetValueOrAttribute' => 'YES', |
||
208 | ], |
||
209 | ], |
||
210 | 'type' => 'string', |
||
211 | 'operator' => '==', |
||
212 | 'skipOnEmpty' => true, |
||
213 | 'skipOnError' => false, |
||
214 | ], |
||
215 | ], |
||
216 | [ |
||
217 | new CompareTo('YES', operator: '!=='), |
||
218 | [ |
||
219 | 'targetValue' => 'YES', |
||
220 | 'targetAttribute' => null, |
||
221 | 'incorrectInputMessage' => [ |
||
222 | 'template' => 'The allowed types are integer, float, string, boolean and null.', |
||
223 | 'parameters' => [ |
||
224 | 'targetValue' => 'YES', |
||
225 | 'targetAttribute' => null, |
||
226 | 'targetValueOrAttribute' => 'YES', |
||
227 | ], |
||
228 | ], |
||
229 | 'incorrectDataSetTypeMessage' => [ |
||
230 | 'template' => 'The attribute value returned from a custom data set must have a scalar type.', |
||
231 | 'parameters' => [ |
||
232 | 'targetValue' => 'YES', |
||
233 | 'targetAttribute' => null, |
||
234 | 'targetValueOrAttribute' => 'YES', |
||
235 | ], |
||
236 | ], |
||
237 | 'message' => [ |
||
238 | 'template' => 'Value must not be equal to "{targetValueOrAttribute}".', |
||
239 | 'parameters' => [ |
||
240 | 'targetValue' => 'YES', |
||
241 | 'targetAttribute' => null, |
||
242 | 'targetValueOrAttribute' => 'YES', |
||
243 | ], |
||
244 | ], |
||
245 | 'type' => 'string', |
||
246 | 'operator' => '!==', |
||
247 | 'skipOnEmpty' => false, |
||
248 | 'skipOnError' => false, |
||
249 | ], |
||
250 | ], |
||
251 | [ |
||
252 | new CompareTo('YES', message: 'Custom message for {targetValueOrAttribute}.'), |
||
253 | [ |
||
254 | 'targetValue' => 'YES', |
||
255 | 'targetAttribute' => null, |
||
256 | 'incorrectInputMessage' => [ |
||
257 | 'template' => 'The allowed types are integer, float, string, boolean and null.', |
||
258 | 'parameters' => [ |
||
259 | 'targetValue' => 'YES', |
||
260 | 'targetAttribute' => null, |
||
261 | 'targetValueOrAttribute' => 'YES', |
||
262 | ], |
||
263 | ], |
||
264 | 'incorrectDataSetTypeMessage' => [ |
||
265 | 'template' => 'The attribute value returned from a custom data set must have a scalar type.', |
||
266 | 'parameters' => [ |
||
267 | 'targetValue' => 'YES', |
||
268 | 'targetAttribute' => null, |
||
269 | 'targetValueOrAttribute' => 'YES', |
||
270 | ], |
||
271 | ], |
||
272 | 'message' => [ |
||
273 | 'template' => 'Custom message for {targetValueOrAttribute}.', |
||
274 | 'parameters' => [ |
||
275 | 'targetValue' => 'YES', |
||
276 | 'targetAttribute' => null, |
||
277 | 'targetValueOrAttribute' => 'YES', |
||
278 | ], |
||
279 | ], |
||
280 | 'type' => 'string', |
||
281 | 'operator' => '==', |
||
282 | 'skipOnEmpty' => false, |
||
283 | 'skipOnError' => false, |
||
284 | ], |
||
285 | ], |
||
286 | [ |
||
287 | new CompareTo(null, 'test'), |
||
288 | [ |
||
289 | 'targetValue' => null, |
||
290 | 'targetAttribute' => 'test', |
||
291 | 'incorrectInputMessage' => [ |
||
292 | 'template' => 'The allowed types are integer, float, string, boolean and null.', |
||
293 | 'parameters' => [ |
||
294 | 'targetValue' => null, |
||
295 | 'targetAttribute' => 'test', |
||
296 | 'targetValueOrAttribute' => 'test', |
||
297 | ], |
||
298 | ], |
||
299 | 'incorrectDataSetTypeMessage' => [ |
||
300 | 'template' => 'The attribute value returned from a custom data set must have a scalar type.', |
||
301 | 'parameters' => [ |
||
302 | 'targetValue' => null, |
||
303 | 'targetAttribute' => 'test', |
||
304 | 'targetValueOrAttribute' => 'test', |
||
305 | ], |
||
306 | ], |
||
307 | 'message' => [ |
||
308 | 'template' => 'Value must be equal to "{targetValueOrAttribute}".', |
||
309 | 'parameters' => [ |
||
310 | 'targetValue' => null, |
||
311 | 'targetAttribute' => 'test', |
||
312 | 'targetValueOrAttribute' => 'test', |
||
313 | ], |
||
314 | ], |
||
315 | 'type' => 'string', |
||
316 | 'operator' => '==', |
||
317 | 'skipOnEmpty' => false, |
||
318 | 'skipOnError' => false, |
||
319 | ], |
||
320 | ], |
||
321 | [ |
||
322 | new CompareTo( |
||
323 | null, |
||
324 | 'test', |
||
325 | incorrectInputMessage: 'Custom message 1.', |
||
326 | incorrectDataSetTypeMessage: 'Custom message 2.', |
||
327 | message: 'Custom message 3.', |
||
328 | ), |
||
329 | [ |
||
330 | 'targetValue' => null, |
||
331 | 'targetAttribute' => 'test', |
||
332 | 'incorrectInputMessage' => [ |
||
333 | 'template' => 'Custom message 1.', |
||
334 | 'parameters' => [ |
||
335 | 'targetValue' => null, |
||
336 | 'targetAttribute' => 'test', |
||
337 | 'targetValueOrAttribute' => 'test', |
||
338 | ], |
||
339 | ], |
||
340 | 'incorrectDataSetTypeMessage' => [ |
||
341 | 'template' => 'Custom message 2.', |
||
342 | 'parameters' => [ |
||
343 | 'targetValue' => null, |
||
344 | 'targetAttribute' => 'test', |
||
345 | 'targetValueOrAttribute' => 'test', |
||
346 | ], |
||
347 | ], |
||
348 | 'message' => [ |
||
349 | 'template' => 'Custom message 3.', |
||
350 | 'parameters' => [ |
||
351 | 'targetValue' => null, |
||
352 | 'targetAttribute' => 'test', |
||
353 | 'targetValueOrAttribute' => 'test', |
||
354 | ], |
||
355 | ], |
||
356 | 'type' => 'string', |
||
357 | 'operator' => '==', |
||
358 | 'skipOnEmpty' => false, |
||
359 | 'skipOnError' => false, |
||
360 | ], |
||
361 | ], |
||
362 | [ |
||
363 | new CompareTo(1, 'test'), |
||
364 | [ |
||
365 | 'targetValue' => 1, |
||
366 | 'targetAttribute' => 'test', |
||
367 | 'incorrectInputMessage' => [ |
||
368 | 'template' => 'The allowed types are integer, float, string, boolean and null.', |
||
369 | 'parameters' => [ |
||
370 | 'targetValue' => 1, |
||
371 | 'targetAttribute' => 'test', |
||
372 | 'targetValueOrAttribute' => 1, |
||
373 | ], |
||
374 | ], |
||
375 | 'incorrectDataSetTypeMessage' => [ |
||
376 | 'template' => 'The attribute value returned from a custom data set must have a scalar type.', |
||
377 | 'parameters' => [ |
||
378 | 'targetValue' => 1, |
||
379 | 'targetAttribute' => 'test', |
||
380 | 'targetValueOrAttribute' => 1, |
||
381 | ], |
||
382 | ], |
||
383 | 'message' => [ |
||
384 | 'template' => 'Value must be equal to "{targetValueOrAttribute}".', |
||
385 | 'parameters' => [ |
||
386 | 'targetValue' => 1, |
||
387 | 'targetAttribute' => 'test', |
||
388 | 'targetValueOrAttribute' => 1, |
||
389 | ], |
||
390 | ], |
||
391 | 'type' => 'string', |
||
392 | 'operator' => '==', |
||
393 | 'skipOnEmpty' => false, |
||
394 | 'skipOnError' => false, |
||
395 | ], |
||
597 |