Conditions | 1 |
Paths | 1 |
Total Lines | 12 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
37 | public function handle(DomainEvent $event) : void |
||
38 | { |
||
39 | $notification = new Notification( |
||
40 | $event->notificationId()->id(), |
||
|
|||
41 | $event->userId()->id(), |
||
42 | $event->body()->body(), |
||
43 | $event->occurredOn()->getTimestamp(), |
||
44 | $event->status()->status() |
||
45 | ); |
||
46 | |||
47 | $this->view->save($notification); |
||
48 | } |
||
49 | } |
||
50 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: