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 |
||
31 | View Code Duplication | class CerbereDoneActionEvent extends CerbereEvent |
|
|
|||
32 | { |
||
33 | /** |
||
34 | * @var ActionInterface |
||
35 | */ |
||
36 | protected $action; |
||
37 | |||
38 | /** |
||
39 | * @var Project |
||
40 | */ |
||
41 | protected $project; |
||
42 | |||
43 | /** |
||
44 | * @param ActionInterface $action |
||
45 | * @param Project $project |
||
46 | */ |
||
47 | public function __construct(ActionInterface $action, Project $project) |
||
52 | |||
53 | /** |
||
54 | * @return ActionInterface |
||
55 | */ |
||
56 | public function getAction() |
||
60 | |||
61 | /** |
||
62 | * @param ActionInterface $action |
||
63 | */ |
||
64 | public function setAction($action) |
||
68 | |||
69 | /** |
||
70 | * @return Project |
||
71 | */ |
||
72 | public function getProject() |
||
76 | |||
77 | /** |
||
78 | * @param Project $project |
||
79 | */ |
||
80 | public function setProject($project) |
||
84 | } |
||
85 |
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.