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 declare(strict_types=1); |
||
18 | class Logo extends RuleAbstract |
||
19 | { |
||
20 | const NODE_NAME = 'image'; |
||
21 | |||
22 | protected $urlAttributeName = 'url'; |
||
23 | |||
24 | /** |
||
25 | * @return string |
||
26 | */ |
||
27 | 1 | public function getUrlAttributeName() : string |
|
31 | |||
32 | /** |
||
33 | * @param string $name |
||
34 | */ |
||
35 | public function setUrlAttributeName(string $name) : void |
||
39 | |||
40 | /** |
||
41 | * @param NodeInterface $node |
||
42 | * @param \DOMElement $element |
||
43 | */ |
||
44 | 1 | public function setProperty(NodeInterface $node, \DOMElement $element) : void |
|
55 | |||
56 | /** |
||
57 | * @inheritDoc |
||
58 | */ |
||
59 | 2 | protected function hasValue(NodeInterface $node) : bool |
|
63 | |||
64 | /** |
||
65 | * @inheritDoc |
||
66 | */ |
||
67 | 1 | View Code Duplication | protected function addElement(\DomDocument $document, \DOMElement $rootElement, NodeInterface $node) : void |
78 | } |
||
79 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.