TrelloChannel   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 6
dl 0
loc 45
ccs 14
cts 15
cp 0.9333
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 22 4
1
<?php
2
3
namespace NotificationChannels\Trello;
4
5
use GuzzleHttp\Client;
6
use Illuminate\Notifications\Notification;
7
use Illuminate\Support\Arr;
8
use NotificationChannels\Trello\Exceptions\CouldNotSendNotification;
9
use NotificationChannels\Trello\Exceptions\InvalidConfiguration;
10
11
class TrelloChannel
12
{
13
    const API_ENDPOINT = 'https://api.trello.com/1/cards/';
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
    }
23
24
    /**
25
     * Send the given notification.
26
     *
27
     * @param mixed $notifiable
28
     * @param \Illuminate\Notifications\Notification $notification
29
     *
30
     * @throws \NotificationChannels\Trello\Exceptions\InvalidConfiguration
31
     * @throws \NotificationChannels\Trello\Exceptions\CouldNotSendNotification
32
     */
33 3
    public function send($notifiable, Notification $notification)
34
    {
35 3
        if (! $routing = collect($notifiable->routeNotificationFor('Trello'))) {
36
            return;
37
        }
38
39 3
        $key = config('services.trello.key');
40
41 3
        if (is_null($key)) {
42 1
            throw InvalidConfiguration::configurationNotSet();
43
        }
44
45 2
        $trelloParameters = $notification->toTrello($notifiable)->toArray();
0 ignored issues
show
Bug introduced by
The method toTrello() 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...
46
47 2
        $response = $this->client->post(self::API_ENDPOINT.'?key='.$key.'&token='.$routing->get('token'), [
48 2
            'form_params' => Arr::set($trelloParameters, 'idList', $routing->get('idList')),
49
        ]);
50
51 2
        if ($response->getStatusCode() !== 200) {
52 1
            throw CouldNotSendNotification::serviceRespondedWithAnError($response);
53
        }
54 1
    }
55
}
56