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 |
||
13 | class NotifiableBehavior extends Behavior |
||
14 | { |
||
15 | public $notifications = []; |
||
16 | |||
17 | /** |
||
18 | * @var Notifier |
||
19 | */ |
||
20 | public $notifier = 'notifier'; |
||
21 | |||
22 | public function init() |
||
27 | |||
28 | /** |
||
29 | * @inheritdoc |
||
30 | */ |
||
31 | public function attach($owner) |
||
43 | |||
44 | /** |
||
45 | * @inheritdoc |
||
46 | */ |
||
47 | public function detach() |
||
61 | |||
62 | /** |
||
63 | * Handles the event using public properties. |
||
64 | * @param Event $event |
||
65 | * @throws \InvalidArgumentException |
||
66 | * @throws \RuntimeException |
||
67 | */ |
||
68 | public function handle(Event $event) |
||
88 | |||
89 | |||
90 | } |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: