Conditions | 3 |
Paths | 4 |
Total Lines | 17 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
28 | public function __construct(NotifiableInterface $notifiable, ChannelInterface $channel, array $config) |
||
29 | { |
||
30 | // Set the data for Slack Broadcasts |
||
31 | if (!empty($config['webhook'])) { |
||
32 | $notifiable->setSlackWebhook($config['webhook']); |
||
|
|||
33 | } |
||
34 | |||
35 | // Set data for pusher broadcasts |
||
36 | if (!empty($config['channel_name'])) { |
||
37 | $notifiable->setPusherChannel($config['channel_name']); |
||
38 | } |
||
39 | |||
40 | $this->notifiable = $notifiable; |
||
41 | $this->channel = $channel; |
||
42 | $this->config = $config; |
||
43 | $this->channelName = $channel->channelName(); |
||
44 | } |
||
45 | |||
58 | } |
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: