Completed
Pull Request — master (#3)
by Abdullah
02:43 queued 51s
created

ZendeskChannel   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 41
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
B send() 0 20 5
1
<?php
2
3
namespace NotificationChannels\Zendesk;
4
5
use Zendesk\API\Client;
6
use Illuminate\Support\Arr;
7
use Illuminate\Notifications\Notification;
8
use NotificationChannels\Zendesk\Exceptions\CouldNotSendNotification;
9
10
class ZendeskChannel
11
{
12
    /** @var Client */
13
    protected $client;
14
15
    /** @param Client $client */
16 3
    public function __construct(Client $client)
17
    {
18 3
        $this->client = $client;
19 3
    }
20
21
    /**
22
     * Send the given notification.
23
     *
24
     * @param mixed $notifiable
25
     * @param \Illuminate\Notifications\Notification $notification
26
     *
27
     * @throws \NotificationChannels\Zendesk\Exceptions\InvalidConfiguration
28
     * @throws \NotificationChannels\Zendesk\Exceptions\CouldNotSendNotification
29
     */
30 3
    public function send($notifiable, Notification $notification)
31
    {
32 3
        $zendeskParameters = $notification->toZendesk($notifiable)->toArray();
1 ignored issue
show
Bug introduced by
The method toZendesk() 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...
33
34 3
        if (!isset($zendeskParameters['requester']['name']) || $zendeskParameters['requester']['name'] ==='') {
35 1
            $routing = collect($notifiable->routeNotificationFor('Zendesk'));
36 1
            if (! Arr::has($routing, ['name', 'email'])) {
37
                return;
38
            }
39
40 1
            $zendeskParameters['requester']['name'] = $routing['name'];
41 1
            $zendeskParameters['requester']['email'] = $routing['email'];
42
        }
43
44 3
        $response = $this->client->tickets()->create($zendeskParameters);
45
46 3
        if ($response->getStatusCode() !== 200) {
47 1
            throw CouldNotSendNotification::serviceRespondedWithAnError($response);
48
        }
49 2
    }
50
}
51