Completed
Pull Request — master (#47)
by Romain
02:37
created

OpenGraphElement::getAllowedButtonsType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Kerox\Messenger\Model\Message\Attachment\Template\Element;
4
5
use Kerox\Messenger\Helper\ValidatorTrait;
6
use Kerox\Messenger\Model\Common\Buttons\AbstractButtons;
7
8
class OpenGraphElement implements \JsonSerializable
9
{
10
11
    use ValidatorTrait;
12
13
    /**
14
     * @var string
15
     */
16
    protected $url;
17
18
    /**
19
     * @var \Kerox\Messenger\Model\Common\Buttons\AbstractButtons[]
20
     */
21
    protected $buttons = [];
22
23
    /**
24
     * OpenGraphElement constructor.
25
     *
26
     * @param string $url
27
     */
28 2
    public function __construct(string $url)
29
    {
30 2
        $this->isValidUrl($url);
31
32 2
        $this->url = $url;
33 2
    }
34
35
    /**
36
     * @param \Kerox\Messenger\Model\Common\Buttons\AbstractButtons[] $buttons
37
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\OpenGraphElement
38
     */
39 2
    public function setButtons(array $buttons): OpenGraphElement
40
    {
41 2
        $this->isValidArray($buttons, 1);
42 2
        $this->isValidButtons($buttons, $this->getAllowedButtonsType());
43
44 1
        $this->buttons = $buttons;
45
46 1
        return $this;
47
    }
48
49
    /**
50
     * @return array
51
     */
52 2
    protected function getAllowedButtonsType(): array
53
    {
54
        return [
55 2
            AbstractButtons::TYPE_WEB_URL,
56
        ];
57
    }
58
59
    /**
60
     * @return array
61
     */
62 1
    public function jsonSerialize(): array
63
    {
64
        $json = [
65 1
            'url' => $this->url,
66 1
            'buttons' => $this->buttons,
67
        ];
68
69 1
        return array_filter($json);
70
    }
71
}
72