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 |
||
9 | class PropertyHook implements \Transphporm\Hook { |
||
10 | private $rules; |
||
11 | private $configLine; |
||
12 | private $file; |
||
13 | private $filePath; |
||
14 | private $line; |
||
15 | private $valueParser; |
||
16 | private $pseudoMatcher; |
||
17 | private $properties = []; |
||
18 | private $functionSet; |
||
19 | |||
20 | View Code Duplication | public function __construct(array $rules, &$configLine, $file, $line, PseudoMatcher $pseudoMatcher, |
|
31 | |||
32 | public function runOnImmutableElements(): bool { |
||
35 | |||
36 | public function run(\DomElement $element) { |
||
50 | |||
51 | // TODO: Have all rule values parsed before running them so that things like `content-append` are not expecting tokens |
||
52 | // problem with this is that anything in data changed by run properties is not shown |
||
53 | // TODO: Allow `update-frequency` to be parsed before it is accessed in rule (might need to switch location of rule check) |
||
54 | private function callProperties($element) { |
||
63 | |||
64 | public function registerProperty($name, \Transphporm\Property $property) { |
||
67 | |||
68 | private function callProperty($name, $element, $value) { |
||
79 | } |
||
80 |
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.