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 |
||
20 | class Similarity extends SimilarityAbstract implements SimilarInterface |
||
21 | { |
||
22 | const MODE_STRING = 'text'; |
||
23 | |||
24 | const MODE_NUMBER = 'number'; |
||
25 | |||
26 | protected $mode; |
||
27 | |||
28 | protected $expert; |
||
29 | |||
30 | 41 | protected function getMode() |
|
38 | |||
39 | 41 | public function setMode($mode) |
|
46 | |||
47 | 20 | View Code Duplication | public function setValues($a, $b) |
56 | |||
57 | 2 | public function setStopwords(array $list) |
|
63 | |||
64 | 21 | View Code Duplication | public function setNumberValues($a, $b) |
73 | |||
74 | 41 | protected function getExpert() |
|
82 | |||
83 | 41 | public function hasSimilarity() |
|
87 | |||
88 | public function __toArray() |
||
92 | } |
||
93 |
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.