ButtonTemplate::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 11
loc 11
ccs 8
cts 8
cp 1
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Model\Message\Attachment\Template;
6
7
use Kerox\Messenger\Model\Message\Attachment\AbstractTemplate;
8
9
class ButtonTemplate extends AbstractTemplate
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $text;
15
16
    /**
17
     * @var \Kerox\Messenger\Model\Common\Button\AbstractButton[]
18
     */
19
    protected $buttons;
20
21
    /**
22
     * @var bool
23
     */
24
    protected $sharable;
25
26
    /**
27
     * Buttons constructor.
28
     *
29
     * @param \Kerox\Messenger\Model\Common\Button\AbstractButton[] $buttons
30
     */
31 1 View Code Duplication
    public function __construct(string $text, array $buttons, bool $sharable = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
    {
33 1
        parent::__construct();
34
35 1
        $this->isValidString($text, 640);
36 1
        $this->isValidArray($buttons, 3);
37
38 1
        $this->text = $text;
39 1
        $this->buttons = $buttons;
40 1
        $this->sharable = $sharable;
41 1
    }
42
43
    /**
44
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\ButtonTemplate
45
     */
46 1
    public static function create(string $text, array $buttons, bool $sharable = false): self
47
    {
48 1
        return new self($text, $buttons, $sharable);
49
    }
50
51 1
    public function toArray(): array
52
    {
53 1
        $array = parent::toArray();
54
        $array += [
55
            'payload' => [
56 1
                'template_type' => AbstractTemplate::TYPE_BUTTON,
57 1
                'text' => $this->text,
58 1
                'buttons' => $this->buttons,
59 1
                'sharable' => $this->sharable,
60
            ],
61
        ];
62
63 1
        return $this->arrayFilter($array);
64
    }
65
}
66