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 |
||
16 | class Precipitation implements ModelInterface |
||
17 | { |
||
18 | /** @var int */ |
||
19 | protected $probability; |
||
20 | |||
21 | /** @var float */ |
||
22 | protected $intensity; |
||
23 | |||
24 | /** @var float */ |
||
25 | protected $accumulation; |
||
26 | |||
27 | |||
28 | |||
29 | /** @var string */ |
||
30 | protected $type; |
||
31 | |||
32 | /** |
||
33 | * @return mixed |
||
34 | */ |
||
35 | public function getIntensity() |
||
39 | |||
40 | /** |
||
41 | * @return mixed |
||
42 | */ |
||
43 | public function getProbability() |
||
47 | |||
48 | /** |
||
49 | * @return string |
||
50 | */ |
||
51 | public function getType() |
||
55 | |||
56 | /** |
||
57 | * @api |
||
58 | * |
||
59 | * @return string |
||
60 | */ |
||
61 | public function __toString() |
||
65 | |||
66 | /** |
||
67 | * @param array $data |
||
68 | * @return $this |
||
69 | */ |
||
70 | View Code Duplication | public function setData(array $data) |
|
85 | } |
||
86 |
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.