Completed
Push — master ( cc28e2...03ffd9 )
by Marcel
04:46
created

EvernoteChannel   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 89.66%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 8
c 2
b 1
f 0
lcom 1
cbo 6
dl 0
loc 61
ccs 26
cts 29
cp 0.8966
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
C send() 0 39 7
1
<?php
2
3
namespace NotificationChannels\Evernote;
4
5
use Evernote\Client;
6
use Evernote\Model\HtmlNoteContent;
7
use Evernote\Model\Note;
8
use Evernote\Model\PlainTextNoteContent;
9
use Exception;
10
use Illuminate\Support\Arr;
11
use NotificationChannels\Evernote\Exceptions\CouldNotSendNotification;
12
use Illuminate\Notifications\Notification;
13
14
class EvernoteChannel
15
{
16
    /** @var Client */
17
    protected $client;
18
19
    /**
20
     * @param Client $client
21
     */
22 2
    public function __construct(Client $client)
23
    {
24 2
        $this->client = $client;
25 2
    }
26
27
    /**
28
     * Send the given notification.
29
     *
30
     * @param mixed $notifiable
31
     * @param \Illuminate\Notifications\Notification $notification
32
     *
33
     * @throws \NotificationChannels\Evernote\Exceptions\CouldNotSendNotification
34
     */
35 2
    public function send($notifiable, Notification $notification)
36
    {
37 2
        if (! $token = $notifiable->routeNotificationFor('Evernote')) {
38
            return;
39
        }
40
41 2
        $this->client->setToken($token);
42
43 2
        $message = $notification->toEvernote($notifiable)->toArray();
0 ignored issues
show
Bug introduced by
The method toEvernote() 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...
44
45 2
        $this->client->setSandbox(Arr::get($message, 'sandbox', false));
46
47 2
        $note = new Note();
48 2
        $note->setTitle($message['title']);
49
50 2
        if (! is_null($message['content'])) {
51 2
            if (Arr::get($message, 'content.type') === EvernoteContent::TYPE_HTML) {
52
                $content = new HtmlNoteContent(Arr::get($message, 'content.content'));
53
            } else {
54 2
                $content = new PlainTextNoteContent(Arr::get($message, 'content.content'));
55
            }
56 2
            $note->setContent($content);
57 2
        }
58 2
        $note->setTagNames($message['tags']);
59
60 2
        if ($message['done'] === true) {
61 2
            $note->setAsDone();
62 2
        }
63
64 2
        if (! is_null(Arr::get($message, 'reminder'))) {
65 2
            $note->setReminder($message['reminder']);
66 2
        }
67
68
        try {
69 2
            $this->client->uploadNote($note);
70 2
        } catch (Exception $e) {
71 1
            throw CouldNotSendNotification::serviceRespondedWithAnError($e->getMessage());
72
        }
73 1
    }
74
}
75