Complex classes like Common 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 Common, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
17 | class Common extends ControllerAbstract |
||
18 | { |
||
19 | /** |
||
20 | * process the class |
||
21 | * |
||
22 | * @since 4.0.0 |
||
23 | * |
||
24 | * @param string $action action to process |
||
25 | * |
||
26 | * @return string |
||
27 | */ |
||
28 | |||
29 | public function process(string $action = null) : string |
||
140 | |||
141 | /** |
||
142 | * publish the item |
||
143 | * |
||
144 | * @since 4.0.0 |
||
145 | * |
||
146 | * @param string $table name of the table |
||
147 | * @param int $id identifier of the item |
||
148 | * |
||
149 | * @return bool |
||
150 | */ |
||
151 | |||
152 | protected function _publish(string $table = null, int $id = null) : bool |
||
179 | |||
180 | /** |
||
181 | * unpublish the item |
||
182 | * |
||
183 | * @since 4.0.0 |
||
184 | * |
||
185 | * @param string $table name of the table |
||
186 | * @param int $id identifier of the item |
||
187 | * |
||
188 | * @return bool |
||
189 | */ |
||
190 | |||
191 | protected function _unpublish(string $table = null, int $id = null) : bool |
||
218 | |||
219 | /** |
||
220 | * enable the item |
||
221 | * |
||
222 | * @since 4.0.0 |
||
223 | * |
||
224 | * @param string $table name of the table |
||
225 | * @param int $id identifier of the item |
||
226 | * |
||
227 | * @return bool |
||
228 | */ |
||
229 | |||
230 | protected function _enable(string $table = null, int $id = null) : bool |
||
249 | |||
250 | /** |
||
251 | * disable the item |
||
252 | * |
||
253 | * @since 4.0.0 |
||
254 | * |
||
255 | * @param string $table name of the table |
||
256 | * @param int $id identifier of the item |
||
257 | * |
||
258 | * @return bool |
||
259 | */ |
||
260 | |||
261 | protected function _disable(string $table = null, int $id = null) : bool |
||
280 | |||
281 | /** |
||
282 | * install the item |
||
283 | * |
||
284 | * @since 4.0.0 |
||
285 | * |
||
286 | * @param string $table name of the table |
||
287 | * @param string $alias alias of the item |
||
288 | * |
||
289 | * @return bool |
||
290 | */ |
||
291 | |||
292 | protected function _install(string $table = null, string $alias = null) : bool |
||
305 | |||
306 | /** |
||
307 | * uninstall the item |
||
308 | * |
||
309 | * @since 4.0.0 |
||
310 | * |
||
311 | * @param string $table name of the table |
||
312 | * @param string $alias alias of the item |
||
313 | * |
||
314 | * @return bool |
||
315 | */ |
||
316 | |||
317 | protected function _uninstall(string $table = null, string $alias = null) : bool |
||
330 | |||
331 | /** |
||
332 | * delete the item |
||
333 | * |
||
334 | * @since 4.0.0 |
||
335 | * |
||
336 | * @param string $table name of the table |
||
337 | * @param int $id identifier of the item |
||
338 | * |
||
339 | * @return bool |
||
340 | */ |
||
341 | |||
342 | protected function _delete(string $table = null, int $id = null) : bool |
||
379 | |||
380 | /** |
||
381 | * get the route |
||
382 | * |
||
383 | * @since 4.0.0 |
||
384 | * |
||
385 | * @param string $table name of the table |
||
386 | * @param int $id identifier of the item |
||
387 | * |
||
388 | * @return string |
||
389 | */ |
||
390 | |||
391 | protected function _getRoute(string $table = null, int $id = null) : string |
||
406 | } |
||
407 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.