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 |
||
25 | class Counter extends Repository |
||
26 | { |
||
27 | public function __construct(UserInterface $model) |
||
31 | |||
32 | /** |
||
33 | * @param int $deleted |
||
34 | * |
||
35 | * @return int |
||
36 | */ |
||
37 | public function countNotDeleted() |
||
41 | |||
42 | /** |
||
43 | * @param int $deleted |
||
44 | * |
||
45 | * @return int |
||
46 | */ |
||
47 | public function countDeleted() |
||
51 | |||
52 | /** |
||
53 | * Count number of created issues in a project. |
||
54 | * |
||
55 | * @param int $projectId |
||
56 | * |
||
57 | * @return int |
||
58 | */ |
||
59 | View Code Duplication | public function createdIssuesCount($projectId = 0) |
|
70 | |||
71 | /** |
||
72 | * Returns all projects with open issue count. |
||
73 | * |
||
74 | * @param int $status |
||
75 | * |
||
76 | * @return Builder|Relations\BelongsToMany |
||
77 | */ |
||
78 | public function projectsWithCountOpenIssues($status = Project::STATUS_OPEN) |
||
89 | |||
90 | /** |
||
91 | * Count number of archived projects. |
||
92 | * |
||
93 | * @return int |
||
94 | */ |
||
95 | public function countProjectsByStatus($status) |
||
103 | } |
||
104 |
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..