TodoistChannel   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 43
ccs 12
cts 13
cp 0.9231
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 19 3
1
<?php
2
3
namespace NotificationChannels\Todoist;
4
5
use GuzzleHttp\Client;
6
use NotificationChannels\Todoist\Exceptions\CouldNotSendNotification;
7
use Illuminate\Notifications\Notification;
8
9
class TodoistChannel
10
{
11
    const API_ENDPOINT = 'https://todoist.com/API/v7/sync';
12
13
    /** @var Client */
14
    protected $client;
15
16
    /**
17
     * @param Client $client
18
     */
19 2
    public function __construct(Client $client)
20
    {
21 2
        $this->client = $client;
22 2
    }
23
24
    /**
25
     * Send the given notification.
26
     *
27
     * @param mixed $notifiable
28
     * @param \Illuminate\Notifications\Notification $notification
29
     *
30
     * @throws \NotificationChannels\Todoist\Exceptions\CouldNotSendNotification
31
     */
32 2
    public function send($notifiable, Notification $notification)
33
    {
34 2
        if (! $token = collect($notifiable->routeNotificationFor('Todoist'))) {
35
            return;
36
        }
37
38 2
        $command = $notification->toTodoist($notifiable)->toArray();
0 ignored issues
show
Bug introduced by
The method toTodoist() does not seem to exist on object<Illuminate\Notifications\Notification>.

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...
39
40 2
        $response = $this->client->post(self::API_ENDPOINT, [
41
            'form_params' => [
42 2
                'commands' => json_encode([$command]),
43 2
                'token' => $token,
44
            ],
45
        ]);
46
47 2
        if ($response->getStatusCode() !== 200) {
48 1
            throw CouldNotSendNotification::serviceRespondedWithAnError($response);
49
        }
50 1
    }
51
}
52