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 Fetcher extends Repository |
||
| 22 | { |
||
| 23 | public function __construct(Project $model) |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Returns collection of active projects. |
||
| 30 | * |
||
| 31 | * @return Eloquent\Collection |
||
| 32 | */ |
||
| 33 | public function getActiveProjects() |
||
| 37 | |||
| 38 | public function getNotes() |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Returns collection of public projects. |
||
| 45 | * |
||
| 46 | * @return Eloquent\Collection |
||
| 47 | */ |
||
| 48 | public function getPublicProjects() |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Returns all users that are not assigned in the current project. |
||
| 55 | * |
||
| 56 | * @return array |
||
| 57 | */ |
||
| 58 | public function getNotMembers() |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Fetch and filter issues in the project. |
||
| 65 | * |
||
| 66 | * @param int $status |
||
| 67 | * @param array $filter |
||
| 68 | * |
||
| 69 | * @return \Illuminate\Database\Eloquent\Collection |
||
| 70 | */ |
||
| 71 | public function getIssues($status = Project\Issue::STATUS_OPEN, array $filter = []) |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Fetch and filter issues in the project. |
||
| 101 | * |
||
| 102 | * @param int $status |
||
| 103 | * @param array $filter |
||
| 104 | * |
||
| 105 | * @return \Illuminate\Database\Eloquent\Collection |
||
| 106 | */ |
||
| 107 | public function getIssuesForLoggedUser($status = Project\Issue::STATUS_OPEN, array $filter = []) |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Fetch issues assigned to a user. |
||
| 118 | * |
||
| 119 | * @param UserInterface $user |
||
| 120 | * |
||
| 121 | * @return \Illuminate\Database\Eloquent\Collection |
||
| 122 | */ |
||
| 123 | public function getAssignedOrCreatedIssues(UserInterface $user) |
||
| 131 | |||
| 132 | public function getCreatedIssues(UserInterface $user) |
||
| 140 | |||
| 141 | public function getAssignedIssues(UserInterface $user) |
||
| 149 | |||
| 150 | public function getRecentActivities(UserInterface $user = null, $limit = 10) |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Returns projects with issues details eager loaded. |
||
| 168 | * |
||
| 169 | * @return Relations\HasMany |
||
| 170 | */ |
||
| 171 | public function getPublicProjectsWithRecentIssues() |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Returns collection of tags for Kanban view. |
||
| 183 | * |
||
| 184 | * @param UserInterface $user |
||
| 185 | * |
||
| 186 | * @return mixed |
||
| 187 | */ |
||
| 188 | public function getKanbanTagsForUser(UserInterface $user) |
||
| 192 | |||
| 193 | public function getKanbanTags() |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Returns users assigned to the project that can fix issues (with edit permission). |
||
| 200 | * |
||
| 201 | * @return Relations\BelongsToMany |
||
| 202 | */ |
||
| 203 | public function getUsersCanFixIssue() |
||
| 211 | |||
| 212 | public function getUsers() |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Sort by updated_at column. |
||
| 219 | * |
||
| 220 | * @param HasMany $query |
||
| 221 | * @param string $order |
||
| 222 | * |
||
| 223 | * @return void |
||
| 224 | */ |
||
| 225 | protected function sortByUpdated(HasMany $query, $order = 'asc') |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Sort by issues tag group |
||
| 232 | * Note: this sort will return the collection. |
||
| 233 | * |
||
| 234 | * @param HasMany $query |
||
| 235 | * @param string $tagGroup |
||
| 236 | * @param string $order |
||
| 237 | * |
||
| 238 | * @return Eloquent\Collection |
||
| 239 | */ |
||
| 240 | View Code Duplication | protected function sortByTag(HasMany $query, $tagGroup, $order = 'asc') |
|
| 263 | |||
| 264 | /** |
||
| 265 | * Returns projects with open issue count. |
||
| 266 | * |
||
| 267 | * @param int $status |
||
| 268 | * @param int $private |
||
| 269 | * |
||
| 270 | * @return Collection |
||
| 271 | */ |
||
| 272 | View Code Duplication | public function getProjectsWithOpenIssuesCount($status = Project::STATUS_OPEN, $private = Project::PRIVATE_YES) |
|
| 282 | |||
| 283 | /** |
||
| 284 | * Return projects with count of open & closed issues. |
||
| 285 | * |
||
| 286 | * @param array $projectIds |
||
| 287 | * |
||
| 288 | * @return Collection |
||
| 289 | */ |
||
| 290 | public function getProjectsWithCountIssues(array $projectIds) |
||
| 297 | } |
||
| 298 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..