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) |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @param Institution $raInstitution |
||
| 131 | * @return ArrayCollection |
||
| 132 | */ |
||
| 133 | public function listRasFor(Institution $raInstitution) |
||
| 143 | |||
| 144 | /** |
||
| 145 | * @param IdentityId $identityId |
||
| 146 | * @return void |
||
| 147 | */ |
||
| 148 | View Code Duplication | public function removeByIdentityId(IdentityId $identityId) |
|
| 158 | |||
| 159 | /** |
||
| 160 | * @param IdentityId $identityId |
||
| 161 | * @param Institution $raInstitution |
||
| 162 | * @return void |
||
| 163 | */ |
||
| 164 | View Code Duplication | public function removeByIdentityIdAndRaInstitution(IdentityId $identityId, Institution $raInstitution) |
|
| 175 | |||
| 176 | /** |
||
| 177 | * @param IdentityId $identityId |
||
| 178 | * @param Institution $institution |
||
| 179 | * @return void |
||
| 180 | */ |
||
| 181 | View Code Duplication | public function removeByIdentityIdAndInstitution(IdentityId $identityId, Institution $institution) |
|
| 192 | } |
||
| 193 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.