Complex classes like Utils 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 Utils, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
20 | final class Utils |
||
21 | { |
||
22 | /** |
||
23 | * @param string $char |
||
24 | * |
||
25 | * @return bool |
||
26 | */ |
||
27 | public static function isWhite(string $char): bool |
||
31 | |||
32 | /** |
||
33 | * @param string $char |
||
34 | * |
||
35 | * @return bool |
||
36 | */ |
||
37 | public static function isSymChar(string $char): bool |
||
41 | |||
42 | /** |
||
43 | * @param string $char |
||
44 | * |
||
45 | * @return bool |
||
46 | */ |
||
47 | public static function isOctal(string $char): bool |
||
53 | |||
54 | /** |
||
55 | * @param string $string |
||
56 | * |
||
57 | * @return int |
||
58 | */ |
||
59 | public static function characterValue(string $string): int |
||
103 | |||
104 | /** |
||
105 | * @param array $array |
||
106 | * @param callable $cmp |
||
107 | */ |
||
108 | public static function stableSort(array &$array, callable $cmp) |
||
130 | |||
131 | /** |
||
132 | * @param array $array |
||
133 | * @param int $length |
||
134 | * |
||
135 | * @return bool |
||
136 | */ |
||
137 | public static function vacantRow(array $array, int $length): bool |
||
147 | |||
148 | /** |
||
149 | * @param array $a |
||
150 | * @param array $b |
||
151 | * @param int $length |
||
152 | * |
||
153 | * @return bool |
||
154 | */ |
||
155 | public static function eqRow(array $a, array $b, int $length): bool |
||
165 | |||
166 | /** |
||
167 | * @param int $action |
||
168 | * |
||
169 | * @return string |
||
170 | */ |
||
171 | public static function printAction(int $action): string |
||
179 | |||
180 | /** |
||
181 | * @param Lr1|null $left |
||
182 | * @param Lr1|null $right |
||
183 | * |
||
184 | * @return bool |
||
185 | */ |
||
186 | public static function isSameSet(Lr1 $left = null, Lr1 $right = null): bool |
||
201 | |||
202 | /** |
||
203 | * @param Context $ctx |
||
204 | * @param BitSet $set |
||
205 | * |
||
206 | * @return string |
||
207 | */ |
||
208 | public static function dumpSet(Context $ctx, BitSet $set): string |
||
218 | } |
||
219 |