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 |
||
| 12 | class UserInvitationObserver |
||
| 13 | { |
||
| 14 | |||
| 15 | public $service; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * UserInvitationObserver constructor. |
||
| 19 | * |
||
| 20 | * @param $service |
||
| 21 | */ |
||
| 22 | public function __construct(UserInvitations $service) |
||
| 23 | { |
||
| 24 | $this->service = $service; |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Listen to the UserInvitation created event. |
||
| 29 | * |
||
| 30 | * @param UserInvitation $invitation |
||
| 31 | * @return void |
||
| 32 | */ |
||
| 33 | public function created(UserInvitation $invitation) |
||
| 34 | { |
||
| 35 | $this->service->send($invitation); |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Listen to the UserInvitation deleting event. |
||
| 40 | * |
||
| 41 | * @param UserInvitation $invitation |
||
| 42 | * @return void |
||
| 43 | */ |
||
| 44 | public function deleting(UserInvitation $invitation) |
||
|
|
|||
| 45 | { |
||
| 46 | // |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Listen to the UserInvitation deleted event. |
||
| 51 | */ |
||
| 52 | View Code Duplication | public function deleted(UserInvitation $invitation) |
|
| 68 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.