NetgsmChannel::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace TarfinLabs\Netgsm;
4
5
use Exception;
6
use GuzzleHttp\Exception\GuzzleException;
7
use Illuminate\Notifications\Notification;
8
use TarfinLabs\Netgsm\Exceptions\IncorrectPhoneNumberFormatException;
9
use TarfinLabs\Netgsm\Sms\AbstractNetgsmMessage;
10
11
class NetgsmChannel
12
{
13
    protected $netgsm;
14
15
    public function __construct(Netgsm $netgsm)
16
    {
17
        $this->netgsm = $netgsm;
18
    }
19
20
    /**
21
     * Send the given notification.
22
     *
23
     * @param              $notifiable
24
     * @param Notification $notification
25
     * @throws Exceptions\CouldNotSendNotification
26
     * @throws GuzzleException
27
     * @throws IncorrectPhoneNumberFormatException
28
     * @throws Exception
29
     */
30
    public function send($notifiable, Notification $notification)
31
    {
32
        $message = $notification->toNetgsm($notifiable);
0 ignored issues
show
Bug introduced by
The method toNetgsm() 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

32
        /** @scrutinizer ignore-call */ 
33
        $message = $notification->toNetgsm($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...
33
34
        if (! $message instanceof AbstractNetgsmMessage) {
35
            throw new Exception(trans('netgsm::errors.invalid_netgsm_message'));
0 ignored issues
show
Bug introduced by
It seems like trans('netgsm::errors.invalid_netgsm_message') can also be of type array and array; however, parameter $message of Exception::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

35
            throw new Exception(/** @scrutinizer ignore-type */ trans('netgsm::errors.invalid_netgsm_message'));
Loading history...
36
        }
37
38
        if (! $message->getRecipients()) {
39
            $phone = $notifiable->routeNotificationFor('Netgsm');
40
            $message->setRecipients($phone);
41
        }
42
43
        $this->netgsm->sendSms($message);
44
    }
45
}
46