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 |
||
7 | final class PhpCsConfigData extends AbstractToolConfigData |
||
8 | { |
||
9 | const TOOL = 'phpcs'; |
||
10 | const STANDARD_KEY = 'standard'; |
||
11 | const STANDARDS_LIST = '[PSR2/PHPCS/MySource/Zend/Squiz/PSR1/PEAR]'; |
||
12 | const ENABLED_KEY = 'enabled'; |
||
13 | const DEFAULT_ANSWER = 'Y'; |
||
14 | /** @var string */ |
||
15 | private $standard = 'PSR2'; |
||
16 | |||
17 | /** |
||
18 | * @param array $data |
||
19 | * |
||
20 | * @return array |
||
21 | */ |
||
22 | 9 | public function createConfigData(array $data) |
|
30 | |||
31 | /** |
||
32 | * @return string |
||
33 | */ |
||
34 | 9 | protected function getToolName() |
|
38 | |||
39 | 9 | View Code Duplication | private function setEnabled() |
54 | |||
55 | 9 | private function setStandard() |
|
66 | } |
||
67 |
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.