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 Fetcher extends Repository |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * @var User |
||
| 26 | */ |
||
| 27 | protected $model; |
||
| 28 | |||
| 29 | public function __construct(UserInterface $model) |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Returns projects the user member of. |
||
| 36 | * |
||
| 37 | * @return Eloquent\Collection |
||
| 38 | */ |
||
| 39 | public function getProjects() |
||
| 43 | |||
| 44 | public function getProjectsWithSettings() |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Returns public users. |
||
| 51 | * |
||
| 52 | * @return Eloquent\Collection |
||
| 53 | */ |
||
| 54 | public function getActiveUsers() |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Returns user projects with activities details eager loaded. |
||
| 61 | * |
||
| 62 | * @param int $status |
||
| 63 | * @done |
||
| 64 | * |
||
| 65 | * @return Relations\HasMany |
||
| 66 | */ |
||
| 67 | public function getProjectsWithRecentActivities($status = Project::STATUS_OPEN) |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Returns projects with issues details eager loaded. |
||
| 74 | * |
||
| 75 | * @return Relations\HasMany |
||
| 76 | */ |
||
| 77 | public function getProjectsWithRecentIssues() |
||
| 91 | |||
| 92 | public function getIssuesGroupByTags(Eloquent\Collection $tagIds, $projectId = null) |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Returns all projects with open issue count. |
||
| 116 | * |
||
| 117 | * @param int $status |
||
| 118 | * |
||
| 119 | * @return Builder|Relations\BelongsToMany |
||
| 120 | */ |
||
| 121 | public function getProjectsWithOpenIssuesCount($status = Project::STATUS_OPEN) |
||
| 129 | } |
||
| 130 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.