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 |
||
| 29 | abstract class AssetsAbstract implements AssetsInterface |
||
| 30 | { |
||
| 31 | |||
| 32 | /** |
||
| 33 | * DOM tag name of asset item |
||
| 34 | * |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | protected $element_tag = 'a-asset-item'; |
||
| 38 | |||
| 39 | protected $attrs = array(); |
||
| 40 | /** |
||
| 41 | * Asset constructor set asset ID |
||
| 42 | * |
||
| 43 | * @param string $id |
||
| 44 | */ |
||
| 45 | 6 | public function __construct(string $id) |
|
| 49 | |||
| 50 | /** |
||
| 51 | * Set ID attribute of the asset |
||
| 52 | * |
||
| 53 | * {@inheritdoc} |
||
| 54 | * |
||
| 55 | * @param string $id |
||
| 56 | */ |
||
| 57 | 9 | public function id(string $id = 'untitled'): AssetsInterface |
|
| 62 | |||
| 63 | /** |
||
| 64 | * Set Assets src attribute |
||
| 65 | * |
||
| 66 | * {@inheritdoc} |
||
| 67 | * |
||
| 68 | * @param null|string $src |
||
| 69 | * @return void |
||
|
|
|||
| 70 | */ |
||
| 71 | 3 | public function src(string $src = null): AssetsInterface |
|
| 76 | |||
| 77 | /** |
||
| 78 | * Create and add DOM element of the asset |
||
| 79 | * |
||
| 80 | * @param \DOMDocument $aframe_dom |
||
| 81 | * @return \DOMElement |
||
| 82 | */ |
||
| 83 | 3 | public function domElement(&$aframe_dom): DOMElement |
|
| 90 | |||
| 91 | /** |
||
| 92 | * Set Dom element name |
||
| 93 | * |
||
| 94 | * @param string $element_tag |
||
| 95 | * @return void |
||
| 96 | */ |
||
| 97 | 6 | public function setDomElementTag(string $element_tag) |
|
| 101 | |||
| 102 | /** |
||
| 103 | * Append DOM attributes no set by components |
||
| 104 | * |
||
| 105 | * @param \DOMElement $a_entity |
||
| 106 | */ |
||
| 107 | 3 | private function appendAttributes(\DOMElement &$a_entity) |
|
| 113 | |||
| 114 | 3 | View Code Duplication | private function setAttribute(&$a_entity, $attr, $val) |
| 121 | } |
||
| 122 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.