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 |
||
32 | class RaListingRepository extends EntityRepository |
||
33 | { |
||
34 | /** |
||
35 | * @var InstitutionAuthorizationRepositoryFilter |
||
36 | */ |
||
37 | private $authorizationRepositoryFilter; |
||
38 | |||
39 | public function __construct( |
||
47 | |||
48 | /** |
||
49 | * @param IdentityId $identityId The RA's identity id. |
||
50 | * @return null|RaListing |
||
|
|||
51 | */ |
||
52 | public function findByIdentityId(IdentityId $identityId) |
||
56 | |||
57 | /** |
||
58 | * @param IdentityId $identityId The RA's identity id. |
||
59 | * @param Institution $raInstitution |
||
60 | * @return null|RaListing |
||
61 | */ |
||
62 | public function findByIdentityIdAndRaInstitution(IdentityId $identityId, Institution $raInstitution) |
||
69 | |||
70 | /** |
||
71 | * @param IdentityId $identityId The RA's identity id. |
||
72 | * @param Institution $institution |
||
73 | * @return RaListing[] |
||
74 | */ |
||
75 | public function findByIdentityIdAndInstitution(IdentityId $identityId, Institution $institution) |
||
82 | |||
83 | public function save(RaListing $raListingEntry) |
||
88 | |||
89 | /** |
||
90 | * @param RaListingQuery $query |
||
91 | * @return \Doctrine\ORM\Query |
||
92 | */ |
||
93 | public function createSearchQuery(RaListingQuery $query) |
||
134 | |||
135 | /** |
||
136 | * @param Institution $raInstitution |
||
137 | * @return ArrayCollection |
||
138 | */ |
||
139 | public function listRasFor(Institution $raInstitution) |
||
149 | |||
150 | /** |
||
151 | * @param IdentityId $identityId |
||
152 | * @return void |
||
153 | */ |
||
154 | View Code Duplication | public function removeByIdentityId(IdentityId $identityId) |
|
164 | |||
165 | /** |
||
166 | * @param IdentityId $identityId |
||
167 | * @param Institution $raInstitution |
||
168 | * @return void |
||
169 | */ |
||
170 | View Code Duplication | public function removeByIdentityIdAndRaInstitution(IdentityId $identityId, Institution $raInstitution) |
|
181 | |||
182 | /** |
||
183 | * @param IdentityId $identityId |
||
184 | * @param Institution $institution |
||
185 | * @return void |
||
186 | */ |
||
187 | View Code Duplication | public function removeByIdentityIdAndInstitution(IdentityId $identityId, Institution $institution) |
|
198 | } |
||
199 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.