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 namespace App\Modules\Roles\Repositories; |
||
| 6 | class RoleRepository extends BaseRepository |
||
| 7 | { |
||
| 8 | /** |
||
| 9 | * Init new object. |
||
| 10 | * |
||
| 11 | * @param Role $model |
||
| 12 | * @return void |
||
|
|
|||
| 13 | */ |
||
| 14 | public function __construct(Role $model) |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Assign the given permission ids to the given role. |
||
| 21 | * |
||
| 22 | * @param integer $roleId |
||
| 23 | * @param array $permissionIds |
||
| 24 | * @return object |
||
| 25 | */ |
||
| 26 | View Code Duplication | public function assignPermissions($roleId, $permissionIds) |
|
| 36 | } |
||
| 37 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.