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 |
||
86 | class Spec |
||
87 | { |
||
88 | /** |
||
89 | * @param string $name |
||
90 | * @param array $arguments |
||
91 | * |
||
92 | * @return PlatformFunction |
||
93 | */ |
||
94 | public static function __callStatic($name, array $arguments = []) |
||
106 | |||
107 | /* |
||
108 | * Logic |
||
109 | */ |
||
110 | |||
111 | /** |
||
112 | * @return AndX |
||
113 | */ |
||
114 | public static function andX() |
||
121 | |||
122 | /** |
||
123 | * @return OrX |
||
124 | */ |
||
125 | public static function orX() |
||
132 | |||
133 | /** |
||
134 | * @param Filter $spec |
||
135 | * |
||
136 | * @return Not |
||
137 | */ |
||
138 | public static function not(Filter $spec) |
||
142 | |||
143 | /* |
||
144 | * Query modifier |
||
145 | */ |
||
146 | |||
147 | /** |
||
148 | * @param string $field |
||
149 | * @param string $newAlias |
||
150 | * @param string $dqlAlias |
||
151 | * |
||
152 | * @return Join |
||
153 | */ |
||
154 | public static function join($field, $newAlias, $dqlAlias = null) |
||
158 | |||
159 | /** |
||
160 | * @param string $field |
||
161 | * @param string $newAlias |
||
162 | * @param string $dqlAlias |
||
163 | * |
||
164 | * @return LeftJoin |
||
165 | */ |
||
166 | public static function leftJoin($field, $newAlias, $dqlAlias = null) |
||
170 | |||
171 | /** |
||
172 | * @param string $field |
||
173 | * @param string $newAlias |
||
174 | * @param string $dqlAlias |
||
175 | * |
||
176 | * @return InnerJoin |
||
177 | */ |
||
178 | public static function innerJoin($field, $newAlias, $dqlAlias = null) |
||
182 | |||
183 | /** |
||
184 | * @param string $field |
||
185 | * @param string $dqlAlias |
||
186 | * |
||
187 | * @return IndexBy |
||
188 | */ |
||
189 | public static function indexBy($field, $dqlAlias = null) |
||
193 | |||
194 | /** |
||
195 | * @param int $count |
||
196 | * |
||
197 | * @return Limit |
||
198 | */ |
||
199 | public static function limit($count) |
||
203 | |||
204 | /** |
||
205 | * @param int $count |
||
206 | * |
||
207 | * @return Offset |
||
208 | */ |
||
209 | public static function offset($count) |
||
213 | |||
214 | /** |
||
215 | * @param int $sliceSize |
||
216 | * @param int $sliceNumber |
||
217 | * |
||
218 | * @return Slice |
||
219 | */ |
||
220 | public static function slice($sliceSize, $sliceNumber = 0) |
||
224 | |||
225 | /** |
||
226 | * @param string $field |
||
227 | * @param string $order |
||
228 | * @param string|null $dqlAlias |
||
229 | * |
||
230 | * @return OrderBy |
||
231 | */ |
||
232 | public static function orderBy($field, $order = 'ASC', $dqlAlias = null) |
||
236 | |||
237 | /** |
||
238 | * @param string $field |
||
239 | * @param string $dqlAlias |
||
240 | * |
||
241 | * @return GroupBy |
||
242 | */ |
||
243 | public static function groupBy($field, $dqlAlias = null) |
||
247 | |||
248 | /* |
||
249 | * Selection |
||
250 | */ |
||
251 | |||
252 | /** |
||
253 | * @param mixed $field |
||
254 | * |
||
255 | * @return Select |
||
256 | */ |
||
257 | public static function select($field) |
||
261 | |||
262 | /** |
||
263 | * @param mixed $field |
||
264 | * |
||
265 | * @return AddSelect |
||
266 | */ |
||
267 | public static function addSelect($field) |
||
271 | |||
272 | /** |
||
273 | * @param string $dqlAlias |
||
274 | * |
||
275 | * @return SelectEntity |
||
276 | */ |
||
277 | public static function selectEntity($dqlAlias) |
||
281 | |||
282 | /** |
||
283 | * @param Filter|Operand|string $expression |
||
284 | * @param string $alias |
||
285 | * |
||
286 | * @return SelectAs |
||
287 | */ |
||
288 | public static function selectAs($expression, $alias) |
||
292 | |||
293 | /** |
||
294 | * @param Filter|Operand|string $expression |
||
295 | * @param string $alias |
||
296 | * |
||
297 | * @return SelectHiddenAs |
||
298 | */ |
||
299 | public static function selectHiddenAs($expression, $alias) |
||
303 | |||
304 | /* |
||
305 | * Result modifier |
||
306 | */ |
||
307 | |||
308 | /** |
||
309 | * @return AsArray |
||
310 | */ |
||
311 | public static function asArray() |
||
315 | |||
316 | /** |
||
317 | * @return AsSingleScalar |
||
318 | */ |
||
319 | public static function asSingleScalar() |
||
323 | |||
324 | /** |
||
325 | * @return AsScalar |
||
326 | */ |
||
327 | public static function asScalar() |
||
331 | |||
332 | /** |
||
333 | * @param int $cacheLifetime How many seconds the cached entry is valid |
||
334 | * |
||
335 | * @return Cache |
||
336 | */ |
||
337 | public static function cache($cacheLifetime) |
||
341 | |||
342 | /** |
||
343 | * @param int $roundSeconds How may seconds to round time |
||
344 | * |
||
345 | * @return RoundDateTime |
||
346 | */ |
||
347 | public static function roundDateTimeParams($roundSeconds) |
||
351 | |||
352 | /* |
||
353 | * Filters |
||
354 | */ |
||
355 | |||
356 | /** |
||
357 | * @param Operand|string $field |
||
358 | * @param string|null $dqlAlias |
||
359 | * |
||
360 | * @return IsNull |
||
361 | */ |
||
362 | public static function isNull($field, $dqlAlias = null) |
||
366 | |||
367 | /** |
||
368 | * @param Operand|string $field |
||
369 | * @param string|null $dqlAlias |
||
370 | * |
||
371 | * @return IsNotNull |
||
372 | */ |
||
373 | public static function isNotNull($field, $dqlAlias = null) |
||
377 | |||
378 | /** |
||
379 | * Make sure the $field has a value equals to $value. |
||
380 | * |
||
381 | * @param string $field |
||
382 | * @param mixed $value |
||
383 | * @param string $dqlAlias |
||
384 | * |
||
385 | * @return In |
||
386 | */ |
||
387 | public static function in($field, $value, $dqlAlias = null) |
||
391 | |||
392 | /** |
||
393 | * @param string $field |
||
394 | * @param mixed $value |
||
395 | * @param string $dqlAlias |
||
396 | * |
||
397 | * @return Not |
||
398 | */ |
||
399 | public static function notIn($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 eq($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 neq($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 lt($field, $value, $dqlAlias = null) |
||
439 | |||
440 | /** |
||
441 | * @param Operand|string $field |
||
442 | * @param Operand|mixed $value |
||
443 | * @param string|null $dqlAlias |
||
444 | * |
||
445 | * @return Comparison |
||
446 | */ |
||
447 | public static function lte($field, $value, $dqlAlias = null) |
||
451 | |||
452 | /** |
||
453 | * @param Operand|string $field |
||
454 | * @param Operand|mixed $value |
||
455 | * @param string|null $dqlAlias |
||
456 | * |
||
457 | * @return Comparison |
||
458 | */ |
||
459 | public static function gt($field, $value, $dqlAlias = null) |
||
463 | |||
464 | /** |
||
465 | * @param Operand|string $field |
||
466 | * @param Operand|mixed $value |
||
467 | * @param string|null $dqlAlias |
||
468 | * |
||
469 | * @return Comparison |
||
470 | */ |
||
471 | public static function gte($field, $value, $dqlAlias = null) |
||
475 | |||
476 | /** |
||
477 | * @param Operand|string $field |
||
478 | * @param string $value |
||
479 | * @param string $format |
||
480 | * @param string|null $dqlAlias |
||
481 | * |
||
482 | * @return Like |
||
483 | */ |
||
484 | public static function like($field, $value, $format = Like::CONTAINS, $dqlAlias = null) |
||
488 | |||
489 | /** |
||
490 | * @param string $value |
||
491 | * @param string|null $dqlAlias |
||
492 | * |
||
493 | * @return InstanceOfX |
||
494 | */ |
||
495 | public static function instanceOfX($value, $dqlAlias = null) |
||
499 | |||
500 | /** |
||
501 | * @param Operand|string $value |
||
502 | * @param Operand|string $field |
||
503 | * @param string|null $dqlAlias |
||
504 | * |
||
505 | * @return MemberOfX |
||
506 | */ |
||
507 | public static function memberOfX($value, $field, $dqlAlias = null) |
||
511 | |||
512 | /* |
||
513 | * Specifications |
||
514 | */ |
||
515 | |||
516 | /** |
||
517 | * @param Filter|QueryModifier $spec |
||
518 | * |
||
519 | * @return CountOf |
||
520 | */ |
||
521 | public static function countOf($spec) |
||
525 | |||
526 | /** |
||
527 | * @param Filter|string $spec |
||
528 | * |
||
529 | * @return Having |
||
530 | */ |
||
531 | public static function having($spec) |
||
535 | |||
536 | /* |
||
537 | * Operands |
||
538 | */ |
||
539 | |||
540 | /** |
||
541 | * @param string $fieldName |
||
542 | * |
||
543 | * @return Field |
||
544 | */ |
||
545 | public static function field($fieldName) |
||
549 | |||
550 | /** |
||
551 | * @param mixed $value |
||
552 | * @param int|string|null $valueType |
||
553 | * |
||
554 | * @return Value |
||
555 | */ |
||
556 | public static function value($value, $valueType = null) |
||
560 | |||
561 | /** |
||
562 | * @param array $values |
||
563 | * @param int|string|null $valueType |
||
564 | * |
||
565 | * @return Values |
||
566 | */ |
||
567 | public static function values($values, $valueType = null) |
||
571 | |||
572 | /** |
||
573 | * @param string $value |
||
574 | * @param string $format |
||
575 | * |
||
576 | * @return LikePattern |
||
577 | */ |
||
578 | public static function likePattern($value, $format = LikePattern::CONTAINS) |
||
582 | |||
583 | /* |
||
584 | * Arithmetic operands |
||
585 | */ |
||
586 | |||
587 | /** |
||
588 | * @param Operand|string $field |
||
589 | * @param Operand|mixed $value |
||
590 | * |
||
591 | * @return Addition |
||
592 | */ |
||
593 | public static function add($field, $value) |
||
597 | |||
598 | /** |
||
599 | * @param Operand|string $field |
||
600 | * @param Operand|mixed $value |
||
601 | * |
||
602 | * @return Subtraction |
||
603 | */ |
||
604 | public static function sub($field, $value) |
||
608 | |||
609 | /** |
||
610 | * @param Operand|string $field |
||
611 | * @param Operand|mixed $value |
||
612 | * |
||
613 | * @return Multiplication |
||
614 | */ |
||
615 | public static function mul($field, $value) |
||
619 | |||
620 | /** |
||
621 | * @param Operand|string $field |
||
622 | * @param Operand|mixed $value |
||
623 | * |
||
624 | * @return Division |
||
625 | */ |
||
626 | public static function div($field, $value) |
||
630 | |||
631 | /** |
||
632 | * @param Operand|string $field |
||
633 | * @param Operand|mixed $value |
||
634 | * |
||
635 | * @return Modulo |
||
636 | */ |
||
637 | public static function mod($field, $value) |
||
641 | |||
642 | /* |
||
643 | * Bitwise operands |
||
644 | */ |
||
645 | |||
646 | /** |
||
647 | * @param Operand|string $field |
||
648 | * @param Operand|mixed $value |
||
649 | * |
||
650 | * @return BitAnd |
||
651 | */ |
||
652 | public static function bAnd($field, $value) |
||
656 | |||
657 | /** |
||
658 | * @param Operand|string $field |
||
659 | * @param Operand|mixed $value |
||
660 | * |
||
661 | * @return BitOr |
||
662 | */ |
||
663 | public static function bOr($field, $value) |
||
667 | |||
668 | /** |
||
669 | * @param Operand|string $field |
||
670 | * @param Operand|mixed $value |
||
671 | * |
||
672 | * @return BitXor |
||
673 | */ |
||
674 | public static function bXor($field, $value) |
||
678 | |||
679 | /** |
||
680 | * @param Operand|string $field |
||
681 | * @param Operand|mixed $value |
||
682 | * |
||
683 | * @return BitLeftShift |
||
684 | */ |
||
685 | public static function bLs($field, $value) |
||
689 | |||
690 | /** |
||
691 | * @param Operand|string $field |
||
692 | * @param Operand|mixed $value |
||
693 | * |
||
694 | * @return BitRightShift |
||
695 | */ |
||
696 | public static function bRs($field, $value) |
||
700 | |||
701 | /** |
||
702 | * @param Operand|string $field |
||
703 | * |
||
704 | * @return BitNot |
||
705 | */ |
||
706 | public static function bNot($field) |
||
710 | |||
711 | /** |
||
712 | * Call DQL function. |
||
713 | * |
||
714 | * Usage: |
||
715 | * Spec::fun('CURRENT_DATE') |
||
716 | * Spec::fun('DATE_DIFF', $date1, $date2) |
||
717 | * Spec::fun('DATE_DIFF', [$date1, $date2]) |
||
718 | * |
||
719 | * @param string $functionName |
||
720 | * @param mixed $arguments |
||
721 | * |
||
722 | * @return PlatformFunction |
||
723 | */ |
||
724 | public static function fun($functionName, $arguments = []) |
||
735 | |||
736 | /** |
||
737 | * @param string $alias |
||
738 | * |
||
739 | * @return Alias |
||
740 | */ |
||
741 | public static function alias($alias) |
||
745 | } |
||
746 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.