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 |
||
| 3 | class Kint |
||
| 4 | { |
||
| 5 | /** |
||
| 6 | * @var mixed Kint mode |
||
| 7 | * |
||
| 8 | * false: Disabled |
||
| 9 | * true: Enabled, default mode selection |
||
| 10 | * string: Manual mode selection |
||
| 11 | */ |
||
| 12 | public static $enabled_mode = true; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Default mode. |
||
| 16 | * |
||
| 17 | * @var string |
||
| 18 | */ |
||
| 19 | public static $mode_default = self::MODE_RICH; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Default mode in CLI with cli_detection on. |
||
| 23 | * |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | public static $mode_default_cli = self::MODE_CLI; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var bool Return output instead of echoing |
||
| 30 | */ |
||
| 31 | public static $return; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var string format of the link to the source file in trace entries. |
||
| 35 | * |
||
| 36 | * Use %f for file path, %l for line number. |
||
| 37 | * |
||
| 38 | * [!] EXAMPLE (works with for phpStorm and RemoteCall Plugin): |
||
| 39 | * |
||
| 40 | * Kint::$file_link_format = 'http://localhost:8091/?message=%f:%l'; |
||
| 41 | */ |
||
| 42 | public static $file_link_format = ''; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var bool whether to display where kint was called from |
||
| 46 | */ |
||
| 47 | public static $display_called_from = true; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var array base directories of your application that will be displayed instead of the full path. |
||
| 51 | * |
||
| 52 | * Keys are paths, values are replacement strings |
||
| 53 | * |
||
| 54 | * [!] EXAMPLE (for Kohana framework): |
||
| 55 | * |
||
| 56 | * Kint::$app_root_dirs = array( |
||
| 57 | * APPPATH => 'APPPATH', |
||
| 58 | * SYSPATH => 'SYSPATH', |
||
| 59 | * MODPATH => 'MODPATH', |
||
| 60 | * DOCROOT => 'DOCROOT', |
||
| 61 | * ); |
||
| 62 | * |
||
| 63 | * [!] EXAMPLE #2 (for a semi-universal approach) |
||
| 64 | * |
||
| 65 | * Kint::$app_root_dirs = array( |
||
| 66 | * realpath( __DIR__ . '/../../..' ) => 'ROOT', // go up as many levels as needed |
||
| 67 | * ); |
||
| 68 | */ |
||
| 69 | public static $app_root_dirs = array(); |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var int max array/object levels to go deep, if zero no limits are applied |
||
| 73 | */ |
||
| 74 | public static $max_depth = 6; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var bool expand all trees by default for rich view |
||
| 78 | */ |
||
| 79 | public static $expanded = false; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @var bool enable detection when Kint is command line. |
||
| 83 | * |
||
| 84 | * Formats output with whitespace only; does not HTML-escape it |
||
| 85 | */ |
||
| 86 | public static $cli_detection = true; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @var array Kint aliases. Add debug functions in Kint wrappers here to fix modifiers and backtraces |
||
| 90 | */ |
||
| 91 | public static $aliases = array( |
||
| 92 | array('Kint', 'dump'), |
||
| 93 | array('Kint', 'trace'), |
||
| 94 | array('Kint', 'dumpArray'), |
||
| 95 | ); |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @var array Kint_Renderer descendants. Add to array to extend. |
||
| 99 | */ |
||
| 100 | public static $renderers = array( |
||
| 101 | self::MODE_RICH => 'Kint_Renderer_Rich', |
||
| 102 | self::MODE_PLAIN => 'Kint_Renderer_Plain', |
||
| 103 | self::MODE_TEXT => 'Kint_Renderer_Text', |
||
| 104 | self::MODE_CLI => 'Kint_Renderer_Cli', |
||
| 105 | ); |
||
| 106 | |||
| 107 | const MODE_RICH = 'r'; |
||
| 108 | const MODE_TEXT = 't'; |
||
| 109 | const MODE_CLI = 'c'; |
||
| 110 | const MODE_PLAIN = 'p'; |
||
| 111 | |||
| 112 | public static $plugins = array( |
||
| 113 | 'Kint_Parser_Base64', |
||
| 114 | 'Kint_Parser_Blacklist', |
||
| 115 | 'Kint_Parser_ClassMethods', |
||
| 116 | 'Kint_Parser_ClassStatics', |
||
| 117 | 'Kint_Parser_Closure', |
||
| 118 | 'Kint_Parser_Color', |
||
| 119 | 'Kint_Parser_DateTime', |
||
| 120 | 'Kint_Parser_FsPath', |
||
| 121 | 'Kint_Parser_Iterator', |
||
| 122 | 'Kint_Parser_Json', |
||
| 123 | 'Kint_Parser_Microtime', |
||
| 124 | 'Kint_Parser_SimpleXMLElement', |
||
| 125 | 'Kint_Parser_SplFileInfo', |
||
| 126 | 'Kint_Parser_SplObjectStorage', |
||
| 127 | 'Kint_Parser_Stream', |
||
| 128 | 'Kint_Parser_Table', |
||
| 129 | 'Kint_Parser_Throwable', |
||
| 130 | 'Kint_Parser_Timestamp', |
||
| 131 | 'Kint_Parser_ToString', |
||
| 132 | 'Kint_Parser_Trace', |
||
| 133 | 'Kint_Parser_Xml', |
||
| 134 | ); |
||
| 135 | |||
| 136 | private static $plugin_pool = array(); |
||
| 137 | private static $dump_array = false; |
||
| 138 | private static $names = array(); |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Stashes or sets all settings at once. |
||
| 142 | * |
||
| 143 | * @param array|null $settings Array of all settings to be set or null to set none |
||
| 144 | * |
||
| 145 | * @return array Current settings |
||
| 146 | */ |
||
| 147 | public static function settings(array $settings = null) |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Prints a debug backtrace, same as Kint::dump(1). |
||
| 183 | * |
||
| 184 | * @param array $trace [OPTIONAL] you can pass your own trace, otherwise, `debug_backtrace` will be called |
||
| 185 | * |
||
| 186 | * @return mixed |
||
| 187 | */ |
||
| 188 | public static function trace($trace = null) |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Dumps an array as separate values, and uses $names to seed the parser. |
||
| 220 | * |
||
| 221 | * @param array $data Data to be dumped |
||
| 222 | * @param array[Kint_Object]|null $names Array of Kint_Object to seed the parser with |
||
|
|
|||
| 223 | */ |
||
| 224 | public static function dumpArray(array $data, array $names = null) |
||
| 236 | |||
| 237 | /** |
||
| 238 | * Dump information about variables, accepts any number of parameters, supports modifiers:. |
||
| 239 | * |
||
| 240 | * clean up any output before kint and place the dump at the top of page: |
||
| 241 | * - Kint::dump() |
||
| 242 | * ***** |
||
| 243 | * expand all nodes on display: |
||
| 244 | * ! Kint::dump() |
||
| 245 | * ***** |
||
| 246 | * dump variables disregarding their depth: |
||
| 247 | * + Kint::dump() |
||
| 248 | * ***** |
||
| 249 | * return output instead of displaying it: |
||
| 250 | * |
||
| 251 | * @ Kint::dump() |
||
| 252 | * ***** |
||
| 253 | * force output as plain text |
||
| 254 | * ~ Kint::dump() |
||
| 255 | * |
||
| 256 | * Modifiers are supported by all dump wrapper functions, including Kint::trace(). Space is optional. |
||
| 257 | * |
||
| 258 | * @param mixed $data |
||
| 259 | * |
||
| 260 | * @return int|string |
||
| 261 | */ |
||
| 262 | public static function dump($data = null) |
||
| 433 | |||
| 434 | /** |
||
| 435 | * generic path display callback, can be configured in app_root_dirs; purpose is |
||
| 436 | * to show relevant path info and hide as much of the path as possible. |
||
| 437 | * |
||
| 438 | * @param string $file |
||
| 439 | * |
||
| 440 | * @return string |
||
| 441 | */ |
||
| 442 | public static function shortenPath($file) |
||
| 479 | |||
| 480 | public static function getIdeLink($file, $line) |
||
| 484 | |||
| 485 | /** |
||
| 486 | * returns parameter names that the function was passed, as well as any predefined symbols before function |
||
| 487 | * call (modifiers). |
||
| 488 | * |
||
| 489 | * @param array $trace |
||
| 490 | * |
||
| 491 | * @return array($params, $modifiers, $callee, $caller, $miniTrace) |
||
| 492 | */ |
||
| 493 | private static function getCalleeInfo($trace, $num_params) |
||
| 590 | |||
| 591 | public static function composerGetExtras($key = 'kint') |
||
| 631 | |||
| 632 | public static function composerGetDisableHelperFunctions() |
||
| 638 | } |
||
| 639 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.