Complex classes like Changers 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 Changers, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
8 | trait Changers |
||
9 | { |
||
10 | /** |
||
11 | * @param array $config |
||
12 | * @param array $keys |
||
13 | * @param mixed $value |
||
14 | * |
||
15 | * @return array |
||
16 | */ |
||
17 | public static function addConfigRow(array $config, array $keys, $value) |
||
32 | |||
33 | /** |
||
34 | * @param array $matrix |
||
35 | * @param array $castMap |
||
36 | * @param bool $allKeysMustBePresent |
||
37 | * |
||
38 | * @return array |
||
39 | */ |
||
40 | public static function castColumns(array $matrix, array $castMap, $allKeysMustBePresent = true) |
||
85 | |||
86 | /** |
||
87 | * @param array $matrix |
||
88 | * @param mixed $columns |
||
89 | * |
||
90 | * @return array |
||
91 | */ |
||
92 | public static function deleteColumns(array $matrix, array $columns) |
||
111 | |||
112 | /** |
||
113 | * @param mixed $array |
||
114 | * @param mixed $subArray |
||
115 | * @param bool $overwrite |
||
116 | * @param bool $ignoreIfExists |
||
117 | * |
||
118 | * @return array |
||
119 | */ |
||
120 | public static function insertSubArray($array, $subArray, $overwrite = false, $ignoreIfExists = false) |
||
148 | |||
149 | /** |
||
150 | * @param array $matrix |
||
151 | * @param mixed $column |
||
152 | * @param mixed $value |
||
153 | * @param bool $insertIfMissing |
||
154 | * @param bool $overwrite |
||
155 | * |
||
156 | * @return array |
||
157 | */ |
||
158 | public static function setColumn(array $matrix, $column, $value, $insertIfMissing = true, $overwrite = true) |
||
184 | |||
185 | /** |
||
186 | * @param array $matrix |
||
187 | * |
||
188 | * @return array |
||
189 | */ |
||
190 | public static function transpose(array $matrix) |
||
197 | } |