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 |
||
7 | class Stage extends Model |
||
8 | { |
||
9 | /** |
||
10 | * @var int |
||
11 | */ |
||
12 | protected $id; |
||
13 | |||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $name; |
||
18 | |||
19 | /** |
||
20 | * @var bool |
||
21 | */ |
||
22 | protected $notify; |
||
23 | |||
24 | /** |
||
25 | * @var bool |
||
26 | */ |
||
27 | protected $inLeads; |
||
28 | |||
29 | /** |
||
30 | * @var bool |
||
31 | */ |
||
32 | protected $inDeals; |
||
33 | |||
34 | public function __construct(array $stageData = []) |
||
52 | |||
53 | /** |
||
54 | * @return bool |
||
55 | * @throws LPTrackerSDKException |
||
56 | */ |
||
57 | View Code Duplication | public function validate() |
|
69 | |||
70 | /** |
||
71 | * @return array |
||
72 | */ |
||
73 | public function toArray() |
||
83 | |||
84 | /** |
||
85 | * @return int |
||
86 | */ |
||
87 | public function getId() |
||
91 | |||
92 | /** |
||
93 | * @return string |
||
94 | */ |
||
95 | public function getName() |
||
99 | |||
100 | /** |
||
101 | * @return bool |
||
102 | */ |
||
103 | public function shouldNotify() |
||
107 | |||
108 | /** |
||
109 | * @return bool |
||
110 | */ |
||
111 | public function shouldShowInLeads() |
||
115 | |||
116 | /** |
||
117 | * @return bool |
||
118 | */ |
||
119 | public function shouldShowInDeals() |
||
123 | } |
||
124 |
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.