SmsRuChannel::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kafkiansky\SmsRuChannel;
6
7
use Illuminate\Notifications\Notification;
8
use Kafkiansky\SmsRu\Message\SmsRuMessage;
9
use Kafkiansky\SmsRu\Message\To;
10
use Kafkiansky\SmsRu\SmsRuApi;
11
12
final class SmsRuChannel
13
{
14
    /**
15
     * @var SmsRuApi
16
     */
17
    private $api;
18
19
    public function __construct(SmsRuApi $api)
20
    {
21
        $this->api = $api;
22
    }
23
24
    public function send($notifiable, Notification $notification)
25
    {
26
        $message = $notification->toSmsRu($notifiable);
0 ignored issues
show
Bug introduced by
The method toSmsRu() does not seem to exist on object<Illuminate\Notifications\Notification>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
27
28
        if ($message instanceof SmsRuMessage) {
29
            return $this->api->send($message);
30
        }
31
32
        if (! ($to = $notifiable->routeNotificationFor('SmsRu', $notification))) {
33
            return null;
34
        }
35
36
        if (\is_string($message)) {
37
            return $this->api->send(new SmsRuMessage(new To($to, $message)));
38
        }
39
40
        return null;
41
    }
42
}
43