Complex classes like readable 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 readable, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
15 | abstract class readable |
||
16 | { |
||
17 | /** |
||
18 | * @var int strings longer than this number of characters will be truncated when formatting string-values |
||
19 | */ |
||
20 | public static $max_string_length = 120; |
||
21 | |||
22 | /** |
||
23 | * @var string[] map where PHP error severity code => constant name |
||
24 | */ |
||
25 | public static $severity_names = [ |
||
26 | E_ERROR => "E_ERROR", |
||
27 | E_USER_ERROR => "E_USER_ERROR", |
||
28 | E_CORE_ERROR => "E_CORE_ERROR", |
||
29 | E_COMPILE_ERROR => "E_COMPILE_ERROR", |
||
30 | E_PARSE => "E_PARSE", |
||
31 | E_WARNING => "E_WARNING", |
||
32 | E_USER_WARNING => "E_USER_WARNING", |
||
33 | E_CORE_WARNING => "E_CORE_WARNING", |
||
34 | E_COMPILE_WARNING => "E_COMPILE_WARNING", |
||
35 | E_NOTICE => "E_NOTICE", |
||
36 | E_USER_NOTICE => "E_USER_NOTICE", |
||
37 | E_STRICT => "E_STRICT", |
||
38 | E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR", |
||
39 | E_DEPRECATED => "E_DEPRECATED", |
||
40 | E_USER_DEPRECATED => "E_USER_DEPRECATED", |
||
41 | ]; |
||
42 | |||
43 | /** |
||
44 | * @param mixed $value any type of PHP value |
||
45 | * |
||
46 | * @return string readable representation of the given value |
||
47 | */ |
||
48 | 1 | public static function value($value) |
|
101 | |||
102 | /** |
||
103 | * @param array $array array containing any type of PHP values |
||
104 | * |
||
105 | * @return string comma-separated human-readable representation of the given values |
||
106 | */ |
||
107 | 1 | public static function values(array $array) |
|
119 | |||
120 | /** |
||
121 | * @param mixed $value any type of PHP value |
||
122 | * |
||
123 | * @return string human-readable type-name |
||
124 | */ |
||
125 | 1 | public static function typeof($value) |
|
150 | |||
151 | /** |
||
152 | * @param mixed $callable |
||
153 | * |
||
154 | * @return string human-readable description of callback |
||
155 | */ |
||
156 | 1 | public static function callback($callable) |
|
168 | |||
169 | /** |
||
170 | * @param Exception|Error|int $error an Exception, Error (or one of the E_* error severity constants) |
||
171 | * |
||
172 | * @return string |
||
173 | */ |
||
174 | 1 | public static function error($error) |
|
200 | |||
201 | /** |
||
202 | * @param int $severity one of the E_* error severity constants |
||
203 | * |
||
204 | * @return string |
||
205 | */ |
||
206 | 1 | public static function severity($severity) |
|
212 | |||
213 | /** |
||
214 | * @param array|Exception|Error $source Exception, Error or stack-trace data as provided |
||
215 | * by Exception::getTrace() or debug_backtrace() |
||
216 | * @param bool $with_params if TRUE, calls will be formatted with parameters |
||
217 | * |
||
218 | * @return string |
||
219 | */ |
||
220 | 1 | public static function trace($source, $with_params = true) |
|
267 | } |
||
268 |