Completed
Pull Request — master (#4)
by Abdullah
02:53
created

ZendeskChannel::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace NotificationChannels\Zendesk;
4
5
use Zendesk\API\HttpClient;
6
use Illuminate\Notifications\Notification;
7
use NotificationChannels\Zendesk\Exceptions\CouldNotSendNotification;
8
9
class ZendeskChannel
10
{
11
    /** @var HttpClient */
12
    protected $client;
13
14
    /** @param HttpClient $client */
15 2
    public function __construct(HttpClient $client)
16
    {
17 2
        $this->client = $client;
18 2
    }
19
20
    /**
21
     * Send the given notification.
22
     *
23
     * @param mixed $notifiable
24
     * @param \Illuminate\Notifications\Notification $notification
25
     *
26
     * @throws \NotificationChannels\Zendesk\Exceptions\InvalidConfiguration
27
     * @throws \NotificationChannels\Zendesk\Exceptions\CouldNotSendNotification
28
     */
29 2
    public function send($notifiable, Notification $notification)
30
    {
31 2
        $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...
32
33
        try {
34 2
            $response = $this->client->tickets()->create($zendeskParameters);
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
35
        } catch (\Zendesk\API\Exceptions\ApiResponseException $e) {
36
            throw CouldNotSendNotification::serviceRespondedWithAnError($e->getMessage());
37
        }
38 2
    }
39
}
40