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 |
||
| 22 | class ProjectRepository extends Repository implements ProjectContract |
||
| 23 | { |
||
| 24 | protected $updaterClass = UpdaterRepository::class; |
||
| 25 | protected $counterClass = CounterRepository::class; |
||
| 26 | |||
| 27 | public function __construct(Project $model) |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Returns collection of active projects. |
||
| 34 | * |
||
| 35 | * @return Eloquent\Collection |
||
| 36 | */ |
||
| 37 | public function getActiveProjects() |
||
| 41 | |||
| 42 | public function getNotes() |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Returns collection of public projects. |
||
| 49 | * |
||
| 50 | * @return Eloquent\Collection |
||
| 51 | */ |
||
| 52 | public function getPublicProjects() |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Returns all users that are not assigned in the current project. |
||
| 59 | * |
||
| 60 | * @return array |
||
| 61 | */ |
||
| 62 | public function getNotMembers() |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Fetch and filter issues in the project. |
||
| 69 | * |
||
| 70 | * @param int $status |
||
| 71 | * @param array $filter |
||
| 72 | * |
||
| 73 | * @return \Illuminate\Database\Eloquent\Collection |
||
| 74 | */ |
||
| 75 | public function getIssues($status = Project\Issue::STATUS_OPEN, array $filter = []) |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Fetch issues assigned to a user. |
||
| 105 | * |
||
| 106 | * @param UserInterface $user |
||
| 107 | * |
||
| 108 | * @return \Illuminate\Database\Eloquent\Collection |
||
| 109 | */ |
||
| 110 | public function getAssignedOrCreatedIssues(UserInterface $user) |
||
| 118 | |||
| 119 | public function getCreatedIssues(UserInterface $user) |
||
| 127 | |||
| 128 | public function getAssignedIssues(UserInterface $user) |
||
| 136 | |||
| 137 | public function getRecentActivities(UserInterface $user, $limit = 10) |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Returns projects with issues details eager loaded. |
||
| 155 | * |
||
| 156 | * @return Relations\HasMany |
||
| 157 | */ |
||
| 158 | public function getPublicProjectsWithRecentIssues() |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Returns collection of tags for Kanban view. |
||
| 170 | * |
||
| 171 | * @param UserInterface $user |
||
| 172 | * |
||
| 173 | * @return mixed |
||
| 174 | */ |
||
| 175 | public function getKanbanTagsForUser(UserInterface $user) |
||
| 179 | |||
| 180 | public function getKanbanTags() |
||
| 184 | |||
| 185 | /** |
||
| 186 | * Returns users assigned to the project that can fix issues (with edit permission). |
||
| 187 | * |
||
| 188 | * @return Relations\BelongsToMany |
||
| 189 | */ |
||
| 190 | public function getUsersCanFixIssue() |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Sort by updated_at column. |
||
| 201 | * |
||
| 202 | * @param HasMany $query |
||
| 203 | * @param string $order |
||
| 204 | * |
||
| 205 | * @return void |
||
| 206 | */ |
||
| 207 | protected function sortByUpdated(HasMany $query, $order = 'asc') |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Sort by issues tag group |
||
| 214 | * Note: this sort will return the collection. |
||
| 215 | * |
||
| 216 | * @param HasMany $query |
||
| 217 | * @param string $tagGroup |
||
| 218 | * @param string $order |
||
| 219 | * |
||
| 220 | * @return Eloquent\Collection |
||
| 221 | */ |
||
| 222 | View Code Duplication | protected function sortByTag(HasMany $query, $tagGroup, $order = 'asc') |
|
| 245 | |||
| 246 | /** |
||
| 247 | * Returns projects with open issue count. |
||
| 248 | * |
||
| 249 | * @param int $status |
||
| 250 | * @param int $private |
||
| 251 | * |
||
| 252 | * @return Collection |
||
| 253 | */ |
||
| 254 | View Code Duplication | public function getProjectsWithOpenIssuesCount($status = Project::STATUS_OPEN, $private = Project::PRIVATE_YES) |
|
| 264 | |||
| 265 | /** |
||
| 266 | * Return projects with count of open & closed issues. |
||
| 267 | * |
||
| 268 | * @param array $projectIds |
||
| 269 | * |
||
| 270 | * @return Collection |
||
| 271 | */ |
||
| 272 | public function getProjectsWithCountIssues(array $projectIds) |
||
| 279 | } |
||
| 280 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.