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 |
||
84 | class Spec |
||
85 | { |
||
86 | /** |
||
87 | * @param string $name |
||
88 | * @param array $arguments |
||
89 | * |
||
90 | * @return PlatformFunction |
||
91 | */ |
||
92 | public static function __callStatic($name, array $arguments = []) |
||
96 | |||
97 | /* |
||
98 | * Logic |
||
99 | */ |
||
100 | |||
101 | /** |
||
102 | * @return AndX |
||
103 | */ |
||
104 | public static function andX() |
||
111 | |||
112 | /** |
||
113 | * @return OrX |
||
114 | */ |
||
115 | public static function orX() |
||
122 | |||
123 | /** |
||
124 | * @param Filter $spec |
||
125 | * |
||
126 | * @return Not |
||
127 | */ |
||
128 | public static function not(Filter $spec) |
||
132 | |||
133 | /* |
||
134 | * Query modifier |
||
135 | */ |
||
136 | |||
137 | /** |
||
138 | * @param string $field |
||
139 | * @param string $newAlias |
||
140 | * @param string $dqlAlias |
||
141 | * |
||
142 | * @return Join |
||
143 | */ |
||
144 | public static function join($field, $newAlias, $dqlAlias = null) |
||
148 | |||
149 | /** |
||
150 | * @param string $field |
||
151 | * @param string $newAlias |
||
152 | * @param string $dqlAlias |
||
153 | * |
||
154 | * @return LeftJoin |
||
155 | */ |
||
156 | public static function leftJoin($field, $newAlias, $dqlAlias = null) |
||
160 | |||
161 | /** |
||
162 | * @param string $field |
||
163 | * @param string $newAlias |
||
164 | * @param string $dqlAlias |
||
165 | * |
||
166 | * @return InnerJoin |
||
167 | */ |
||
168 | public static function innerJoin($field, $newAlias, $dqlAlias = null) |
||
172 | |||
173 | /** |
||
174 | * @param int $count |
||
175 | * |
||
176 | * @return Limit |
||
177 | */ |
||
178 | public static function limit($count) |
||
182 | |||
183 | /** |
||
184 | * @param int $count |
||
185 | * |
||
186 | * @return Offset |
||
187 | */ |
||
188 | public static function offset($count) |
||
192 | |||
193 | /** |
||
194 | * @param int $sliceSize |
||
195 | * @param int $sliceNumber |
||
196 | * |
||
197 | * @return Slice |
||
198 | */ |
||
199 | public static function slice($sliceSize, $sliceNumber = 0) |
||
203 | |||
204 | /** |
||
205 | * @param string $field |
||
206 | * @param string $order |
||
207 | * @param string|null $dqlAlias |
||
208 | * |
||
209 | * @return OrderBy |
||
210 | */ |
||
211 | public static function orderBy($field, $order = 'ASC', $dqlAlias = null) |
||
215 | |||
216 | /** |
||
217 | * @param string $field |
||
218 | * @param string $dqlAlias |
||
219 | * |
||
220 | * @return GroupBy |
||
221 | */ |
||
222 | public static function groupBy($field, $dqlAlias = null) |
||
226 | |||
227 | /* |
||
228 | * Selection |
||
229 | */ |
||
230 | |||
231 | /** |
||
232 | * @param mixed $field |
||
233 | * |
||
234 | * @return Select |
||
235 | */ |
||
236 | public static function select($field) |
||
240 | |||
241 | /** |
||
242 | * @param mixed $field |
||
243 | * |
||
244 | * @return AddSelect |
||
245 | */ |
||
246 | public static function addSelect($field) |
||
250 | |||
251 | /** |
||
252 | * @param string $dqlAlias |
||
253 | * |
||
254 | * @return SelectEntity |
||
255 | */ |
||
256 | public static function selectEntity($dqlAlias) |
||
260 | |||
261 | /** |
||
262 | * @param Filter|Operand|string $expression |
||
263 | * @param string $alias |
||
264 | * |
||
265 | * @return SelectAs |
||
266 | */ |
||
267 | public static function selectAs($expression, $alias) |
||
271 | |||
272 | /** |
||
273 | * @param Filter|Operand|string $expression |
||
274 | * @param string $alias |
||
275 | * |
||
276 | * @return SelectHiddenAs |
||
277 | */ |
||
278 | public static function selectHiddenAs($expression, $alias) |
||
282 | |||
283 | /* |
||
284 | * Result modifier |
||
285 | */ |
||
286 | |||
287 | /** |
||
288 | * @return AsArray |
||
289 | */ |
||
290 | public static function asArray() |
||
294 | |||
295 | /** |
||
296 | * @return AsSingleScalar |
||
297 | */ |
||
298 | public static function asSingleScalar() |
||
302 | |||
303 | /** |
||
304 | * @return AsScalar |
||
305 | */ |
||
306 | public static function asScalar() |
||
310 | |||
311 | /** |
||
312 | * @param int $cacheLifetime How many seconds the cached entry is valid |
||
313 | * |
||
314 | * @return Cache |
||
315 | */ |
||
316 | public static function cache($cacheLifetime) |
||
320 | |||
321 | /** |
||
322 | * @param int $roundSeconds How may seconds to round time |
||
323 | * |
||
324 | * @return RoundDateTime |
||
325 | */ |
||
326 | public static function roundDateTimeParams($roundSeconds) |
||
330 | |||
331 | /* |
||
332 | * Filters |
||
333 | */ |
||
334 | |||
335 | /** |
||
336 | * @param Operand|string $field |
||
337 | * @param string|null $dqlAlias |
||
338 | * |
||
339 | * @return IsNull |
||
340 | */ |
||
341 | public static function isNull($field, $dqlAlias = null) |
||
345 | |||
346 | /** |
||
347 | * @param Operand|string $field |
||
348 | * @param string|null $dqlAlias |
||
349 | * |
||
350 | * @return IsNotNull |
||
351 | */ |
||
352 | public static function isNotNull($field, $dqlAlias = null) |
||
356 | |||
357 | /** |
||
358 | * Make sure the $field has a value equals to $value. |
||
359 | * |
||
360 | * @param string $field |
||
361 | * @param mixed $value |
||
362 | * @param string $dqlAlias |
||
363 | * |
||
364 | * @return In |
||
365 | */ |
||
366 | public static function in($field, $value, $dqlAlias = null) |
||
370 | |||
371 | /** |
||
372 | * @param string $field |
||
373 | * @param mixed $value |
||
374 | * @param string $dqlAlias |
||
375 | * |
||
376 | * @return Not |
||
377 | */ |
||
378 | public static function notIn($field, $value, $dqlAlias = null) |
||
382 | |||
383 | /** |
||
384 | * @param Operand|string $field |
||
385 | * @param Operand|mixed $value |
||
386 | * @param string|null $dqlAlias |
||
387 | * |
||
388 | * @return Comparison |
||
389 | */ |
||
390 | public static function eq($field, $value, $dqlAlias = null) |
||
394 | |||
395 | /** |
||
396 | * @param Operand|string $field |
||
397 | * @param Operand|mixed $value |
||
398 | * @param string|null $dqlAlias |
||
399 | * |
||
400 | * @return Comparison |
||
401 | */ |
||
402 | public static function neq($field, $value, $dqlAlias = null) |
||
406 | |||
407 | /** |
||
408 | * @param Operand|string $field |
||
409 | * @param Operand|mixed $value |
||
410 | * @param string|null $dqlAlias |
||
411 | * |
||
412 | * @return Comparison |
||
413 | */ |
||
414 | public static function lt($field, $value, $dqlAlias = null) |
||
418 | |||
419 | /** |
||
420 | * @param Operand|string $field |
||
421 | * @param Operand|mixed $value |
||
422 | * @param string|null $dqlAlias |
||
423 | * |
||
424 | * @return Comparison |
||
425 | */ |
||
426 | public static function lte($field, $value, $dqlAlias = null) |
||
430 | |||
431 | /** |
||
432 | * @param Operand|string $field |
||
433 | * @param Operand|mixed $value |
||
434 | * @param string|null $dqlAlias |
||
435 | * |
||
436 | * @return Comparison |
||
437 | */ |
||
438 | public static function gt($field, $value, $dqlAlias = null) |
||
442 | |||
443 | /** |
||
444 | * @param Operand|string $field |
||
445 | * @param Operand|mixed $value |
||
446 | * @param string|null $dqlAlias |
||
447 | * |
||
448 | * @return Comparison |
||
449 | */ |
||
450 | public static function gte($field, $value, $dqlAlias = null) |
||
454 | |||
455 | /** |
||
456 | * @param Operand|string $field |
||
457 | * @param string $value |
||
458 | * @param string $format |
||
459 | * @param string|null $dqlAlias |
||
460 | * |
||
461 | * @return Like |
||
462 | */ |
||
463 | public static function like($field, $value, $format = Like::CONTAINS, $dqlAlias = null) |
||
467 | |||
468 | /** |
||
469 | * @param string $value |
||
470 | * @param string|null $dqlAlias |
||
471 | * |
||
472 | * @return InstanceOfX |
||
473 | */ |
||
474 | public static function instanceOfX($value, $dqlAlias = null) |
||
478 | |||
479 | /* |
||
480 | * Specifications |
||
481 | */ |
||
482 | |||
483 | /** |
||
484 | * @param Filter|QueryModifier $spec |
||
485 | * |
||
486 | * @return CountOf |
||
487 | */ |
||
488 | public static function countOf($spec) |
||
492 | |||
493 | /** |
||
494 | * @param Filter|string $spec |
||
495 | * |
||
496 | * @return Having |
||
497 | */ |
||
498 | public static function having($spec) |
||
502 | |||
503 | /* |
||
504 | * Operands |
||
505 | */ |
||
506 | |||
507 | /** |
||
508 | * @param string $fieldName |
||
509 | * |
||
510 | * @return Field |
||
511 | */ |
||
512 | public static function field($fieldName) |
||
516 | |||
517 | /** |
||
518 | * @param mixed $value |
||
519 | * @param int|string|null $valueType |
||
520 | * |
||
521 | * @return Value |
||
522 | */ |
||
523 | public static function value($value, $valueType = null) |
||
527 | |||
528 | /** |
||
529 | * @param array $values |
||
530 | * @param int|string|null $valueType |
||
531 | * |
||
532 | * @return Values |
||
533 | */ |
||
534 | public static function values($values, $valueType = null) |
||
538 | |||
539 | /** |
||
540 | * @param string $value |
||
541 | * @param string $format |
||
542 | * |
||
543 | * @return LikePattern |
||
544 | */ |
||
545 | public static function likePattern($value, $format = LikePattern::CONTAINS) |
||
549 | |||
550 | /* |
||
551 | * Arithmetic operands |
||
552 | */ |
||
553 | |||
554 | /** |
||
555 | * @param Operand|string $field |
||
556 | * @param Operand|mixed $value |
||
557 | * |
||
558 | * @return Addition |
||
559 | */ |
||
560 | public static function add($field, $value) |
||
564 | |||
565 | /** |
||
566 | * @param Operand|string $field |
||
567 | * @param Operand|mixed $value |
||
568 | * |
||
569 | * @return Subtraction |
||
570 | */ |
||
571 | public static function sub($field, $value) |
||
575 | |||
576 | /** |
||
577 | * @param Operand|string $field |
||
578 | * @param Operand|mixed $value |
||
579 | * |
||
580 | * @return Multiplication |
||
581 | */ |
||
582 | public static function mul($field, $value) |
||
586 | |||
587 | /** |
||
588 | * @param Operand|string $field |
||
589 | * @param Operand|mixed $value |
||
590 | * |
||
591 | * @return Division |
||
592 | */ |
||
593 | public static function div($field, $value) |
||
597 | |||
598 | /** |
||
599 | * @param Operand|string $field |
||
600 | * @param Operand|mixed $value |
||
601 | * |
||
602 | * @return Modulo |
||
603 | */ |
||
604 | public static function mod($field, $value) |
||
608 | |||
609 | /* |
||
610 | * Bitwise operands |
||
611 | */ |
||
612 | |||
613 | /** |
||
614 | * @param Operand|string $field |
||
615 | * @param Operand|mixed $value |
||
616 | * |
||
617 | * @return BitAnd |
||
618 | */ |
||
619 | public static function bAnd($field, $value) |
||
623 | |||
624 | /** |
||
625 | * @param Operand|string $field |
||
626 | * @param Operand|mixed $value |
||
627 | * |
||
628 | * @return BitOr |
||
629 | */ |
||
630 | public static function bOr($field, $value) |
||
634 | |||
635 | /** |
||
636 | * @param Operand|string $field |
||
637 | * @param Operand|mixed $value |
||
638 | * |
||
639 | * @return BitXor |
||
640 | */ |
||
641 | public static function bXor($field, $value) |
||
645 | |||
646 | /** |
||
647 | * @param Operand|string $field |
||
648 | * @param Operand|mixed $value |
||
649 | * |
||
650 | * @return BitLeftShift |
||
651 | */ |
||
652 | public static function bLs($field, $value) |
||
656 | |||
657 | /** |
||
658 | * @param Operand|string $field |
||
659 | * @param Operand|mixed $value |
||
660 | * |
||
661 | * @return BitRightShift |
||
662 | */ |
||
663 | public static function bRs($field, $value) |
||
667 | |||
668 | /** |
||
669 | * @param Operand|string $field |
||
670 | * |
||
671 | * @return BitNot |
||
672 | */ |
||
673 | public static function bNot($field) |
||
677 | |||
678 | /** |
||
679 | * @param string $functionName |
||
680 | * @param mixed $arguments |
||
681 | * |
||
682 | * @return PlatformFunction |
||
683 | */ |
||
684 | public static function fun($functionName, $arguments = []) |
||
690 | |||
691 | /** |
||
692 | * @param string $alias |
||
693 | * |
||
694 | * @return Alias |
||
695 | */ |
||
696 | public static function alias($alias) |
||
700 | } |
||
701 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.