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 |
||
| 28 | class Application extends AbstractRepository |
||
| 29 | { |
||
| 30 | |||
| 31 | /** |
||
| 32 | * {@inheritDoc} |
||
| 33 | */ |
||
| 34 | View Code Duplication | public function findBy(array $criteria, array $sort = null, $limit = null, $skip = null) |
|
| 43 | |||
| 44 | /** |
||
| 45 | * {@inheritDoc} |
||
| 46 | */ |
||
| 47 | View Code Duplication | public function findOneBy(array $criteria) |
|
| 56 | |||
| 57 | /** |
||
| 58 | * {@inheritDoc} |
||
| 59 | */ |
||
| 60 | View Code Duplication | public function createQueryBuilder($findDrafts = false) |
|
| 68 | |||
| 69 | /** |
||
| 70 | * Gets a pointer to an application |
||
| 71 | * |
||
| 72 | * @param array $params |
||
| 73 | */ |
||
| 74 | public function getPaginatorCursor($params) |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Gets a query builder to search for applications |
||
| 83 | * |
||
| 84 | * @param array $params |
||
| 85 | * @return unknown |
||
| 86 | */ |
||
| 87 | View Code Duplication | protected function getPaginationQueryBuilder($params) |
|
| 94 | |||
| 95 | /** |
||
| 96 | * Gets a result list of applications |
||
| 97 | * |
||
| 98 | * @param array $params |
||
| 99 | * @return \Applications\Repository\PaginationList |
||
| 100 | */ |
||
| 101 | public function getPaginationList($params) |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @param $job |
||
| 115 | * |
||
| 116 | * @return mixed |
||
| 117 | */ |
||
| 118 | public function loadApplicationsForJob($job) |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Get unread applications |
||
| 128 | * |
||
| 129 | * @param \Jobs\Entity\JobInterface $job |
||
| 130 | * @return array|bool|\Doctrine\MongoDB\ArrayIterator|\Doctrine\MongoDB\Cursor|\Doctrine\MongoDB\EagerCursor|mixed|null |
||
| 131 | */ |
||
| 132 | public function loadUnreadApplicationsForJob($job) |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Get comments of an applications |
||
| 143 | * |
||
| 144 | * @param $commentOrId |
||
| 145 | * @internal param \Application\Entity\Comment $comment | Id |
||
| 146 | * @return \Applications\Entity\Comment|NULL |
||
| 147 | */ |
||
| 148 | public function findComment($commentOrId) |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Gets social profiles of an application |
||
| 166 | * |
||
| 167 | * @param String $profileId |
||
| 168 | * @return $profile|NULL |
||
| 169 | */ |
||
| 170 | public function findProfile($profileId) |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @return mixed |
||
| 183 | * @throws \Doctrine\ODM\MongoDB\MongoDBException |
||
| 184 | */ |
||
| 185 | public function getStates() |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @param $user UserInterface |
||
| 195 | * @param $applyId |
||
| 196 | * @return ApplicationEntity|null |
||
| 197 | */ |
||
| 198 | public function findDraft($user, $applyId) |
||
| 223 | |||
| 224 | /** |
||
| 225 | * Get applications for given user ID |
||
| 226 | * |
||
| 227 | * @param string $userId |
||
| 228 | * @param int $limit |
||
| 229 | * @return Cursor |
||
| 230 | * @since 0.27 |
||
| 231 | */ |
||
| 232 | View Code Duplication | public function getUserApplications($userId, $limit = null) |
|
| 244 | } |
||
| 245 |
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.