Complex classes like Spec often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Spec, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
77 | class Spec |
||
78 | { |
||
79 | /** |
||
80 | * @param string $name |
||
81 | * @param array $arguments |
||
82 | * |
||
83 | * @return PlatformFunction |
||
84 | */ |
||
85 | public static function __callStatic($name, array $arguments = []) |
||
89 | |||
90 | /* |
||
91 | * Logic |
||
92 | */ |
||
93 | |||
94 | /** |
||
95 | * @return AndX |
||
96 | */ |
||
97 | public static function andX() |
||
104 | |||
105 | /** |
||
106 | * @return OrX |
||
107 | */ |
||
108 | public static function orX() |
||
115 | |||
116 | /** |
||
117 | * @param Filter $spec |
||
118 | * |
||
119 | * @return Not |
||
120 | */ |
||
121 | public static function not(Filter $spec) |
||
125 | |||
126 | /* |
||
127 | * Query modifier |
||
128 | */ |
||
129 | |||
130 | /** |
||
131 | * @param string $field |
||
132 | * @param string $newAlias |
||
133 | * @param string $dqlAlias |
||
134 | * |
||
135 | * @return Join |
||
136 | */ |
||
137 | public static function join($field, $newAlias, $dqlAlias = null) |
||
141 | |||
142 | /** |
||
143 | * @param string $field |
||
144 | * @param string $newAlias |
||
145 | * @param string $dqlAlias |
||
146 | * |
||
147 | * @return LeftJoin |
||
148 | */ |
||
149 | public static function leftJoin($field, $newAlias, $dqlAlias = null) |
||
153 | |||
154 | /** |
||
155 | * @param string $field |
||
156 | * @param string $newAlias |
||
157 | * @param string $dqlAlias |
||
158 | * |
||
159 | * @return InnerJoin |
||
160 | */ |
||
161 | public static function innerJoin($field, $newAlias, $dqlAlias = null) |
||
165 | |||
166 | /** |
||
167 | * @param int $count |
||
168 | * |
||
169 | * @return Limit |
||
170 | */ |
||
171 | public static function limit($count) |
||
175 | |||
176 | /** |
||
177 | * @param int $count |
||
178 | * |
||
179 | * @return Offset |
||
180 | */ |
||
181 | public static function offset($count) |
||
185 | |||
186 | /** |
||
187 | * @param int $sliceSize |
||
188 | * @param int $sliceNumber |
||
189 | * |
||
190 | * @return Slice |
||
191 | */ |
||
192 | public static function slice($sliceSize, $sliceNumber = 0) |
||
196 | |||
197 | /** |
||
198 | * @param string $field |
||
199 | * @param string $order |
||
200 | * @param string|null $dqlAlias |
||
201 | * |
||
202 | * @return OrderBy |
||
203 | */ |
||
204 | public static function orderBy($field, $order = 'ASC', $dqlAlias = null) |
||
208 | |||
209 | /** |
||
210 | * @param string $field |
||
211 | * @param string $dqlAlias |
||
212 | * |
||
213 | * @return GroupBy |
||
214 | */ |
||
215 | public static function groupBy($field, $dqlAlias = null) |
||
219 | |||
220 | /* |
||
221 | * Selection |
||
222 | */ |
||
223 | |||
224 | /** |
||
225 | * @param mixed $field |
||
226 | * |
||
227 | * @return Select |
||
228 | */ |
||
229 | public static function select($field) |
||
233 | |||
234 | /** |
||
235 | * @param mixed $field |
||
236 | * |
||
237 | * @return AddSelect |
||
238 | */ |
||
239 | public static function addSelect($field) |
||
243 | |||
244 | /** |
||
245 | * @param string $dqlAlias |
||
246 | * |
||
247 | * @return SelectEntity |
||
248 | */ |
||
249 | public static function selectEntity($dqlAlias) |
||
253 | |||
254 | /** |
||
255 | * @param Filter|Operand|string $expression |
||
256 | * @param string $alias |
||
257 | * |
||
258 | * @return SelectAs |
||
259 | */ |
||
260 | public static function selectAs($expression, $alias) |
||
264 | |||
265 | /** |
||
266 | * @param Filter|Operand|string $expression |
||
267 | * @param string $alias |
||
268 | * |
||
269 | * @return SelectHiddenAs |
||
270 | */ |
||
271 | public static function selectHiddenAs($expression, $alias) |
||
275 | |||
276 | /* |
||
277 | * Result modifier |
||
278 | */ |
||
279 | |||
280 | /** |
||
281 | * @return AsArray |
||
282 | */ |
||
283 | public static function asArray() |
||
287 | |||
288 | /** |
||
289 | * @return AsSingleScalar |
||
290 | */ |
||
291 | public static function asSingleScalar() |
||
295 | |||
296 | /** |
||
297 | * @param int $cacheLifetime How many seconds the cached entry is valid |
||
298 | * |
||
299 | * @return Cache |
||
300 | */ |
||
301 | public static function cache($cacheLifetime) |
||
305 | |||
306 | /** |
||
307 | * @param int $roundSeconds How may seconds to round time |
||
308 | * |
||
309 | * @return RoundDateTime |
||
310 | */ |
||
311 | public static function roundDateTimeParams($roundSeconds) |
||
315 | |||
316 | /* |
||
317 | * Filters |
||
318 | */ |
||
319 | |||
320 | /** |
||
321 | * @param Operand|string $field |
||
322 | * @param string|null $dqlAlias |
||
323 | * |
||
324 | * @return IsNull |
||
325 | */ |
||
326 | public static function isNull($field, $dqlAlias = null) |
||
330 | |||
331 | /** |
||
332 | * @param Operand|string $field |
||
333 | * @param string|null $dqlAlias |
||
334 | * |
||
335 | * @return IsNotNull |
||
336 | */ |
||
337 | public static function isNotNull($field, $dqlAlias = null) |
||
341 | |||
342 | /** |
||
343 | * Make sure the $field has a value equals to $value. |
||
344 | * |
||
345 | * @param string $field |
||
346 | * @param mixed $value |
||
347 | * @param string $dqlAlias |
||
348 | * |
||
349 | * @return In |
||
350 | */ |
||
351 | public static function in($field, $value, $dqlAlias = null) |
||
355 | |||
356 | /** |
||
357 | * @param string $field |
||
358 | * @param mixed $value |
||
359 | * @param string $dqlAlias |
||
360 | * |
||
361 | * @return Not |
||
362 | */ |
||
363 | public static function notIn($field, $value, $dqlAlias = null) |
||
367 | |||
368 | /** |
||
369 | * @param Operand|string $field |
||
370 | * @param Operand|mixed $value |
||
371 | * @param string|null $dqlAlias |
||
372 | * |
||
373 | * @return Comparison |
||
374 | */ |
||
375 | public static function eq($field, $value, $dqlAlias = null) |
||
379 | |||
380 | /** |
||
381 | * @param Operand|string $field |
||
382 | * @param Operand|mixed $value |
||
383 | * @param string|null $dqlAlias |
||
384 | * |
||
385 | * @return Comparison |
||
386 | */ |
||
387 | public static function neq($field, $value, $dqlAlias = null) |
||
391 | |||
392 | /** |
||
393 | * @param Operand|string $field |
||
394 | * @param Operand|mixed $value |
||
395 | * @param string|null $dqlAlias |
||
396 | * |
||
397 | * @return Comparison |
||
398 | */ |
||
399 | public static function lt($field, $value, $dqlAlias = null) |
||
403 | |||
404 | /** |
||
405 | * @param Operand|string $field |
||
406 | * @param Operand|mixed $value |
||
407 | * @param string|null $dqlAlias |
||
408 | * |
||
409 | * @return Comparison |
||
410 | */ |
||
411 | public static function lte($field, $value, $dqlAlias = null) |
||
415 | |||
416 | /** |
||
417 | * @param Operand|string $field |
||
418 | * @param Operand|mixed $value |
||
419 | * @param string|null $dqlAlias |
||
420 | * |
||
421 | * @return Comparison |
||
422 | */ |
||
423 | public static function gt($field, $value, $dqlAlias = null) |
||
427 | |||
428 | /** |
||
429 | * @param Operand|string $field |
||
430 | * @param Operand|mixed $value |
||
431 | * @param string|null $dqlAlias |
||
432 | * |
||
433 | * @return Comparison |
||
434 | */ |
||
435 | public static function gte($field, $value, $dqlAlias = null) |
||
439 | |||
440 | /** |
||
441 | * @param Operand|string $field |
||
442 | * @param string $value |
||
443 | * @param string $format |
||
444 | * @param string|null $dqlAlias |
||
445 | * |
||
446 | * @return Like |
||
447 | */ |
||
448 | public static function like($field, $value, $format = Like::CONTAINS, $dqlAlias = null) |
||
452 | |||
453 | /** |
||
454 | * @param string $value |
||
455 | * @param string|null $dqlAlias |
||
456 | * |
||
457 | * @return InstanceOfX |
||
458 | */ |
||
459 | public static function instanceOfX($value, $dqlAlias = null) |
||
463 | |||
464 | /* |
||
465 | * Specifications |
||
466 | */ |
||
467 | |||
468 | /** |
||
469 | * @param Filter|QueryModifier $spec |
||
470 | * |
||
471 | * @return CountOf |
||
472 | */ |
||
473 | public static function countOf($spec) |
||
477 | |||
478 | /** |
||
479 | * @param Filter|string $spec |
||
480 | * |
||
481 | * @return Having |
||
482 | */ |
||
483 | public static function having($spec) |
||
487 | |||
488 | /* |
||
489 | * Operands |
||
490 | */ |
||
491 | |||
492 | /** |
||
493 | * @param string $fieldName |
||
494 | * |
||
495 | * @return Field |
||
496 | */ |
||
497 | public static function field($fieldName) |
||
501 | |||
502 | /** |
||
503 | * @param mixed $value |
||
504 | * @param int|string|null $valueType |
||
505 | * |
||
506 | * @return Value |
||
507 | */ |
||
508 | public static function value($value, $valueType = null) |
||
512 | |||
513 | /** |
||
514 | * @param array $values |
||
515 | * @param int|string|null $valueType |
||
516 | * |
||
517 | * @return Values |
||
518 | */ |
||
519 | public static function values($values, $valueType = null) |
||
523 | |||
524 | /** |
||
525 | * @param string $value |
||
526 | * @param string $format |
||
527 | * |
||
528 | * @return LikePattern |
||
529 | */ |
||
530 | public static function likePattern($value, $format = LikePattern::CONTAINS) |
||
534 | |||
535 | /* |
||
536 | * Arithmetic operands |
||
537 | */ |
||
538 | |||
539 | /** |
||
540 | * @param Operand|string $field |
||
541 | * @param Operand|mixed $value |
||
542 | * |
||
543 | * @return Addition |
||
544 | */ |
||
545 | public static function add($field, $value) |
||
549 | |||
550 | /** |
||
551 | * @param Operand|string $field |
||
552 | * @param Operand|mixed $value |
||
553 | * |
||
554 | * @return Subtraction |
||
555 | */ |
||
556 | public static function sub($field, $value) |
||
560 | |||
561 | /** |
||
562 | * @param Operand|string $field |
||
563 | * @param Operand|mixed $value |
||
564 | * |
||
565 | * @return Multiplication |
||
566 | */ |
||
567 | public static function mul($field, $value) |
||
571 | |||
572 | /** |
||
573 | * @param Operand|string $field |
||
574 | * @param Operand|mixed $value |
||
575 | * |
||
576 | * @return Division |
||
577 | */ |
||
578 | public static function div($field, $value) |
||
582 | |||
583 | /** |
||
584 | * @param Operand|string $field |
||
585 | * @param Operand|mixed $value |
||
586 | * |
||
587 | * @return Modulo |
||
588 | */ |
||
589 | public static function mod($field, $value) |
||
593 | |||
594 | /** |
||
595 | * @param string $functionName |
||
596 | * @param mixed $arguments |
||
597 | * |
||
598 | * @return PlatformFunction |
||
599 | */ |
||
600 | public static function fun($functionName, $arguments = []) |
||
606 | |||
607 | /** |
||
608 | * @param string $alias |
||
609 | * |
||
610 | * @return Alias |
||
611 | */ |
||
612 | public static function alias($alias) |
||
616 | } |
||
617 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.