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 |
||
| 19 | class Counter extends Repository |
||
| 20 | { |
||
| 21 | public function __construct(UserInterface $model) |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Count active users. |
||
| 28 | * |
||
| 29 | * @return int |
||
| 30 | */ |
||
| 31 | public function countNotDeleted() |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Count deleted users. |
||
| 38 | * |
||
| 39 | * @return int |
||
| 40 | */ |
||
| 41 | public function countDeleted() |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Count number of created issues in a project. |
||
| 48 | * |
||
| 49 | * @param int $projectId |
||
| 50 | * |
||
| 51 | * @return int |
||
| 52 | */ |
||
| 53 | public function createdIssuesCount($projectId = 0) |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Count number of archived projects. |
||
| 67 | * |
||
| 68 | * @param $status |
||
| 69 | * |
||
| 70 | * @return int |
||
| 71 | */ |
||
| 72 | public function countProjectsByStatus($status) |
||
| 80 | } |
||
| 81 |
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..