|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NotificationChannels\OneSignal; |
|
4
|
|
|
|
|
5
|
|
|
use Berkayk\OneSignal\OneSignalClient; |
|
6
|
|
|
use Illuminate\Notifications\Notification; |
|
7
|
|
|
use NotificationChannels\OneSignal\Exceptions\CouldNotSendNotification; |
|
8
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
9
|
|
|
|
|
10
|
|
|
class OneSignalChannel |
|
11
|
|
|
{ |
|
12
|
|
|
/** @var OneSignalClient */ |
|
13
|
|
|
protected $oneSignal; |
|
14
|
|
|
|
|
15
|
10 |
|
public function __construct(OneSignalClient $oneSignal) |
|
16
|
|
|
{ |
|
17
|
10 |
|
$this->oneSignal = $oneSignal; |
|
18
|
10 |
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Send the given notification. |
|
22
|
|
|
* |
|
23
|
|
|
* @param mixed $notifiable |
|
24
|
|
|
* @param \Illuminate\Notifications\Notification $notification |
|
25
|
|
|
* |
|
26
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
|
27
|
|
|
* @throws \NotificationChannels\OneSignal\Exceptions\CouldNotSendNotification |
|
28
|
|
|
*/ |
|
29
|
10 |
|
public function send($notifiable, Notification $notification) |
|
30
|
|
|
{ |
|
31
|
10 |
|
if (! $userIds = $notifiable->routeNotificationFor('OneSignal', $notification)) { |
|
32
|
1 |
|
return; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** @var ResponseInterface $response */ |
|
36
|
9 |
|
$response = $this->oneSignal->sendNotificationCustom( |
|
37
|
9 |
|
$this->payload($notifiable, $notification, $userIds) |
|
38
|
|
|
); |
|
39
|
|
|
|
|
40
|
9 |
|
if ($response->getStatusCode() !== 200) { |
|
41
|
1 |
|
throw CouldNotSendNotification::serviceRespondedWithAnError($response); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
8 |
|
return $response; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param mixed $notifiable |
|
49
|
|
|
* @param \Illuminate\Notifications\Notification $notification |
|
50
|
|
|
* @param mixed $targeting |
|
|
|
|
|
|
51
|
|
|
* |
|
52
|
|
|
* @return array |
|
53
|
|
|
*/ |
|
54
|
9 |
|
protected function payload($notifiable, $notification, $userIds) |
|
55
|
|
|
{ |
|
56
|
9 |
|
return OneSignalPayloadFactory::make($notifiable, $notification, $userIds); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.