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 |
||
16 | class Projector implements EventListenerInterface |
||
17 | { |
||
18 | use DelegateEventHandlingToSpecificMethodTrait; |
||
19 | |||
20 | /** |
||
21 | * @var RepositoryInterface |
||
22 | */ |
||
23 | private $repository; |
||
24 | |||
25 | /** |
||
26 | * @var SapiVersion |
||
27 | */ |
||
28 | private $sapiVersion; |
||
29 | |||
30 | /** |
||
31 | * @param RepositoryInterface $repository |
||
32 | * @param SapiVersion $sapiVersion |
||
33 | */ |
||
34 | public function __construct( |
||
40 | |||
41 | /** |
||
42 | * @param RoleCreated $roleCreated |
||
43 | * @param DomainMessage $domainMessage |
||
44 | */ |
||
45 | public function applyRoleCreated( |
||
54 | |||
55 | /** |
||
56 | * @param RoleRenamed $roleRenamed |
||
57 | * @param DomainMessage $domainMessage |
||
58 | */ |
||
59 | public function applyRoleRenamed( |
||
68 | |||
69 | /** |
||
70 | * @param RoleDeleted $roleDeleted |
||
71 | * @param DomainMessage $domainMessage |
||
72 | */ |
||
73 | public function applyRoleDeleted( |
||
79 | |||
80 | /** |
||
81 | * @param ConstraintAdded $constraintAdded |
||
82 | */ |
||
83 | View Code Duplication | protected function applyConstraintAdded(ConstraintAdded $constraintAdded) { |
|
92 | |||
93 | /** |
||
94 | * @param ConstraintUpdated $constraintUpdated |
||
95 | */ |
||
96 | View Code Duplication | protected function applyConstraintUpdated(ConstraintUpdated $constraintUpdated) |
|
106 | |||
107 | /** |
||
108 | * @param ConstraintRemoved $constraintRemoved |
||
109 | */ |
||
110 | protected function applyConstraintRemoved(ConstraintRemoved $constraintRemoved) |
||
119 | } |
||
120 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.