Completed
Pull Request — master (#9)
by
unknown
09:18
created

TrelloMessage::top()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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