Complex classes like ComparisonUtils 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 ComparisonUtils, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 7 | class ComparisonUtils |
||
| 8 | { |
||
| 9 | public static function equals($a, $b): bool |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Compares two values according to their type. |
||
| 40 | * |
||
| 41 | * @param mixed $a |
||
| 42 | * @param mixed $b |
||
| 43 | * @return int the comparison result: negative integer, zero, or positive integer if <tt>$this</tt> is less than, |
||
| 44 | * equal to, or greater than <tt>$other</tt>, respectively |
||
| 45 | * @throws IncomparableException if the values are incomparable |
||
| 46 | * @throws \InvalidArgumentException if either of values is <tt>null</tt> |
||
| 47 | */ |
||
| 48 | public static function compareValues($a, $b): int |
||
| 68 | |||
| 69 | public static function compareBigIntegers($a, $b): int |
||
| 77 | |||
| 78 | public static function compareFloats($a, $b): int |
||
| 88 | |||
| 89 | public static function compareArrays(array $a, array $b): int |
||
| 155 | } |
||
| 156 |