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 Updater extends RepositoryUpdater |
||
| 26 | { |
||
| 27 | protected $model; |
||
| 28 | |||
| 29 | public function __construct(UserInterface $model) |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Add a new user. |
||
| 36 | * |
||
| 37 | * @param array $info |
||
| 38 | * |
||
| 39 | * @return bool |
||
| 40 | */ |
||
| 41 | View Code Duplication | public function create(array $info) |
|
| 56 | |||
| 57 | /** |
||
| 58 | * Soft deletes a user and empties the email. |
||
| 59 | * |
||
| 60 | * @return bool |
||
| 61 | */ |
||
| 62 | View Code Duplication | public function delete() |
|
| 73 | |||
| 74 | /** |
||
| 75 | * Updates the users settings, validates the fields. |
||
| 76 | * |
||
| 77 | * @param array $info |
||
| 78 | * |
||
| 79 | * @return Eloquent\Model |
||
| 80 | */ |
||
| 81 | View Code Duplication | public function update(array $attributes = []) |
|
| 91 | |||
| 92 | /** |
||
| 93 | * Update user messages setting. |
||
| 94 | * |
||
| 95 | * @param array $input |
||
| 96 | */ |
||
| 97 | View Code Duplication | public function updateMessagesSettings(array $input) |
|
| 108 | } |
||
| 109 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.