Test Failed
Pull Request — master (#47)
by
unknown
03:07
created

ExpoChannel::send()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3.0884

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 11
cts 14
cp 0.7856
rs 9.552
c 0
b 0
f 0
cc 3
nc 4
nop 2
crap 3.0884
1
<?php
2
3
namespace NotificationChannels\ExpoPushNotifications;
4
5
use ExponentPhpSDK\Expo;
6
use Illuminate\Notifications\Notification;
7
use Illuminate\Contracts\Events\Dispatcher;
8
use ExponentPhpSDK\Exceptions\ExpoException;
9
use Illuminate\Notifications\Events\NotificationFailed;
10
use NotificationChannels\ExpoPushNotifications\Exceptions\CouldNotSendNotification;
11
12
class ExpoChannel
13
{
14
    /**
15
     * @var Dispatcher
16
     */
17
    private $events;
18
19
    /**
20
     * @var Expo
21
     */
22
    public $expo;
23
24
    /**
25
     * ExpoChannel constructor.
26
     *
27
     * @param Expo $expo
28
     * @param Dispatcher $events
29
     */
30 12
    public function __construct(Expo $expo, Dispatcher $events)
31
    {
32 12
        $this->events = $events;
33 12
        $this->expo = $expo;
34 12
    }
35
36
    /**
37
     * Send the given notification.
38
     *
39
     * @param mixed $notifiable
40
     * @param \Illuminate\Notifications\Notification $notification
41
     *
42
     * @throws CouldNotSendNotification
43
     *
44
     * @return void
45
     */
46 2
    public function send($notifiable, Notification $notification)
47
    {
48 2
        $interest = $notifiable->routeNotificationFor('ExpoPushNotifications')
49 2
            ?: $this->interestName($notifiable);
50
51
        $ssl_params = [
52 2
            "CURLOPT_SSL_VERIFYHOST" => config('exponent-push-notifications.ssl.verify_host', false),
53 2
            "CURLOPT_SSL_VERIFYPEER" => config('exponent-push-notifications.ssl.verify_peer', false),
54
        ];
55
56
        try {
57 2
            $this->expo->notify(
58 2
                $interest,
59 2
                $notification->toExpoPush($notifiable)->toArray(),
60 2
                $ssl_params,
0 ignored issues
show
Documentation introduced by
$ssl_params is of type array<string,*,{"CURLOPT...T_SSL_VERIFYPEER":"*"}>, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
61 2
                true
0 ignored issues
show
Unused Code introduced by
The call to Expo::notify() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
62
            );
63 2
        } catch (ExpoException $e) {
64
            $this->events->dispatch(
65
                new NotificationFailed($notifiable, $notification, 'expo-push-notifications', $e->getMessage())
66
            );
67
        }
68
    }
69
70
    /**
71
     * Get the interest name for the notifiable.
72
     *
73
     * @param $notifiable
74
     *
75
     * @return string
76
     */
77 8
    public function interestName($notifiable)
78
    {
79 8
        $class = str_replace('\\', '.', get_class($notifiable));
80
81 8
        return $class.'.'.$notifiable->getKey();
82
    }
83
}
84