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 |
||
21 | class Job extends AbstractRepository |
||
22 | { |
||
23 | /** |
||
24 | * Gets a pagination cursor to the jobs collection |
||
25 | * |
||
26 | * @param $params |
||
27 | * @return mixed |
||
28 | */ |
||
29 | View Code Duplication | public function getPaginatorCursor($params) |
|
36 | |||
37 | /** |
||
38 | * Checks, if a job posting with a certain applyId (external job id) exists |
||
39 | * |
||
40 | * @param $applyId |
||
41 | * @return bool |
||
42 | * @throws \Doctrine\ODM\MongoDB\MongoDBException |
||
43 | */ |
||
44 | View Code Duplication | public function existsApplyId($applyId) |
|
55 | |||
56 | /** |
||
57 | * @param $resourceId |
||
58 | * @return array |
||
59 | */ |
||
60 | public function findByAssignedPermissionsResourceId($resourceId) |
||
70 | |||
71 | /** |
||
72 | * Gets the Job Titles of a certain user. |
||
73 | * |
||
74 | * @param $query |
||
75 | * @param $userId |
||
76 | * @return mixed |
||
77 | * @throws \Doctrine\ODM\MongoDB\MongoDBException |
||
78 | */ |
||
79 | public function getTypeAheadResults($query, $userId) |
||
93 | |||
94 | /** |
||
95 | * Look for an drafted Document of a given user |
||
96 | * |
||
97 | * @param $user |
||
98 | * @return \Jobs\Entity\Job|null |
||
99 | */ |
||
100 | View Code Duplication | public function findDraft($user) |
|
119 | |||
120 | /** |
||
121 | * @return string |
||
122 | */ |
||
123 | public function getUniqueReference() |
||
127 | |||
128 | /** |
||
129 | * Selects job postings of a certain organization |
||
130 | * |
||
131 | * @param int $organizationId |
||
132 | * @return \Jobs\Entity\Job[] |
||
133 | */ |
||
134 | public function findByOrganization($organizationId) |
||
140 | |||
141 | /** |
||
142 | * Selects all Organizations with Active Jobs |
||
143 | * |
||
144 | * @return mixed |
||
145 | * @throws \Doctrine\ODM\MongoDB\MongoDBException |
||
146 | */ |
||
147 | public function findActiveOrganizations() |
||
164 | |||
165 | /** |
||
166 | * @return Cursor |
||
167 | * @throws \Doctrine\ODM\MongoDB\MongoDBException |
||
168 | */ |
||
169 | public function findActiveJob($hydrate = true) |
||
182 | } |
||
183 |
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.