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

Header::getText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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