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 |
||
| 8 | class Tree |
||
| 9 | { |
||
| 10 | /** @var array Collection of ignored DOM nodes */ |
||
| 11 | public static $ignoredNodes = array( |
||
| 12 | 'head', |
||
| 13 | 'meta', |
||
| 14 | 'script', |
||
| 15 | 'noscript', |
||
| 16 | 'link', |
||
| 17 | 'title', |
||
| 18 | 'br', |
||
| 19 | ); |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Build destination code tree from source code. |
||
| 23 | * |
||
| 24 | * @param string $source Source code |
||
| 25 | * |
||
| 26 | * @return Node Less tree root node |
||
| 27 | */ |
||
| 28 | 1 | public function build($source) |
|
| 36 | |||
| 37 | /** |
||
| 38 | * Source code cleaner. |
||
| 39 | * |
||
| 40 | * @param string $source |
||
| 41 | * |
||
| 42 | * @return string Cleared source code |
||
| 43 | */ |
||
| 44 | 1 | protected function prepare($source) |
|
| 49 | |||
| 50 | /** |
||
| 51 | * Analyze source code and create destination code tree. |
||
| 52 | * |
||
| 53 | * @param string $source Source code |
||
| 54 | * |
||
| 55 | * @return Node Internal code tree |
||
| 56 | */ |
||
| 57 | 1 | protected function &analyze($source) |
|
| 68 | |||
| 69 | /** |
||
| 70 | * Perform source node analysis. |
||
| 71 | * |
||
| 72 | * @param \DOMNode $domNode |
||
| 73 | * @param Node $parent |
||
| 74 | * |
||
| 75 | * @return Node |
||
| 76 | */ |
||
| 77 | 1 | protected function &analyzeSourceNode(\DOMNode $domNode, Node $parent) |
|
| 118 | |||
| 119 | /** |
||
| 120 | * Get DOM node attribute value. |
||
| 121 | * |
||
| 122 | * @param \DOMNode $domNode |
||
| 123 | * @param string $attributeName |
||
| 124 | * |
||
| 125 | * @return null|string DOM node attribute value |
||
| 126 | */ |
||
| 127 | 1 | protected function getDOMAttributeValue(\DOMNode $domNode, $attributeName) |
|
| 143 | |||
| 144 | /** |
||
| 145 | * @param Node $node |
||
| 146 | * @param string $output |
||
| 147 | * @param int $level |
||
| 148 | * |
||
| 149 | * @return string |
||
| 150 | */ |
||
| 151 | 1 | public function output(Node $node, &$output = '', $level = 0) |
|
| 172 | } |
||
| 173 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: