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 Rdf extends Rss |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * Format version |
||
23 | */ |
||
24 | const VERSION = '1.0'; |
||
25 | |||
26 | /** |
||
27 | * RDF document must have a <rdf> root node |
||
28 | */ |
||
29 | const ROOT_NODE_TAGNAME = 'rdf'; |
||
30 | |||
31 | /** |
||
32 | * publication date |
||
33 | */ |
||
34 | const DATE_NODE_TAGNAME = 'dc:date'; |
||
35 | |||
36 | /** |
||
37 | * Tells if the parser can handle the feed or not |
||
38 | * @param Document $document |
||
39 | * @return boolean |
||
40 | */ |
||
41 | 2 | View Code Duplication | public function canHandle(Document $document) : bool |
48 | |||
49 | /** |
||
50 | * @param DOMDocument $document |
||
51 | * @return \DomElement |
||
52 | */ |
||
53 | 2 | public function getMainElement(\DOMDocument $document) : \DOMElement |
|
57 | |||
58 | /** |
||
59 | * @return RuleSet |
||
60 | */ |
||
61 | 2 | public function buildFeedRuleSet() : RuleSet |
|
68 | } |
||
69 |
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.