MailLiftChannel   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 94.44%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 49
ccs 17
cts 18
cp 0.9444
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 24 5
1
<?php
2
3
namespace NotificationChannels\MailLift;
4
5
use GuzzleHttp\Client;
6
use Illuminate\Support\Arr;
7
use NotificationChannels\MailLift\Exceptions\CouldNotSendNotification;
8
use Illuminate\Notifications\Notification;
9
use NotificationChannels\MailLift\Exceptions\InvalidConfiguration;
10
11
class MailLiftChannel
12
{
13
    const API_ENDPOINT = 'https://api.maillift.com/2016-04-21/letter/';
14
15
    /** @var Client */
16
    protected $client;
17
18
    /**
19
     * @param Client $client
20
     */
21 3
    public function __construct(Client $client)
22
    {
23 3
        $this->client = $client;
24 3
    }
25
26
    /**
27
     * Send the given notification.
28
     *
29
     * @param mixed $notifiable
30
     * @param \Illuminate\Notifications\Notification $notification
31
     *
32
     * @throws \NotificationChannels\MailLift\Exceptions\InvalidConfiguration
33
     * @throws \NotificationChannels\MailLift\Exceptions\CouldNotSendNotification
34
     */
35 3
    public function send($notifiable, Notification $notification)
36
    {
37 3
        if (! $routing = $notifiable->routeNotificationFor('MailLift')) {
38
            return;
39
        }
40
41 3
        $user = config('services.maillift.user');
42 3
        $key = config('services.maillift.key');
43
44 3
        if (is_null($key) || is_null($user)) {
45 1
            throw InvalidConfiguration::configurationNotSet();
46
        }
47
48 2
        $mailliftParameters = $notification->toMailLift($notifiable)->toArray();
0 ignored issues
show
Bug introduced by
The method toMailLift() 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...
49
50 2
        $response = $this->client->post(self::API_ENDPOINT, [
51 2
            'auth' => [$user, $key],
52 2
            'form_params' => Arr::set($mailliftParameters, 'Recipient', $routing),
53 2
        ]);
54
55 2
        if ($response->getStatusCode() !== 200) {
56 1
            throw CouldNotSendNotification::serviceRespondedWithAnError($response);
57
        }
58 1
    }
59
}
60