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 |
||
17 | View Code Duplication | class CallActivityListProvider implements |
|
|
|||
18 | ActivityListProviderInterface, |
||
19 | CommentProviderInterface, |
||
20 | ActivityListDateProviderInterface |
||
21 | { |
||
22 | const ACTIVITY_CLASS = 'OroCRM\Bundle\CallBundle\Entity\Call'; |
||
23 | const ACL_CLASS = 'OroCRM\Bundle\CallBundle\Entity\Call'; |
||
24 | |||
25 | /** @var DoctrineHelper */ |
||
26 | protected $doctrineHelper; |
||
27 | |||
28 | /** @var ServiceLink */ |
||
29 | protected $entityOwnerAccessorLink; |
||
30 | |||
31 | /** @var ActivityAssociationHelper */ |
||
32 | protected $activityAssociationHelper; |
||
33 | |||
34 | /** @var CommentAssociationHelper */ |
||
35 | protected $commentAssociationHelper; |
||
36 | |||
37 | /** |
||
38 | * @param DoctrineHelper $doctrineHelper |
||
39 | * @param ServiceLink $entityOwnerAccessorLink |
||
40 | * @param ActivityAssociationHelper $activityAssociationHelper |
||
41 | * @param CommentAssociationHelper $commentAssociationHelper |
||
42 | */ |
||
43 | public function __construct( |
||
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | public function isApplicableTarget($entityClass, $accessible = true) |
||
66 | |||
67 | /** |
||
68 | * {@inheritdoc} |
||
69 | */ |
||
70 | public function getSubject($entity) |
||
75 | |||
76 | /** |
||
77 | * {@inheritdoc} |
||
78 | */ |
||
79 | public function getDescription($entity) |
||
84 | |||
85 | /** |
||
86 | * {@inheritdoc} |
||
87 | */ |
||
88 | public function getOwner($entity) |
||
93 | |||
94 | /** |
||
95 | * {@inheritdoc} |
||
96 | */ |
||
97 | public function getCreatedAt($entity) |
||
102 | |||
103 | /** |
||
104 | * {@inheritdoc} |
||
105 | */ |
||
106 | public function getUpdatedAt($entity) |
||
111 | |||
112 | /** |
||
113 | * {@inheritdoc} |
||
114 | */ |
||
115 | public function getData(ActivityList $activityListEntity) |
||
119 | |||
120 | /** |
||
121 | * {@inheritdoc} |
||
122 | */ |
||
123 | public function getOrganization($activityEntity) |
||
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | public function getTemplate() |
||
136 | |||
137 | /** |
||
138 | * {@inheritdoc} |
||
139 | */ |
||
140 | public function getRoutes() |
||
148 | |||
149 | /** |
||
150 | * {@inheritdoc} |
||
151 | */ |
||
152 | public function getActivityClass() |
||
156 | |||
157 | /** |
||
158 | * {@inheritdoc} |
||
159 | */ |
||
160 | public function getAclClass() |
||
164 | |||
165 | /** |
||
166 | * {@inheritdoc} |
||
167 | */ |
||
168 | public function getActivityId($entity) |
||
172 | |||
173 | /** |
||
174 | * {@inheritdoc} |
||
175 | */ |
||
176 | public function isApplicable($entity) |
||
184 | |||
185 | /** |
||
186 | * {@inheritdoc} |
||
187 | */ |
||
188 | public function getTargetEntities($entity) |
||
192 | |||
193 | /** |
||
194 | * {@inheritdoc} |
||
195 | */ |
||
196 | public function isCommentsEnabled($entityClass) |
||
200 | |||
201 | /** |
||
202 | * {@inheritdoc} |
||
203 | */ |
||
204 | public function getActivityOwners($entity, ActivityList $activityList) |
||
219 | } |
||
220 |
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.