Completed
Pull Request — master (#3)
by Romain
01:47
created

GenericElement   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 85
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setSubtitle() 0 6 1
A setImageUrl() 0 6 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 string $subtitle
29
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\GenericElement
30
     */
31
    public function setSubtitle(string $subtitle): GenericElement
32
    {
33
        parent::setSubtitle($subtitle);
34
35
        return $this;
36
    }
37
38
    /**
39
     * @param string $imageUrl
40
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\GenericElement
41
     */
42
    public function setImageUrl(string $imageUrl): GenericElement
43
    {
44
        parent::setImageUrl($imageUrl);
45
46
        return $this;
47
    }
48
49
    /**
50
     * @param mixed $itemUrl
51
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\GenericElement
52
     */
53
    public function setItemUrl(string $itemUrl): GenericElement
54
    {
55
        $this->isValidUrl($itemUrl);
56
        $this->itemUrl = $itemUrl;
57
58
        return $this;
59
    }
60
61
    /**
62
     * @param \Kerox\Messenger\Model\Common\Buttons\AbstractButtons[] $buttons
63
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\GenericElement
64
     */
65
    public function setButtons(array $buttons): GenericElement
66
    {
67
        $this->isValidArray($buttons, 3);
68
        $this->buttons = $buttons;
69
70
        return $this;
71
    }
72
73
    /**
74
     * @return array
75
     */
76
    public function jsonSerialize(): array
77
    {
78
        $json = parent::jsonSerialize();
79
        $json += [
80
            'item_url' => $this->itemUrl,
81
            'image_url' => $this->imageUrl,
82
            'subtitle' => $this->subtitle,
83
            'buttons' => $this->buttons,
84
        ];
85
86
        return array_filter($json);
87
    }
88
}
89