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 |
||
5 | View Code Duplication | class Biasing |
|
|
|||
6 | { |
||
7 | /** @var string[] */ |
||
8 | private $bringToTop = array(); |
||
9 | |||
10 | /** |
||
11 | * @var bool |
||
12 | */ |
||
13 | private $augmentBiases = false; |
||
14 | |||
15 | /** |
||
16 | * @var float|null |
||
17 | */ |
||
18 | private $influence = null; |
||
19 | |||
20 | /** |
||
21 | * @var Bias[] |
||
22 | */ |
||
23 | private $biases = array(); |
||
24 | |||
25 | /** |
||
26 | * @return string[] |
||
27 | */ |
||
28 | public function getBringToTop() |
||
32 | |||
33 | /** |
||
34 | * @param string[] $bringToTop |
||
35 | * |
||
36 | * @return Biasing |
||
37 | */ |
||
38 | public function setBringToTop($bringToTop) |
||
43 | |||
44 | /** |
||
45 | * @return boolean |
||
46 | */ |
||
47 | public function isAugmentBiases() |
||
51 | |||
52 | /** |
||
53 | * @param boolean $augmentBiases |
||
54 | * |
||
55 | * @return Biasing |
||
56 | */ |
||
57 | public function setAugmentBiases($augmentBiases) |
||
62 | |||
63 | /** |
||
64 | * @return float|null |
||
65 | */ |
||
66 | public function getInfluence() |
||
70 | |||
71 | /** |
||
72 | * @param float|null $influence |
||
73 | * |
||
74 | * @return Biasing |
||
75 | */ |
||
76 | public function setInfluence($influence) |
||
81 | |||
82 | /** |
||
83 | * @return Bias[] |
||
84 | */ |
||
85 | public function getBiases() |
||
89 | |||
90 | /** |
||
91 | * @param Bias[] $biases |
||
92 | * |
||
93 | * @return Biasing |
||
94 | */ |
||
95 | public function setBiases($biases) |
||
100 | } |
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.