Completed
Pull Request — master (#38)
by
unknown
03:39
created

DatePicker::setPlaceholder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
namespace Maknz\Slack\BlockElement;
3
4
use DateTime;
5
6
class DatePicker extends Confirmable
7
{
8
    /**
9
     * Block type.
10
     *
11
     * @var string
12
     */
13
    protected $type = 'datepicker';
14
15
    /**
16
     * Action triggered when the date is selected.
17
     *
18
     * @var string
19
     */
20
    protected $action_id;
21
22
    /**
23
     * Placeholder shown on the date picker.
24
     *
25
     * @var \Maknz\Slack\BlockElement\Text
26
     */
27
    protected $placeholder;
28
29
    /**
30
     * Initial date to be selected.
31
     *
32
     * @var \DateTime
33
     */
34
    protected $initial_date;
35
36
    /**
37
     * Internal attribute to property map.
38
     *
39
     * @var array
40
     */
41
    protected static $availableAttributes = [
42
        'action_id'    => 'action_id',
43
        'placeholder'  => 'placeholder',
44
        'initial_date' => 'initial_date',
45
        'confirm'      => 'confirm',
46
    ];
47
48
    /**
49
     * Get the action.
50
     *
51
     * @return string
52
     */
53 1
    public function getActionId()
54
    {
55 1
        return $this->action_id;
56
    }
57
58
    /**
59
     * Set the action.
60
     *
61
     * @param string $actionId
62
     *
63
     * @return DatePicker
64
     */
65 2
    public function setActionId($actionId)
66
    {
67 2
        $this->action_id = $actionId;
68
69 2
        return $this;
70
    }
71
72
    /**
73
     * Get the placeholder.
74
     *
75
     * @return \Maknz\Slack\BlockElement\Text
76
     */
77 2
    public function getPlaceholder()
78
    {
79 2
        return $this->placeholder;
80
    }
81
82
    /**
83
     * Set the placeholder.
84
     *
85
     * @param mixed $placeholder
86
     *
87
     * @return DatePicker
88
     *
89
     * @throws \InvalidArgumentException
90
     */
91 2
    public function setPlaceholder($placeholder)
92
    {
93 2
        $this->placeholder = Text::create($placeholder, Text::TYPE_PLAIN);
94
95 2
        return $this;
96
    }
97
98
    /**
99
     * Get the initial date.
100
     *
101
     * @return \DateTime
102
     */
103 2
    public function getInitialDate()
104
    {
105 2
        return $this->initial_date;
106
    }
107
108
    /**
109
     * Set the initial date.
110
     *
111
     * @param \DateTime $initialDate
112
     *
113
     * @return DatePicker
114
     */
115 2
    public function setInitialDate(DateTime $initialDate)
116
    {
117 2
        $this->initial_date = $initialDate;
118
119 2
        return $this;
120
    }
121
122
    /**
123
     * Convert the block to its array representation.
124
     *
125
     * @return array
126
     */
127 1
    public function toArray()
128
    {
129
        $data = [
130 1
            'type'      => $this->getType(),
131 1
            'action_id' => $this->getActionId(),
132
        ];
133
134 1
        if ($this->getPlaceholder()) {
135 1
            $data['placeholder'] = $this->getPlaceholder()->toArray();
136
        }
137
138 1
        if ($this->getInitialDate()) {
139 1
            $data['initial_date'] = $this->getInitialDate()->format('Y-m-d');
140
        }
141
142 1
        if ($this->getConfirm()) {
143 1
            $data['confirm'] = $this->getConfirm()->toArray();
144
        }
145
146 1
        return $data;
147
    }
148
}
149