Passed
Push — master ( eec88a...376384 )
by Alexander
02:41
created

Header   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 69
ccs 12
cts 12
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getText() 0 3 1
A setText() 0 5 1
A toArray() 0 12 2
1
<?php
2
namespace Maknz\Slack\Block;
3
4
use Maknz\Slack\Block;
5
use Maknz\Slack\BlockElement\Text;
6
7
class Header extends Block
8
{
9
    /**
10
     * Block type.
11
     *
12
     * @var string
13
     */
14
    protected $type = 'header';
15
16
    /**
17
     * The text for the header.
18
     *
19
     * @var \Maknz\Slack\BlockElement\Text
20
     */
21
    protected $text;
22
23
    /**
24
     * Internal attribute to property map.
25
     *
26
     * @var array
27
     */
28
    protected static $availableAttributes = [
29
        'text'     => 'text',
30
        'block_id' => 'block_id',
31
    ];
32
33
    /**
34
     * Get the header text.
35
     *
36
     * @return \Maknz\Slack\BlockElement\Text
37
     */
38 3
    public function getText()
39
    {
40 3
        return $this->text;
41
    }
42
43
    /**
44
     * Set the header text.
45
     *
46
     * @param mixed $text
47
     *
48
     * @return $this
49
     *
50
     * @throws \InvalidArgumentException
51
     */
52 3
    public function setText($text)
53
    {
54 3
        $this->text = Text::create($text);
55
56 3
        return $this;
57
    }
58
59
    /**
60
     * Convert the block to its array representation.
61
     *
62
     * @return array
63
     */
64 1
    public function toArray()
65
    {
66 1
        $data = [
67 1
            'type' => $this->getType(),
68 1
            'text' => $this->getText()->toArray(),
69
        ];
70
71 1
        if ($this->getBlockId()) {
72 1
            $data['block_id'] = $this->getBlockId();
73
        }
74
75 1
        return $data;
76
    }
77
}
78