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 |
||
33 | View Code Duplication | class CerberePostActionEvent extends CerbereEvent |
|
|
|||
34 | { |
||
35 | /** |
||
36 | * @var Cerbere |
||
37 | */ |
||
38 | protected $cerbere; |
||
39 | |||
40 | /** |
||
41 | * @var Job |
||
42 | */ |
||
43 | protected $job; |
||
44 | |||
45 | /** |
||
46 | * @var ActionInterface |
||
47 | */ |
||
48 | protected $action; |
||
49 | |||
50 | /** |
||
51 | * @var Project[] |
||
52 | */ |
||
53 | protected $projects; |
||
54 | |||
55 | /** |
||
56 | * @param Cerbere $cerbere |
||
57 | * @param Job $job |
||
58 | * @param ActionInterface $action |
||
59 | * @param Project[] $projects |
||
60 | */ |
||
61 | public function __construct(Cerbere $cerbere, Job $job, ActionInterface $action, $projects = array()) |
||
68 | |||
69 | /** |
||
70 | * @return ActionInterface |
||
71 | */ |
||
72 | public function getAction() |
||
76 | |||
77 | /** |
||
78 | * @param ActionInterface $action |
||
79 | */ |
||
80 | public function setAction($action) |
||
84 | |||
85 | /** |
||
86 | * @return Cerbere |
||
87 | */ |
||
88 | public function getCerbere() |
||
92 | |||
93 | /** |
||
94 | * @return Job |
||
95 | */ |
||
96 | public function getJob() |
||
100 | |||
101 | /** |
||
102 | * @param Job $job |
||
103 | */ |
||
104 | public function setJob($job) |
||
108 | |||
109 | /** |
||
110 | * @return Project[] |
||
111 | */ |
||
112 | public function getProjects() |
||
116 | |||
117 | /** |
||
118 | * @param Project[] $projects |
||
119 | */ |
||
120 | public function setProjects($projects) |
||
124 | } |
||
125 |
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.