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 RichRenderer 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 RichRenderer, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 10 | class RichRenderer extends Renderer |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * RichRenderer object plugins should implement Kint\Renderer\Rich\ObjectPluginInterface. |
||
| 14 | */ |
||
| 15 | public static $object_plugins = array( |
||
|
|
|||
| 16 | 'blacklist' => 'Kint\\Renderer\\Rich\\BlacklistPlugin', |
||
| 17 | 'callable' => 'Kint\\Renderer\\Rich\\CallablePlugin', |
||
| 18 | 'closure' => 'Kint\\Renderer\\Rich\\ClosurePlugin', |
||
| 19 | 'color' => 'Kint\\Renderer\\Rich\\ColorPlugin', |
||
| 20 | 'depth_limit' => 'Kint\\Renderer\\Rich\\DepthLimitPlugin', |
||
| 21 | 'nothing' => 'Kint\\Renderer\\Rich\\NothingPlugin', |
||
| 22 | 'recursion' => 'Kint\\Renderer\\Rich\\RecursionPlugin', |
||
| 23 | 'simplexml_element' => 'Kint\\Renderer\\Rich\\SimpleXMLElementPlugin', |
||
| 24 | 'trace_frame' => 'Kint\\Renderer\\Rich\\TraceFramePlugin', |
||
| 25 | ); |
||
| 26 | |||
| 27 | /** |
||
| 28 | * RichRenderer tab plugins should implement Kint\Renderer\Rich\TabPluginInterface. |
||
| 29 | */ |
||
| 30 | public static $tab_plugins = array( |
||
| 31 | 'binary' => 'Kint\\Renderer\\Rich\\BinaryPlugin', |
||
| 32 | 'color' => 'Kint\\Renderer\\Rich\\ColorPlugin', |
||
| 33 | 'docstring' => 'Kint\\Renderer\\Rich\\DocstringPlugin', |
||
| 34 | 'microtime' => 'Kint\\Renderer\\Rich\\MicrotimePlugin', |
||
| 35 | 'source' => 'Kint\\Renderer\\Rich\\SourcePlugin', |
||
| 36 | 'table' => 'Kint\\Renderer\\Rich\\TablePlugin', |
||
| 37 | 'timestamp' => 'Kint\\Renderer\\Rich\\TimestampPlugin', |
||
| 38 | ); |
||
| 39 | |||
| 40 | public static $pre_render_sources = array( |
||
| 41 | 'script' => array( |
||
| 42 | array('Kint\\Renderer\\RichRenderer', 'renderJs'), |
||
| 43 | array('Kint\\Renderer\\Rich\\MicrotimePlugin', 'renderJs'), |
||
| 44 | ), |
||
| 45 | 'style' => array( |
||
| 46 | array('Kint\\Renderer\\RichRenderer', 'renderCss'), |
||
| 47 | ), |
||
| 48 | 'raw' => array( |
||
| 49 | array('Kint\\Renderer\\RichRenderer', 'renderFolder'), |
||
| 50 | ), |
||
| 51 | ); |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Whether or not to render access paths. |
||
| 55 | * |
||
| 56 | * Access paths can become incredibly heavy with very deep and wide |
||
| 57 | * structures. Given mostly public variables it will typically make |
||
| 58 | * up one quarter of the output HTML size. |
||
| 59 | * |
||
| 60 | * If this is an unacceptably large amount and your browser is groaning |
||
| 61 | * under the weight of the access paths - your first order of buisiness |
||
| 62 | * should be to get a new browser. Failing that, use this to turn them off. |
||
| 63 | * |
||
| 64 | * @var bool |
||
| 65 | */ |
||
| 66 | public static $access_paths = true; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * The maximum length of a string before it is truncated. |
||
| 70 | * |
||
| 71 | * Falsey to disable |
||
| 72 | * |
||
| 73 | * @var int |
||
| 74 | */ |
||
| 75 | public static $strlen_max = 80; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Path to the CSS file to load by default. |
||
| 79 | * |
||
| 80 | * @var string |
||
| 81 | */ |
||
| 82 | public static $theme = 'original.css'; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Assume types and sizes don't need to be escaped. |
||
| 86 | * |
||
| 87 | * Turn this off if you use anything but ascii in your class names, |
||
| 88 | * but it'll cause a slowdown of around 10% |
||
| 89 | * |
||
| 90 | * @var bool |
||
| 91 | */ |
||
| 92 | public static $escape_types = false; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Move all dumps to a folder at the bottom of the body. |
||
| 96 | * |
||
| 97 | * @var bool |
||
| 98 | */ |
||
| 99 | public static $folder = true; |
||
| 100 | |||
| 101 | protected static $been_run = false; |
||
| 102 | |||
| 103 | protected $plugin_objs = array(); |
||
| 104 | protected $mod_return = false; |
||
| 105 | protected $callee; |
||
| 106 | protected $mini_trace; |
||
| 107 | protected $previous_caller; |
||
| 108 | protected $file_link_format = false; |
||
| 109 | protected $show_minitrace = true; |
||
| 110 | protected $auto_expand = false; |
||
| 111 | |||
| 112 | public function __construct(array $params = array()) |
||
| 143 | |||
| 144 | public function render(BasicObject $o) |
||
| 157 | |||
| 158 | public function renderHeaderWrapper(BasicObject $o, $has_children, $contents) |
||
| 190 | |||
| 191 | public function renderHeader(BasicObject $o) |
||
| 237 | |||
| 238 | public function renderChildren(BasicObject $o) |
||
| 283 | |||
| 284 | protected function renderTab(BasicObject $o, Representation $rep) |
||
| 325 | |||
| 326 | protected static function renderJs() |
||
| 330 | |||
| 331 | View Code Duplication | protected static function renderCss() |
|
| 339 | |||
| 340 | protected static function renderFolder() |
||
| 348 | |||
| 349 | View Code Duplication | public function preRender() |
|
| 383 | |||
| 384 | public function postRender() |
||
| 446 | |||
| 447 | View Code Duplication | public function escape($string, $encoding = false) |
|
| 468 | |||
| 469 | View Code Duplication | protected function getPlugin(array $plugins, array $hints) |
|
| 481 | |||
| 482 | View Code Duplication | protected function ideLink($file, $line) |
|
| 494 | } |
||
| 495 |
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.