Completed
Push — master ( 3347ae...8ec7fe )
by Romain
9s
created

GenericElement::setItemUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
namespace Kerox\Messenger\Model\Message\Attachment\Template\Element;
3
4
class GenericElement extends AbstractElement
5
{
6
7
    /**
8
     * @var null|string
9
     */
10
    protected $itemUrl;
11
12
    /**
13
     * @var null|\Kerox\Messenger\Model\Common\Buttons\AbstractButtons[]
14
     */
15
    protected $buttons = [];
16
17
    /**
18
     * Element constructor.
19
     *
20
     * @param string $title
21
     */
22
    public function __construct(string $title)
23
    {
24
        parent::__construct($title);
25
    }
26
27
    /**
28
     * @param mixed $itemUrl
29
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\GenericElement
30
     */
31
    public function setItemUrl(string $itemUrl): GenericElement
32
    {
33
        $this->isValidUrl($itemUrl);
34
        $this->itemUrl = $itemUrl;
35
36
        return $this;
37
    }
38
39
    /**
40
     * @param \Kerox\Messenger\Model\Common\Buttons\AbstractButtons[] $buttons
41
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\GenericElement
42
     */
43
    public function setButtons(array $buttons): GenericElement
44
    {
45
        $this->isValidArray($buttons, 3);
46
        $this->buttons = $buttons;
47
48
        return $this;
49
    }
50
51
    /**
52
     * @return array
53
     */
54
    public function jsonSerialize(): array
55
    {
56
        $json = parent::jsonSerialize();
57
        $json += [
58
            'item_url' => $this->itemUrl,
59
            'image_url' => $this->imageUrl,
60
            'subtitle' => $this->subtitle,
61
            'buttons' => $this->buttons,
62
        ];
63
64
        return array_filter($json);
65
    }
66
}
67