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 | View Code Duplication | class Bias |
|
21 | { |
||
22 | |||
23 | /** @var string */ |
||
24 | private $name; |
||
25 | |||
26 | /** @var string */ |
||
27 | private $content; |
||
28 | |||
29 | /** @var string */ |
||
30 | private $strength; |
||
31 | |||
32 | /** |
||
33 | * @return string |
||
34 | */ |
||
35 | public function getName() |
||
39 | |||
40 | /** |
||
41 | * @param string $name |
||
42 | * |
||
43 | * @return Bias |
||
44 | */ |
||
45 | public function setName($name) |
||
50 | |||
51 | /** |
||
52 | * @return string |
||
53 | */ |
||
54 | public function getContent() |
||
58 | |||
59 | /** |
||
60 | * @param string $content |
||
61 | * |
||
62 | * @return Bias |
||
63 | */ |
||
64 | public function setContent($content) |
||
69 | |||
70 | /** |
||
71 | * @return string |
||
72 | */ |
||
73 | public function getStrength() |
||
77 | |||
78 | /** |
||
79 | * @param string $strength |
||
80 | * |
||
81 | * @return Bias |
||
82 | */ |
||
83 | public function setStrength($strength) |
||
88 | } |
||
89 |
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.