Complex classes like Helper 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 Helper, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
15 | class Helper |
||
16 | { |
||
17 | /** |
||
18 | * Places item of extra columns into results by care of their order. |
||
19 | * |
||
20 | * @param array $item |
||
21 | * @param array $array |
||
22 | * @return array |
||
23 | */ |
||
24 | public static function includeInArray($item, $array) |
||
44 | |||
45 | /** |
||
46 | * Check if item order is valid. |
||
47 | * |
||
48 | * @param array $item |
||
49 | * @param array $array |
||
50 | * @return bool |
||
51 | */ |
||
52 | protected static function isItemOrderInvalid($item, $array) |
||
56 | |||
57 | /** |
||
58 | * Determines if content is callable or blade string, processes and returns. |
||
59 | * |
||
60 | * @param string|callable $content Pre-processed content |
||
61 | * @param array $data data to use with blade template |
||
62 | * @param mixed $param parameter to call with callable |
||
63 | * @return string Processed content |
||
64 | */ |
||
65 | public static function compileContent($content, array $data, $param) |
||
75 | |||
76 | /** |
||
77 | * Parses and compiles strings by using Blade Template System. |
||
78 | * |
||
79 | * @param string $str |
||
80 | * @param array $data |
||
81 | * @return mixed |
||
82 | * @throws \Exception |
||
83 | */ |
||
84 | public static function compileBlade($str, $data = []) |
||
97 | |||
98 | /** |
||
99 | * Get a mixed value of custom data and the parameters. |
||
100 | * |
||
101 | * @param array $data |
||
102 | * @param mixed $param |
||
103 | * @return array |
||
104 | */ |
||
105 | public static function getMixedValue(array $data, $param) |
||
119 | |||
120 | /** |
||
121 | * Cast the parameter into an array. |
||
122 | * |
||
123 | * @param mixed $param |
||
124 | * @return array |
||
125 | */ |
||
126 | public static function castToArray($param) |
||
140 | |||
141 | /** |
||
142 | * Get equivalent or method of query builder. |
||
143 | * |
||
144 | * @param string $method |
||
145 | * @return string |
||
146 | */ |
||
147 | public static function getOrMethod($method) |
||
155 | |||
156 | /** |
||
157 | * Converts array object values to associative array. |
||
158 | * |
||
159 | * @param mixed $row |
||
160 | * @return array |
||
161 | */ |
||
162 | public static function convertToArray($row) |
||
173 | |||
174 | /** |
||
175 | * @param array $data |
||
176 | * @return array |
||
177 | */ |
||
178 | public static function transform(array $data) |
||
184 | |||
185 | /** |
||
186 | * Transform row data into an array. |
||
187 | * |
||
188 | * @param mixed $row |
||
189 | * @return array |
||
190 | */ |
||
191 | protected static function transformRow($row) |
||
207 | |||
208 | /** |
||
209 | * Build parameters depending on # of arguments passed. |
||
210 | * |
||
211 | * @param array $args |
||
212 | * @return array |
||
213 | */ |
||
214 | public static function buildParameters(array $args) |
||
231 | |||
232 | /** |
||
233 | * Replace all pattern occurrences with keyword |
||
234 | * |
||
235 | * @param array $subject |
||
236 | * @param string $keyword |
||
237 | * @param string $pattern |
||
238 | * @return array |
||
239 | */ |
||
240 | public static function replacePatternWithKeyword(array $subject, $keyword, $pattern = '$1') |
||
253 | |||
254 | /** |
||
255 | * Get column name from string. |
||
256 | * |
||
257 | * @param string $str |
||
258 | * @param bool $wantsAlias |
||
259 | * @return string |
||
260 | */ |
||
261 | public static function extractColumnName($str, $wantsAlias) |
||
279 | |||
280 | /** |
||
281 | * Adds % wildcards to the given string. |
||
282 | * |
||
283 | * @param string $str |
||
284 | * @param bool $lowercase |
||
285 | * @return string |
||
286 | */ |
||
287 | public static function wildcardLikeString($str, $lowercase = true) |
||
304 | } |
||
305 |