SmsChannel::send()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 6
rs 10
1
<?php
2
3
namespace HoomanMirghasemi\Sms\Channels;
4
5
use Exception;
6
use HoomanMirghasemi\Sms\Abstracts\Driver;
7
use HoomanMirghasemi\Sms\SmsManager;
8
use Illuminate\Notifications\Notification;
9
10
class SmsChannel
11
{
12
    /**
13
     * Send notification.
14
     *
15
     * @param              $notifiable
16
     * @param Notification $notification
17
     *
18
     * @throws Exception
19
     *
20
     * @return void
21
     */
22
    public function send($notifiable, Notification $notification): void
23
    {
24
        $manager = $notification->toSms($notifiable);
0 ignored issues
show
Bug introduced by
The method toSms() does not exist on Illuminate\Notifications\Notification. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        /** @scrutinizer ignore-call */ 
25
        $manager = $notification->toSms($notifiable);

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...
25
        if (!is_null($manager)) {
26
            $this->validate($manager);
27
            $manager->send();
0 ignored issues
show
Bug introduced by
The method send() does not exist on HoomanMirghasemi\Sms\SmsManager. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
            $manager->/** @scrutinizer ignore-call */ 
28
                      send();
Loading history...
28
        }
29
    }
30
31
    /**
32
     * Validate sms.
33
     *
34
     * @throws Exception
35
     *
36
     * @return void
37
     */
38
    protected function validate($manager): void
39
    {
40
        if (!$manager instanceof SmsManager && !$manager instanceof Driver) {
41
            throw new Exception('Invalid data for sms notification.');
42
        }
43
    }
44
}
45