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 |
||
| 9 | class User extends ArrayCollection |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @param UserEntity $user |
||
| 13 | * @return $this |
||
| 14 | */ |
||
| 15 | public function update(UserEntity $user) |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param UserEntity $user |
||
| 29 | */ |
||
| 30 | public function append(UserEntity $user) |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @return UserEntity|null |
||
| 37 | */ |
||
| 38 | public function current() |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param UserEntity $user |
||
| 45 | * @return bool|int |
||
| 46 | */ |
||
| 47 | View Code Duplication | public function findKey(UserEntity $user) |
|
| 59 | |||
| 60 | |||
| 61 | |||
| 62 | View Code Duplication | public function findById($id) |
|
| 75 | |||
| 76 | } |