Completed
Push — master ( 34c64f...1a15c2 )
by Morteza
18:10 queued 08:11
created

ChabokChannel   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 6
dl 0
loc 48
ccs 16
cts 17
cp 0.9412
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace NotificationChannels\Chabok;
4
5
use GuzzleHttp\Client;
6
use Illuminate\Support\Arr;
7
use NotificationChannels\Chabok\Exceptions\CouldNotSendNotification;
8
use Illuminate\Notifications\Notification;
9
use NotificationChannels\Chabok\Exceptions\InvalidConfiguration;
10
11
class ChabokChannel
12
{
13
    private static $API_ENDPOINT;
14
15
    /** @var Client */
16
    protected $client;
17
18
    /** @param Client $client */
19 3
    public function __construct(Client $client)
20
    {
21 3
        $this->client = $client;
22 3
        self::$API_ENDPOINT = 'https://' . config('services.chabok.app_id') . '.push.adpdigital.com/api/push/toUsers';
23 3
    }
24
25
    /**
26
     * Send the given notification.
27
     *
28
     * @param mixed $notifiable
29
     * @param \Illuminate\Notifications\Notification $notification
30
     *
31
     * @throws \NotificationChannels\Chabok\Exceptions\InvalidConfiguration
32
     * @throws \NotificationChannels\Chabok\Exceptions\CouldNotSendNotification
33
     */
34 3
    public function send($notifiable, Notification $notification)
35
    {
36 3
        $routing = collect($notifiable->routeNotificationFor('Chabok'));
37
38 3
        if ($routing->isEmpty()) {
39
            return;
40
        }
41
42 3
        $key = config('services.chabok.key');
43
        $additionalConfiguration = config('services.chabok.additional') ?? [];
44 3
45 1
        if (is_null($key)) {
46
            throw InvalidConfiguration::configurationNotSet();
47
        }
48 2
49
        $chabokParameters = $notification->toChabok($notifiable)->toArray();
50 2
        $params = array_merge(
51 2
            ['form_params' => Arr::set($chabokParameters, 'user', $routing->get('uuid'))],
52
            $additionalConfiguration,
53
        );
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected ')'
Loading history...
54 2
        $response = $this->client->post(self::$API_ENDPOINT.'?access_token='.$key, $params);
55 1
56
        if ($response->getStatusCode() !== 200) {
57 1
            throw CouldNotSendNotification::serviceRespondedWithAnError($response);
58
        }
59
    }
60
}
61