Completed
Pull Request — master (#10)
by
unknown
09:57 queued 08:31
created

TrelloMessage::labels()   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 1
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
c 1
b 0
f 1
cc 1
eloc 3
nc 1
nop 1
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
    /** @var string|null */
22
    protected $labels;
23
24
    /**
25
     * @param string $name
26
     *
27
     * @return static
28
     */
29
    public static function create($name = '')
30
    {
31
        return new static($name);
32
    }
33
34
    /**
35
     * @param string $name
36
     */
37
    public function __construct($name = '')
38
    {
39
        $this->name = $name;
40
    }
41
42
    /**
43
     * Set the card name.
44
     *
45
     * @param $name
46
     *
47
     * @return $this
48
     */
49
    public function name($name)
50
    {
51
        $this->name = $name;
52
53
        return $this;
54
    }
55
56
    /**
57
     * Set the card description.
58
     *
59
     * @param $description
60
     *
61
     * @return $this
62
     */
63
    public function description($description)
64
    {
65
        $this->description = $description;
66
67
        return $this;
68
    }
69
70
    /**
71
     * Set the card position.
72
     *
73
     * @param string|int $position
74
     *
75
     * @return $this
76
     */
77
    public function position($position)
78
    {
79
        $this->position = $position;
80
81
        return $this;
82
    }
83
84
    /**
85
     * Set the card position to 'top'.
86
     *
87
     * @return $this
88
     */
89
    public function top()
90
    {
91
        $this->position = 'top';
92
93
        return $this;
94
    }
95
96
    /**
97
     * Set the card position to 'bottom'.
98
     *
99
     * @return $this
100
     */
101
    public function bottom()
102
    {
103
        $this->position = 'bottom';
104
105
        return $this;
106
    }
107
108
    /**
109
     * Set the card position due date.
110
     *
111
     * @param string|DateTime $due
112
     *
113
     * @return $this
114
     */
115
    public function due($due)
116
    {
117
        if (! $due instanceof DateTime) {
118
            $due = new DateTime($due);
119
        }
120
121
        $this->due = $due->format(DateTime::ATOM);
122
123
        return $this;
124
    }
125
126
    /**
127
     * Set the card labels.
128
     *
129
     * @param array $labels
130
     *
131
     * @return $this
132
     */
133
    public function labels($labels)
134
    {
135
        $this->labels = implode(',', $labels);
136
137
        return $this;
138
    }
139
140
    /**
141
     * @return array
142
     */
143
    public function toArray()
144
    {
145
        return [
146
            'name' => $this->name,
147
            'desc' => $this->description,
148
            'pos' => $this->position,
149
            'due' => $this->due,
150
            'labels' => $this->labels,
151
        ];
152
    }
153
}
154