MailLiftMessage::scheduleDelivery()   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
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace NotificationChannels\MailLift;
4
5
use DateTime;
6
7
class MailLiftMessage
8
{
9
    /** @var string */
10
    protected $body;
11
12
    /** @var string */
13
    protected $sender;
14
15
    /** @var string|null */
16
    protected $scheduledDelivery;
17
18
    /**
19
     * @param string $body
20
     *
21
     * @return static
22
     */
23 3
    public static function create($body)
24
    {
25 3
        return new static($body);
26
    }
27
28
    /**
29
     * @param string $body
30
     */
31 8
    public function __construct($body)
32
    {
33 8
        $this->body = $body;
34 8
    }
35
36
    /**
37
     * Set the letter message body.
38
     *
39
     * @param $body
40
     *
41
     * @return $this
42
     */
43 1
    public function body($body)
44
    {
45 1
        $this->body = $body;
46
47 1
        return $this;
48
    }
49
50
    /**
51
     * Set the letter message sender.
52
     *
53
     * @param $sender
54
     *
55
     * @return $this
56
     */
57 3
    public function sender($sender)
58
    {
59 3
        $this->sender = $sender;
60
61 3
        return $this;
62
    }
63
64
    /**
65
     * Set the scheduled delivery date.
66
     *
67
     * @param string|DateTime $scheduledDelivery
68
     *
69
     * @return $this
70
     */
71 2
    public function scheduleDelivery($scheduledDelivery)
72
    {
73 2
        if (! $scheduledDelivery instanceof DateTime) {
74 1
            $scheduledDelivery = new DateTime($scheduledDelivery);
75 1
        }
76
77 2
        $this->scheduledDelivery = $scheduledDelivery->format('Y-m-d');
78
79 2
        return $this;
80
    }
81
82
    /**
83
     * @return array
84
     */
85 8
    public function toArray()
86
    {
87
        return [
88 8
            'MessageBody' => $this->body,
89 8
            'Sender' => $this->sender,
90 8
            'ScheduledDelivery' => $this->scheduledDelivery,
91 8
        ];
92
    }
93
}
94