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 Config { |
||
9 | private $properties = []; |
||
10 | private $pseudo = []; |
||
11 | private $functionSet; |
||
12 | private $headers; |
||
13 | private $filePath; |
||
14 | private $formatter; |
||
15 | private $line = 0; |
||
16 | private $elementData; |
||
17 | private $xPath; |
||
18 | private $valueParser; |
||
19 | |||
20 | View Code Duplication | public function __construct(Functionset $functionSet, Parser\Value $valueParser, Hook\ElementData $elementData, Hook\Formatter $formatter, Parser\CssToXpath $xPath, FilePath $filePath, &$headers) { |
|
29 | |||
30 | public function getFormatter() { |
||
33 | |||
34 | public function &getHeaders() { |
||
37 | |||
38 | public function getFilePath() { |
||
41 | |||
42 | public function &getLine() { |
||
46 | |||
47 | public function registerFormatter($formatter) { |
||
50 | |||
51 | public function getFunctionSet() { |
||
54 | |||
55 | public function getElementData() { |
||
58 | |||
59 | public function getCssToXpath() { |
||
62 | |||
63 | public function getValueParser() { |
||
66 | |||
67 | public function registerProperty($name, Property $property) { |
||
70 | |||
71 | public function registerContentPseudo($name, Property\ContentPseudo $pseudo) { |
||
72 | if (isset($this->properties['content'])) $this->properties['content']->addContentPseudo($name, $pseudo); |
||
73 | } |
||
74 | |||
75 | public function registerPseudo($name, Pseudo $pseudo) { |
||
76 | $this->pseudo[$name] = $pseudo; |
||
77 | } |
||
78 | |||
79 | public function loadProperties(Hook\PropertyHook $hook) { |
||
82 | |||
83 | public function createPseudoMatcher($pseudo) { |
||
88 | |||
89 | } |
||
90 |
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.