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 |
||
16 | class Common extends ControllerAbstract |
||
17 | { |
||
18 | /** |
||
19 | * process the class |
||
20 | * |
||
21 | * @since 4.0.0 |
||
22 | * |
||
23 | * @param string $action action to process |
||
24 | * |
||
25 | * @return string |
||
26 | */ |
||
27 | |||
28 | public function process(string $action = null) : string |
||
139 | |||
140 | /** |
||
141 | * publish the item |
||
142 | * |
||
143 | * @since 4.0.0 |
||
144 | * |
||
145 | * @param string $table name of the table |
||
146 | * @param int $id identifier of the item |
||
147 | * |
||
148 | * @return bool |
||
149 | */ |
||
150 | |||
151 | public function _publish(string $table = null, int $id = null) : bool |
||
175 | |||
176 | /** |
||
177 | * unpublish the item |
||
178 | * |
||
179 | * @since 4.0.0 |
||
180 | * |
||
181 | * @param string $table name of the table |
||
182 | * @param int $id identifier of the item |
||
183 | * |
||
184 | * @return bool |
||
185 | */ |
||
186 | |||
187 | public function _unpublish(string $table = null, int $id = null) : bool |
||
211 | |||
212 | /** |
||
213 | * enable the item |
||
214 | * |
||
215 | * @since 4.0.0 |
||
216 | * |
||
217 | * @param string $table name of the table |
||
218 | * @param int $id identifier of the item |
||
219 | * |
||
220 | * @return bool |
||
221 | */ |
||
222 | |||
223 | public function _enable(string $table = null, int $id = null) : bool |
||
242 | |||
243 | /** |
||
244 | * disable the item |
||
245 | * |
||
246 | * @since 4.0.0 |
||
247 | * |
||
248 | * @param string $table name of the table |
||
249 | * @param int $id identifier of the item |
||
250 | * |
||
251 | * @return bool |
||
252 | */ |
||
253 | |||
254 | public function _disable(string $table = null, int $id = null) : bool |
||
273 | |||
274 | /** |
||
275 | * install the item |
||
276 | * |
||
277 | * @since 4.0.0 |
||
278 | * |
||
279 | * @param string $table name of the table |
||
280 | * @param string $alias alias of the item |
||
281 | * |
||
282 | * @return bool |
||
283 | */ |
||
284 | |||
285 | public function _install(string $table = null, string $alias = null) : bool |
||
295 | |||
296 | /** |
||
297 | * uninstall the item |
||
298 | * |
||
299 | * @since 4.0.0 |
||
300 | * |
||
301 | * @param string $table name of the table |
||
302 | * @param string $alias alias of the item |
||
303 | * |
||
304 | * @return bool |
||
305 | */ |
||
306 | |||
307 | public function _uninstall(string $table = null, string $alias = null) : bool |
||
317 | |||
318 | /** |
||
319 | * delete the item |
||
320 | * |
||
321 | * @since 4.0.0 |
||
322 | * |
||
323 | * @param string $table name of the table |
||
324 | * @param int $id identifier of the item |
||
325 | * |
||
326 | * @return bool |
||
327 | */ |
||
328 | |||
329 | public function _delete(string $table = null, int $id = null) : bool |
||
363 | |||
364 | /** |
||
365 | * get route |
||
366 | * |
||
367 | * @since 4.0.0 |
||
368 | * |
||
369 | * @param string $table name of the table |
||
370 | * @param int $id identifier of the item |
||
371 | * |
||
372 | * @return string |
||
373 | */ |
||
374 | |||
375 | public function _getRoute(string $table = null, int $id = null) : string |
||
390 | } |
||
391 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: