GenericElement::setButtons()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 8
loc 8
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Model\Message\Attachment\Template\Element;
6
7
use Kerox\Messenger\Model\Common\Button\WebUrl;
8
9 View Code Duplication
class GenericElement extends AbstractElement
0 ignored issues
show
Duplication introduced by
This class 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...
10
{
11
    /**
12
     * @var \Kerox\Messenger\Model\Common\Button\WebUrl
13
     */
14
    protected $defaultAction;
15
16
    /**
17
     * @var \Kerox\Messenger\Model\Common\Button\AbstractButton[]|null
18
     */
19
    protected $buttons = [];
20
21
    /**
22
     * @throws \Kerox\Messenger\Exception\MessengerException
23
     *
24
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\GenericElement
25
     */
26 3
    public static function create(string $title): self
27
    {
28 3
        return new self($title);
29
    }
30
31
    /**
32
     * @throws \Kerox\Messenger\Exception\MessengerException
33
     *
34
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\GenericElement
35
     */
36 3
    public function setSubtitle(string $subtitle): self
37
    {
38 3
        parent::setSubtitle($subtitle);
39
40 3
        return $this;
41
    }
42
43
    /**
44
     * @throws \Kerox\Messenger\Exception\MessengerException
45
     *
46
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\GenericElement
47
     */
48 3
    public function setImageUrl(string $imageUrl): self
49
    {
50 3
        parent::setImageUrl($imageUrl);
51
52 3
        return $this;
53
    }
54
55
    /**
56
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\GenericElement
57
     */
58 3
    public function setDefaultAction(WebUrl $defaultAction): self
59
    {
60 3
        $this->defaultAction = $defaultAction;
61
62 3
        return $this;
63
    }
64
65
    /**
66
     * @param \Kerox\Messenger\Model\Common\Button\AbstractButton[] $buttons
67
     *
68
     * @throws \Kerox\Messenger\Exception\MessengerException
69
     *
70
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\GenericElement
71
     */
72 3
    public function setButtons(array $buttons): self
73
    {
74 3
        $this->isValidArray($buttons, 3);
75
76 3
        $this->buttons = $buttons;
77
78 3
        return $this;
79
    }
80
81 3
    public function toArray(): array
82
    {
83 3
        $array = parent::toArray();
84
        $array += [
85 3
            'subtitle' => $this->subtitle,
86 3
            'image_url' => $this->imageUrl,
87 3
            'default_action' => $this->defaultAction,
88 3
            'buttons' => $this->buttons,
89
        ];
90
91 3
        return array_filter($array);
92
    }
93
}
94