Conditions | 5 |
Paths | 5 |
Total Lines | 23 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
16 | public function __construct(NotifiableInterface $notifiable, ChannelInterface $channel, array $config) |
||
17 | { |
||
18 | $this->notifiable = $notifiable; |
||
19 | $this->channel = $channel; |
||
20 | $this->config = $config; |
||
21 | $this->channelName = $channel->channelName(); |
||
22 | |||
23 | switch ($this->channelName) { |
||
24 | case 'slack': |
||
25 | // Set the data for Slack Broadcasts |
||
26 | if (!empty($config['webhook'])) { |
||
27 | $notifiable->setSlackWebhook($config['webhook']); |
||
|
|||
28 | } |
||
29 | break; |
||
30 | |||
31 | case 'pusher': |
||
32 | // Set data for pusher broadcasts |
||
33 | if (!empty($config['channel_name'])) { |
||
34 | $notifiable->setPusherChannel($config['channel_name']); |
||
35 | } |
||
36 | break; |
||
37 | } |
||
38 | } |
||
39 | |||
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: