Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Kint 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 Kint, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
10 | class Kint |
||
11 | { |
||
12 | /** |
||
13 | * @var mixed Kint mode |
||
14 | * |
||
15 | * false: Disabled |
||
16 | * true: Enabled, default mode selection |
||
17 | * other: Manual mode selection |
||
18 | */ |
||
19 | public static $enabled_mode = true; |
||
20 | |||
21 | /** |
||
22 | * Default mode. |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | public static $mode_default = self::MODE_RICH; |
||
27 | |||
28 | /** |
||
29 | * Default mode in CLI with cli_detection on. |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | public static $mode_default_cli = self::MODE_CLI; |
||
34 | |||
35 | /** |
||
36 | * @var bool Return output instead of echoing |
||
37 | */ |
||
38 | public static $return; |
||
39 | |||
40 | /** |
||
41 | * @var string format of the link to the source file in trace entries. |
||
42 | * |
||
43 | * Use %f for file path, %l for line number. |
||
44 | * |
||
45 | * [!] EXAMPLE (works with for phpStorm and RemoteCall Plugin): |
||
46 | * |
||
47 | * Kint::$file_link_format = 'http://localhost:8091/?message=%f:%l'; |
||
48 | */ |
||
49 | public static $file_link_format = ''; |
||
50 | |||
51 | /** |
||
52 | * @var bool whether to display where kint was called from |
||
53 | */ |
||
54 | public static $display_called_from = true; |
||
55 | |||
56 | /** |
||
57 | * @var array base directories of your application that will be displayed instead of the full path. |
||
58 | * |
||
59 | * Keys are paths, values are replacement strings |
||
60 | * |
||
61 | * [!] EXAMPLE (for Laravel 5): |
||
62 | * |
||
63 | * Kint::$app_root_dirs = [ |
||
64 | * base_path() => '<BASE>', |
||
65 | * app_path() => '<APP>', |
||
66 | * config_path() => '<CONFIG>', |
||
67 | * database_path() => '<DATABASE>', |
||
68 | * public_path() => '<PUBLIC>', |
||
69 | * resource_path() => '<RESOURCE>', |
||
70 | * storage_path() => '<STORAGE>', |
||
71 | * ]; |
||
72 | * |
||
73 | * Defaults to [$_SERVER['DOCUMENT_ROOT'] => '<ROOT>'] |
||
74 | */ |
||
75 | public static $app_root_dirs = array(); |
||
76 | |||
77 | /** |
||
78 | * @var int max array/object levels to go deep, if zero no limits are applied |
||
79 | */ |
||
80 | public static $max_depth = 6; |
||
81 | |||
82 | /** |
||
83 | * @var bool expand all trees by default for rich view |
||
84 | */ |
||
85 | public static $expanded = false; |
||
86 | |||
87 | /** |
||
88 | * @var bool enable detection when Kint is command line. |
||
89 | * |
||
90 | * Formats output with whitespace only; does not HTML-escape it |
||
91 | */ |
||
92 | public static $cli_detection = true; |
||
93 | |||
94 | /** |
||
95 | * @var array Kint aliases. Add debug functions in Kint wrappers here to fix modifiers and backtraces |
||
96 | */ |
||
97 | public static $aliases = array( |
||
98 | array('Kint', 'dump'), |
||
99 | array('Kint', 'trace'), |
||
100 | array('Kint', 'dumpArray'), |
||
101 | ); |
||
102 | |||
103 | /** |
||
104 | * @var array Kint\Renderer\Renderer descendants. Add to array to extend. |
||
105 | */ |
||
106 | public static $renderers = array( |
||
107 | self::MODE_RICH => 'Kint\\Renderer\\RichRenderer', |
||
108 | self::MODE_PLAIN => 'Kint\\Renderer\\PlainRenderer', |
||
109 | self::MODE_TEXT => 'Kint\\Renderer\\TextRenderer', |
||
110 | self::MODE_CLI => 'Kint\\Renderer\\CliRenderer', |
||
111 | ); |
||
112 | |||
113 | const MODE_RICH = 'r'; |
||
114 | const MODE_TEXT = 't'; |
||
115 | const MODE_CLI = 'c'; |
||
116 | const MODE_PLAIN = 'p'; |
||
117 | |||
118 | public static $plugins = array( |
||
119 | 'Kint\\Parser\\ArrayObjectPlugin', |
||
120 | 'Kint\\Parser\\Base64Plugin', |
||
121 | 'Kint\\Parser\\BlacklistPlugin', |
||
122 | 'Kint\\Parser\\ClassMethodsPlugin', |
||
123 | 'Kint\\Parser\\ClassStaticsPlugin', |
||
124 | 'Kint\\Parser\\ClosurePlugin', |
||
125 | 'Kint\\Parser\\ColorPlugin', |
||
126 | 'Kint\\Parser\\DateTimePlugin', |
||
127 | 'Kint\\Parser\\FsPathPlugin', |
||
128 | 'Kint\\Parser\\IteratorPlugin', |
||
129 | 'Kint\\Parser\\JsonPlugin', |
||
130 | 'Kint\\Parser\\MicrotimePlugin', |
||
131 | 'Kint\\Parser\\SimpleXMLElementPlugin', |
||
132 | 'Kint\\Parser\\SplFileInfoPlugin', |
||
133 | 'Kint\\Parser\\SplObjectStoragePlugin', |
||
134 | 'Kint\\Parser\\StreamPlugin', |
||
135 | 'Kint\\Parser\\TablePlugin', |
||
136 | 'Kint\\Parser\\ThrowablePlugin', |
||
137 | 'Kint\\Parser\\TimestampPlugin', |
||
138 | 'Kint\\Parser\\ToStringPlugin', |
||
139 | 'Kint\\Parser\\TracePlugin', |
||
140 | 'Kint\\Parser\\XmlPlugin', |
||
141 | ); |
||
142 | |||
143 | private static $plugin_pool = array(); |
||
144 | private static $dump_array = false; |
||
145 | private static $names = array(); |
||
146 | |||
147 | /** |
||
148 | * Stashes or sets all settings at once. |
||
149 | * |
||
150 | * @param array|null $settings Array of all settings to be set or null to set none |
||
151 | * |
||
152 | * @return array Current settings |
||
153 | */ |
||
154 | public static function settings(array $settings = null) |
||
187 | |||
188 | /** |
||
189 | * Prints a debug backtrace, same as Kint::dump(1). |
||
190 | * |
||
191 | * @param array $trace [OPTIONAL] you can pass your own trace, otherwise, `debug_backtrace` will be called |
||
192 | * |
||
193 | * @return mixed |
||
194 | */ |
||
195 | public static function trace(array $trace = null) |
||
220 | |||
221 | /** |
||
222 | * Dumps an array as separate values, and uses $names to seed the parser. |
||
223 | * |
||
224 | * @param array $data Data to be dumped |
||
225 | * @param BasicObject[]|null $names Array of BasicObject to seed the parser with |
||
226 | */ |
||
227 | public static function dumpArray(array $data, array $names = null) |
||
239 | |||
240 | /** |
||
241 | * Dump information about variables, accepts any number of parameters, supports modifiers:. |
||
242 | * |
||
243 | * clean up any output before kint and place the dump at the top of page: |
||
244 | * - Kint::dump() |
||
245 | * ***** |
||
246 | * expand all nodes on display: |
||
247 | * ! Kint::dump() |
||
248 | * ***** |
||
249 | * dump variables disregarding their depth: |
||
250 | * + Kint::dump() |
||
251 | * ***** |
||
252 | * return output instead of displaying it: |
||
253 | * |
||
254 | * @ Kint::dump() |
||
255 | * ***** |
||
256 | * force output as plain text |
||
257 | * ~ Kint::dump() |
||
258 | * |
||
259 | * Modifiers are supported by all dump wrapper functions, including Kint::trace(). Space is optional. |
||
260 | * |
||
261 | * @param mixed $data |
||
262 | * |
||
263 | * @return int|string |
||
264 | */ |
||
265 | public static function dump($data = null) |
||
425 | |||
426 | /** |
||
427 | * generic path display callback, can be configured in app_root_dirs; purpose is |
||
428 | * to show relevant path info and hide as much of the path as possible. |
||
429 | * |
||
430 | * @param string $file |
||
431 | * |
||
432 | * @return string |
||
433 | */ |
||
434 | public static function shortenPath($file) |
||
471 | |||
472 | public static function getIdeLink($file, $line) |
||
476 | |||
477 | /** |
||
478 | * returns parameter names that the function was passed, as well as any predefined symbols before function |
||
479 | * call (modifiers). |
||
480 | * |
||
481 | * @param array $trace |
||
482 | * |
||
483 | * @return array($params, $modifiers, $callee, $caller, $miniTrace) |
||
484 | */ |
||
485 | private static function getCalleeInfo($trace, $num_params) |
||
582 | |||
583 | public static function composerGetExtras($key = 'kint') |
||
619 | |||
620 | public static function composerGetDisableHelperFunctions() |
||
626 | } |
||
627 |
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.