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 |
||
| 20 | class SendCommentMomentHandler |
||
| 21 | { |
||
| 22 | use DispatchesJobs; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Handle the comment updated moment. |
||
| 26 | */ |
||
| 27 | public function handle(CommentEventInterface $event) |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Trigger the moment. |
||
| 40 | * |
||
| 41 | * @param \Gitamin\Models\Comment $comment |
||
| 42 | * @param int $action |
||
| 43 | */ |
||
| 44 | View Code Duplication | protected function trigger(Comment &$comment, $action) |
|
| 55 | } |
||
| 56 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: