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 |
||
11 | class CloverLoader implements FileChecker |
||
12 | { |
||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $file; |
||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | protected $coveredLines; |
||
21 | |||
22 | /** |
||
23 | * XMLReport constructor. |
||
24 | * @param string $file the path the to phpunit clover file |
||
25 | */ |
||
26 | public function __construct($file) |
||
30 | |||
31 | /** |
||
32 | * {@inheritdoc} |
||
33 | */ |
||
34 | public function getLines() |
||
48 | |||
49 | /** |
||
50 | * {@inheritdoc} |
||
51 | */ |
||
52 | public function isValidLine($file, $line) |
||
60 | |||
61 | /** |
||
62 | * {@inheritdoc} |
||
63 | */ |
||
64 | public function handleNotFoundFile() |
||
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | */ |
||
72 | public static function getDescription() |
||
76 | |||
77 | View Code Duplication | protected function checkForNewFiles($reader, $currentFile) |
|
88 | |||
89 | /** |
||
90 | * @param $reader |
||
91 | * @param $currentFile |
||
92 | */ |
||
93 | protected function addLine($reader, $currentFile) |
||
102 | |||
103 | protected function handleStatement($reader, $currentFile) |
||
112 | } |
||
113 |
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.