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 |
||
85 | class Spec |
||
86 | { |
||
87 | /** |
||
88 | * @param string $name |
||
89 | * @param array $arguments |
||
90 | * |
||
91 | * @return PlatformFunction |
||
92 | */ |
||
93 | public static function __callStatic($name, array $arguments = []) |
||
105 | |||
106 | /* |
||
107 | * Logic |
||
108 | */ |
||
109 | |||
110 | /** |
||
111 | * @return AndX |
||
112 | */ |
||
113 | public static function andX() |
||
120 | |||
121 | /** |
||
122 | * @return OrX |
||
123 | */ |
||
124 | public static function orX() |
||
131 | |||
132 | /** |
||
133 | * @param Filter $spec |
||
134 | * |
||
135 | * @return Not |
||
136 | */ |
||
137 | public static function not(Filter $spec) |
||
141 | |||
142 | /* |
||
143 | * Query modifier |
||
144 | */ |
||
145 | |||
146 | /** |
||
147 | * @param string $field |
||
148 | * @param string $newAlias |
||
149 | * @param string $dqlAlias |
||
150 | * |
||
151 | * @return Join |
||
152 | */ |
||
153 | public static function join($field, $newAlias, $dqlAlias = null) |
||
157 | |||
158 | /** |
||
159 | * @param string $field |
||
160 | * @param string $newAlias |
||
161 | * @param string $dqlAlias |
||
162 | * |
||
163 | * @return LeftJoin |
||
164 | */ |
||
165 | public static function leftJoin($field, $newAlias, $dqlAlias = null) |
||
169 | |||
170 | /** |
||
171 | * @param string $field |
||
172 | * @param string $newAlias |
||
173 | * @param string $dqlAlias |
||
174 | * |
||
175 | * @return InnerJoin |
||
176 | */ |
||
177 | public static function innerJoin($field, $newAlias, $dqlAlias = null) |
||
181 | |||
182 | /** |
||
183 | * @param int $count |
||
184 | * |
||
185 | * @return Limit |
||
186 | */ |
||
187 | public static function limit($count) |
||
191 | |||
192 | /** |
||
193 | * @param int $count |
||
194 | * |
||
195 | * @return Offset |
||
196 | */ |
||
197 | public static function offset($count) |
||
201 | |||
202 | /** |
||
203 | * @param int $sliceSize |
||
204 | * @param int $sliceNumber |
||
205 | * |
||
206 | * @return Slice |
||
207 | */ |
||
208 | public static function slice($sliceSize, $sliceNumber = 0) |
||
212 | |||
213 | /** |
||
214 | * @param string $field |
||
215 | * @param string $order |
||
216 | * @param string|null $dqlAlias |
||
217 | * |
||
218 | * @return OrderBy |
||
219 | */ |
||
220 | public static function orderBy($field, $order = 'ASC', $dqlAlias = null) |
||
224 | |||
225 | /** |
||
226 | * @param string $field |
||
227 | * @param string $dqlAlias |
||
228 | * |
||
229 | * @return GroupBy |
||
230 | */ |
||
231 | public static function groupBy($field, $dqlAlias = null) |
||
235 | |||
236 | /* |
||
237 | * Selection |
||
238 | */ |
||
239 | |||
240 | /** |
||
241 | * @param mixed $field |
||
242 | * |
||
243 | * @return Select |
||
244 | */ |
||
245 | public static function select($field) |
||
249 | |||
250 | /** |
||
251 | * @param mixed $field |
||
252 | * |
||
253 | * @return AddSelect |
||
254 | */ |
||
255 | public static function addSelect($field) |
||
259 | |||
260 | /** |
||
261 | * @param string $dqlAlias |
||
262 | * |
||
263 | * @return SelectEntity |
||
264 | */ |
||
265 | public static function selectEntity($dqlAlias) |
||
269 | |||
270 | /** |
||
271 | * @param Filter|Operand|string $expression |
||
272 | * @param string $alias |
||
273 | * |
||
274 | * @return SelectAs |
||
275 | */ |
||
276 | public static function selectAs($expression, $alias) |
||
280 | |||
281 | /** |
||
282 | * @param Filter|Operand|string $expression |
||
283 | * @param string $alias |
||
284 | * |
||
285 | * @return SelectHiddenAs |
||
286 | */ |
||
287 | public static function selectHiddenAs($expression, $alias) |
||
291 | |||
292 | /* |
||
293 | * Result modifier |
||
294 | */ |
||
295 | |||
296 | /** |
||
297 | * @return AsArray |
||
298 | */ |
||
299 | public static function asArray() |
||
303 | |||
304 | /** |
||
305 | * @return AsSingleScalar |
||
306 | */ |
||
307 | public static function asSingleScalar() |
||
311 | |||
312 | /** |
||
313 | * @return AsScalar |
||
314 | */ |
||
315 | public static function asScalar() |
||
319 | |||
320 | /** |
||
321 | * @param int $cacheLifetime How many seconds the cached entry is valid |
||
322 | * |
||
323 | * @return Cache |
||
324 | */ |
||
325 | public static function cache($cacheLifetime) |
||
329 | |||
330 | /** |
||
331 | * @param int $roundSeconds How may seconds to round time |
||
332 | * |
||
333 | * @return RoundDateTime |
||
334 | */ |
||
335 | public static function roundDateTimeParams($roundSeconds) |
||
339 | |||
340 | /* |
||
341 | * Filters |
||
342 | */ |
||
343 | |||
344 | /** |
||
345 | * @param Operand|string $field |
||
346 | * @param string|null $dqlAlias |
||
347 | * |
||
348 | * @return IsNull |
||
349 | */ |
||
350 | public static function isNull($field, $dqlAlias = null) |
||
354 | |||
355 | /** |
||
356 | * @param Operand|string $field |
||
357 | * @param string|null $dqlAlias |
||
358 | * |
||
359 | * @return IsNotNull |
||
360 | */ |
||
361 | public static function isNotNull($field, $dqlAlias = null) |
||
365 | |||
366 | /** |
||
367 | * Make sure the $field has a value equals to $value. |
||
368 | * |
||
369 | * @param string $field |
||
370 | * @param mixed $value |
||
371 | * @param string $dqlAlias |
||
372 | * |
||
373 | * @return In |
||
374 | */ |
||
375 | public static function in($field, $value, $dqlAlias = null) |
||
379 | |||
380 | /** |
||
381 | * @param string $field |
||
382 | * @param mixed $value |
||
383 | * @param string $dqlAlias |
||
384 | * |
||
385 | * @return Not |
||
386 | */ |
||
387 | public static function notIn($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 eq($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 neq($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 lt($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 lte($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 gt($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 gte($field, $value, $dqlAlias = null) |
||
463 | |||
464 | /** |
||
465 | * @param Operand|string $field |
||
466 | * @param string $value |
||
467 | * @param string $format |
||
468 | * @param string|null $dqlAlias |
||
469 | * |
||
470 | * @return Like |
||
471 | */ |
||
472 | public static function like($field, $value, $format = Like::CONTAINS, $dqlAlias = null) |
||
476 | |||
477 | /** |
||
478 | * @param string $value |
||
479 | * @param string|null $dqlAlias |
||
480 | * |
||
481 | * @return InstanceOfX |
||
482 | */ |
||
483 | public static function instanceOfX($value, $dqlAlias = null) |
||
487 | |||
488 | /** |
||
489 | * @param string $value |
||
490 | * @param string|null $dqlAlias |
||
491 | * |
||
492 | * @return MemberOfX |
||
493 | */ |
||
494 | public static function memberOfX($value, $dqlAlias = null) |
||
498 | |||
499 | /* |
||
500 | * Specifications |
||
501 | */ |
||
502 | |||
503 | /** |
||
504 | * @param Filter|QueryModifier $spec |
||
505 | * |
||
506 | * @return CountOf |
||
507 | */ |
||
508 | public static function countOf($spec) |
||
512 | |||
513 | /** |
||
514 | * @param Filter|string $spec |
||
515 | * |
||
516 | * @return Having |
||
517 | */ |
||
518 | public static function having($spec) |
||
522 | |||
523 | /* |
||
524 | * Operands |
||
525 | */ |
||
526 | |||
527 | /** |
||
528 | * @param string $fieldName |
||
529 | * |
||
530 | * @return Field |
||
531 | */ |
||
532 | public static function field($fieldName) |
||
536 | |||
537 | /** |
||
538 | * @param mixed $value |
||
539 | * @param int|string|null $valueType |
||
540 | * |
||
541 | * @return Value |
||
542 | */ |
||
543 | public static function value($value, $valueType = null) |
||
547 | |||
548 | /** |
||
549 | * @param array $values |
||
550 | * @param int|string|null $valueType |
||
551 | * |
||
552 | * @return Values |
||
553 | */ |
||
554 | public static function values($values, $valueType = null) |
||
558 | |||
559 | /** |
||
560 | * @param string $value |
||
561 | * @param string $format |
||
562 | * |
||
563 | * @return LikePattern |
||
564 | */ |
||
565 | public static function likePattern($value, $format = LikePattern::CONTAINS) |
||
569 | |||
570 | /* |
||
571 | * Arithmetic operands |
||
572 | */ |
||
573 | |||
574 | /** |
||
575 | * @param Operand|string $field |
||
576 | * @param Operand|mixed $value |
||
577 | * |
||
578 | * @return Addition |
||
579 | */ |
||
580 | public static function add($field, $value) |
||
584 | |||
585 | /** |
||
586 | * @param Operand|string $field |
||
587 | * @param Operand|mixed $value |
||
588 | * |
||
589 | * @return Subtraction |
||
590 | */ |
||
591 | public static function sub($field, $value) |
||
595 | |||
596 | /** |
||
597 | * @param Operand|string $field |
||
598 | * @param Operand|mixed $value |
||
599 | * |
||
600 | * @return Multiplication |
||
601 | */ |
||
602 | public static function mul($field, $value) |
||
606 | |||
607 | /** |
||
608 | * @param Operand|string $field |
||
609 | * @param Operand|mixed $value |
||
610 | * |
||
611 | * @return Division |
||
612 | */ |
||
613 | public static function div($field, $value) |
||
617 | |||
618 | /** |
||
619 | * @param Operand|string $field |
||
620 | * @param Operand|mixed $value |
||
621 | * |
||
622 | * @return Modulo |
||
623 | */ |
||
624 | public static function mod($field, $value) |
||
628 | |||
629 | /* |
||
630 | * Bitwise operands |
||
631 | */ |
||
632 | |||
633 | /** |
||
634 | * @param Operand|string $field |
||
635 | * @param Operand|mixed $value |
||
636 | * |
||
637 | * @return BitAnd |
||
638 | */ |
||
639 | public static function bAnd($field, $value) |
||
643 | |||
644 | /** |
||
645 | * @param Operand|string $field |
||
646 | * @param Operand|mixed $value |
||
647 | * |
||
648 | * @return BitOr |
||
649 | */ |
||
650 | public static function bOr($field, $value) |
||
654 | |||
655 | /** |
||
656 | * @param Operand|string $field |
||
657 | * @param Operand|mixed $value |
||
658 | * |
||
659 | * @return BitXor |
||
660 | */ |
||
661 | public static function bXor($field, $value) |
||
665 | |||
666 | /** |
||
667 | * @param Operand|string $field |
||
668 | * @param Operand|mixed $value |
||
669 | * |
||
670 | * @return BitLeftShift |
||
671 | */ |
||
672 | public static function bLs($field, $value) |
||
676 | |||
677 | /** |
||
678 | * @param Operand|string $field |
||
679 | * @param Operand|mixed $value |
||
680 | * |
||
681 | * @return BitRightShift |
||
682 | */ |
||
683 | public static function bRs($field, $value) |
||
687 | |||
688 | /** |
||
689 | * @param Operand|string $field |
||
690 | * |
||
691 | * @return BitNot |
||
692 | */ |
||
693 | public static function bNot($field) |
||
697 | |||
698 | /** |
||
699 | * Call DQL function. |
||
700 | * |
||
701 | * Usage: |
||
702 | * Spec::fun('CURRENT_DATE') |
||
703 | * Spec::fun('DATE_DIFF', $date1, $date2) |
||
704 | * Spec::fun('DATE_DIFF', [$date1, $date2]) |
||
705 | * |
||
706 | * @param string $functionName |
||
707 | * @param mixed $arguments |
||
708 | * |
||
709 | * @return PlatformFunction |
||
710 | */ |
||
711 | public static function fun($functionName, $arguments = []) |
||
722 | |||
723 | /** |
||
724 | * @param string $alias |
||
725 | * |
||
726 | * @return Alias |
||
727 | */ |
||
728 | public static function alias($alias) |
||
732 | } |
||
733 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.