Passed
Push — master ( eec14a...4028c5 )
by Alexander
02:26
created

Temporalpicker   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 74
ccs 16
cts 16
cp 1
rs 10
c 1
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getInitialValue() 0 3 1
A setInitialValue() 0 5 1
A toArray() 0 20 4
1
<?php
2
namespace Maknz\Slack\BlockElement;
3
4
use DateTime;
5
use Maknz\Slack\PlaceholderTrait;
6
7
abstract class Temporalpicker extends Confirmable
8
{
9
    use PlaceholderTrait;
10
11
    /**
12
     * Initial date to be selected.
13
     *
14
     * @var \DateTime
15
     */
16
    protected $initial_value;
17
18
    /**
19
     * Get the initial value.
20
     *
21
     * @return \DateTime
22
     */
23 6
    protected function getInitialValue()
24
    {
25 6
        return $this->initial_value;
26
    }
27
28
    /**
29
     * Set the initial value.
30
     *
31
     * @param \DateTime $initialValue
32
     *
33
     * @return $this
34
     */
35 6
    protected function setInitialValue(DateTime $initialValue)
36
    {
37 6
        $this->initial_value = $initialValue;
38
39 6
        return $this;
40
    }
41
42
    /**
43
     * Get the name of the initial value field.
44
     *
45
     * @return string
46
     */
47
    abstract protected function getInitialValueField();
48
49
    /**
50
     * Get the initial value format.
51
     *
52
     * @return string
53
     */
54
    abstract protected function getInitialValueFormat();
55
56
    /**
57
     * Convert the block to its array representation.
58
     *
59
     * @return array
60
     */
61 2
    public function toArray()
62
    {
63 2
        $data = [
64 2
            'type'      => $this->getType(),
65 2
            'action_id' => $this->getActionId(),
66
        ];
67
68 2
        if ($this->getPlaceholder()) {
69 2
            $data['placeholder'] = $this->getPlaceholder()->toArray();
70
        }
71
72 2
        if ($this->getInitialValue()) {
73 2
            $data[$this->getInitialValueField()] = $this->getInitialValue()->format($this->getInitialValueFormat());
74
        }
75
76 2
        if ($this->getConfirm()) {
77 2
            $data['confirm'] = $this->getConfirm()->toArray();
78
        }
79
80 2
        return $data;
81
    }
82
}
83