| 1 | <?php |
||
| 9 | class Broadcaster |
||
| 10 | { |
||
| 11 | protected $notifiable; |
||
| 12 | protected $channel; |
||
| 13 | protected $config; |
||
| 14 | protected $channelName; |
||
| 15 | |||
| 16 | public function __construct(NotifiableInterface $notifiable, ChannelInterface $channel, array $config) |
||
| 39 | |||
| 40 | public function broadcast(NotificationInterface $notification) |
||
| 48 | } |
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: