Passed
Pull Request — master (#53)
by
unknown
01:19
created

TextBlock   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 57
rs 10
c 1
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setText() 0 5 1
A getText() 0 3 1
A toArray() 0 13 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Nexylan packages.
7
 *
8
 * (c) Nexylan SAS <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Nexy\Slack;
15
16
/**
17
 * @author Sullivan Senechal <[email protected]>
18
 * @author Mikey McLellan <[email protected]>
19
 */
20
class TextBlock extends Block
21
{
22
    const PLAIN_TEXT = 'plain_text';
23
    const MARKDOWN = 'mrkdwn';
24
25
    /**
26
     * @var string
27
     */
28
    protected $text;
29
30
    /** @var boolean */
31
    protected $emoji = false;
32
33
    /** @var bool */
34
    protected $verbatim = false;
35
36
    public function __construct($type = self::MARKDOWN)
37
    {
38
        parent::__construct($type);
39
    }
40
41
    /**
42
     * @param string $text
43
     */
44
    public function setText(string $text): self
45
    {
46
        $this->text = $text;
47
48
        return $this;
49
    }
50
51
    /**
52
     * @return string
53
     */
54
    public function getText(): string
55
    {
56
        return $this->text;
57
    }
58
59
    /**
60
     * Convert this block to its array representation.
61
     *
62
     * @return array
63
     */
64
    public function toArray(): array
65
    {
66
        $data = [
67
            'text' => $this->text,
68
            'type' => $this->type];
69
70
        if ($this->type === self::MARKDOWN) {
71
            $data['verbatim'] = $this->verbatim;
72
        }
73
        if ($this->type === self::PLAIN_TEXT) {
74
            $data['emoji'] = $this->emoji;
75
        }
76
        return $data;
77
    }
78
}
79