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:
| 1 | <?php |
||
| 3 | class Kint_Parser_Xml extends Kint_Parser_Plugin |
||
| 4 | { |
||
| 5 | /** |
||
| 6 | * Which method to parse the variable with. |
||
| 7 | * |
||
| 8 | * DOMDocument provides more information including the text between nodes, |
||
| 9 | * however it's memory usage is very high and it takes longer to parse and |
||
| 10 | * render. Plus it's a pain to work with. So SimpleXML is the default. |
||
| 11 | * |
||
| 12 | * @var string |
||
| 13 | */ |
||
| 14 | public static $parse_method = 'SimpleXML'; |
||
| 15 | |||
| 16 | public function getTypes() |
||
| 20 | |||
| 21 | public function getTriggers() |
||
| 25 | |||
| 26 | public function parse(&$var, Kint_Object &$o, $trigger) |
||
| 54 | |||
| 55 | protected static function xmlToSimpleXML($var, $parent_path) |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Get the DOMDocument info. |
||
| 86 | * |
||
| 87 | * The documentation of DOMDocument::loadXML() states that while you can |
||
| 88 | * call it statically, it will give an E_STRICT warning. On my system it |
||
| 89 | * actually gives an E_DEPRECATED warning, but it works so we'll just add |
||
| 90 | * an error-silencing '@' to the access path. |
||
| 91 | * |
||
| 92 | * If it errors loading then we wouldn't have gotten this far in the first place. |
||
| 93 | * |
||
| 94 | * @param string $var The XML string |
||
| 95 | * @param string $parent_path The path to the parent, in this case the XML string |
||
| 96 | * |
||
| 97 | * @return array The root element DOMNode, the access path, and the root element name |
||
| 98 | */ |
||
| 99 | protected static function xmlToDOMDocument($var, $parent_path) |
||
| 120 | } |
||
| 121 |
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.