SmsRuChannel   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 18 4
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