EvernoteMessage::reminder()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 2
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace NotificationChannels\Evernote;
4
5
use DateTime;
6
7
class EvernoteMessage
8
{
9
    /** @var string */
10
    protected $title;
11
12
    /** @var EvernoteContent */
13
    protected $content;
14
15
    /** @var array */
16
    protected $tags = [];
17
18
    /** @var bool */
19
    protected $done = false;
20
21
    /** @var bool */
22
    protected $sandbox = false;
23
24
    /** @var int|null */
25
    protected $reminder;
26
27
    /**
28
     * @param string $title
29
     *
30
     * @return static
31
     */
32 3
    public static function create($title)
33
    {
34 3
        return new static($title);
35
    }
36
37
    /**
38
     * @param string $title
39
     */
40 12
    public function __construct($title)
41
    {
42 12
        $this->title = $title;
43 12
    }
44
45
    /**
46
     * Set the ticket title.
47
     *
48
     * @param string $title
49
     *
50
     * @return $this
51
     */
52 1
    public function title($title)
53
    {
54 1
        $this->title = $title;
55
56 1
        return $this;
57
    }
58
59
    /**
60
     * Set the ticket content.
61
     *
62
     * @param EvernoteContent $content
63
     *
64
     * @return $this
65
     */
66 3
    public function content(EvernoteContent $content)
67
    {
68 3
        $this->content = $content;
69
70 3
        return $this;
71
    }
72
73
    /**
74
     * Set the ticket tags.
75
     *
76
     * @param array $tags
77
     *
78
     * @return $this
79
     */
80
    public function tags($tags)
81
    {
82
        $this->tags = $tags;
83
84
        return $this;
85
    }
86
87
    /**
88
     * Set the ticket as done.
89
     *
90
     * @return $this
91
     */
92 3
    public function done()
93
    {
94 3
        $this->done = true;
95
96 3
        return $this;
97
    }
98
99
    /**
100
     * Enable sandbox mode.
101
     *
102
     * @return $this
103
     */
104 1
    public function sandbox()
105
    {
106 1
        $this->sandbox = true;
107
108 1
        return $this;
109
    }
110
111
    /**
112
     * Set the ticket reminder date.
113
     *
114
     * @param string|DateTime $reminder
115
     *
116
     * @return $this
117
     */
118 4
    public function reminder($reminder)
119
    {
120 4
        if (! $reminder instanceof DateTime) {
121 3
            $reminder = new DateTime($reminder);
122 3
        }
123
124 4
        $this->reminder = $reminder->getTimestamp();
125
126 4
        return $this;
127
    }
128
129
    /**
130
     * @return array
131
     */
132 12
    public function toArray()
133
    {
134
        return [
135 12
            'title' => $this->title,
136 12
            'content' => $this->content ? $this->content->toArray() : null,
137 12
            'reminder' => $this->reminder,
138 12
            'sandbox' => $this->sandbox,
139 12
            'done' => $this->done,
140 12
            'tags' => $this->tags,
141 12
        ];
142
    }
143
}
144