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 |
||
10 | class RelicValueObject |
||
11 | { |
||
12 | /** |
||
13 | * @var int |
||
14 | */ |
||
15 | private $socket; |
||
16 | /** |
||
17 | * @var int |
||
18 | */ |
||
19 | private $itemId; |
||
20 | /** |
||
21 | * @var int |
||
22 | */ |
||
23 | private $context; |
||
24 | /** |
||
25 | * @var int[] |
||
26 | */ |
||
27 | private $bonusLists; |
||
28 | |||
29 | /** |
||
30 | * RelicValueObject constructor. |
||
31 | * @param int $socket |
||
32 | * @param int $itemId |
||
33 | * @param int $context |
||
34 | * @param int[] $bonusLists |
||
35 | */ |
||
36 | View Code Duplication | public function __construct( |
|
47 | |||
48 | /** |
||
49 | * @return int |
||
50 | */ |
||
51 | public function getSocket() |
||
55 | |||
56 | /** |
||
57 | * @return int |
||
58 | */ |
||
59 | public function getItemId() |
||
63 | |||
64 | /** |
||
65 | * @return int |
||
66 | */ |
||
67 | public function getContext() |
||
71 | |||
72 | /** |
||
73 | * @return int[] |
||
74 | */ |
||
75 | public function getBonusLists() |
||
79 | } |
||
80 |
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.