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

GenericElement   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 63
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setItemUrl() 0 7 1
A setButtons() 0 7 1
A jsonSerialize() 0 12 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