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 |
||
19 | final class Utils |
||
20 | { |
||
21 | /** |
||
22 | * @param string $char |
||
23 | * |
||
24 | * @return bool |
||
25 | */ |
||
26 | public static function isWhite(string $char): bool |
||
30 | |||
31 | /** |
||
32 | * @param string $char |
||
33 | * |
||
34 | * @return bool |
||
35 | */ |
||
36 | public static function isSymChar(string $char): bool |
||
40 | |||
41 | /** |
||
42 | * @param string $char |
||
43 | * |
||
44 | * @return bool |
||
45 | */ |
||
46 | public static function isOctal(string $char): bool |
||
52 | |||
53 | /** |
||
54 | * @param string $string |
||
55 | * |
||
56 | * @return int |
||
57 | */ |
||
58 | public static function characterValue(string $string): int |
||
102 | |||
103 | /** |
||
104 | * @param array $array |
||
105 | * @param callable $cmp |
||
106 | */ |
||
107 | public static function stableSort(array &$array, callable $cmp) |
||
129 | |||
130 | /** |
||
131 | * @param array $array |
||
132 | * @param int $length |
||
133 | * @return bool |
||
134 | */ |
||
135 | public static function vacantRow(array $array, int $length): bool |
||
145 | |||
146 | /** |
||
147 | * @param array $a |
||
148 | * @param array $b |
||
149 | * @param int $length |
||
150 | * @return bool |
||
151 | */ |
||
152 | public static function eqRow(array $a, array $b, int $length): bool |
||
162 | |||
163 | /** |
||
164 | * @param int $action |
||
165 | * @return string |
||
166 | */ |
||
167 | public static function printAction(int $action): string |
||
175 | |||
176 | /** |
||
177 | * @param Lr1|null $left |
||
178 | * @param Lr1|null $right |
||
179 | * @return bool |
||
180 | */ |
||
181 | public static function isSameSet(Lr1 $left = null, Lr1 $right = null): bool |
||
195 | |||
196 | /** |
||
197 | * @param Context $ctx |
||
198 | * @param BitSet $set |
||
199 | * @return string |
||
200 | */ |
||
201 | public static function dumpSet(Context $ctx, BitSet $set): string |
||
211 | } |
||
212 |