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

OpenGraph::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Kerox\Messenger\Model\Message\Attachment\Template;
4
5
use Kerox\Messenger\Model\Message\Attachment\Template;
6
7
class OpenGraph extends Template
8
{
9
10
    /**
11
     * @var \Kerox\Messenger\Model\Message\Attachment\Template\Element\OpenGraphElement[]
12
     */
13
    protected $elements = [];
14
15
    /**
16
     * OpenGraph constructor.
17
     *
18
     * @param \Kerox\Messenger\Model\Message\Attachment\Template\Element\OpenGraphElement[] $elements
19
     */
20 1
    public function __construct(array $elements)
21
    {
22 1
        parent::__construct();
23
24 1
        $this->isValidArray($elements, 1);
25
26 1
        $this->elements = $elements;
27 1
    }
28
29
    /**
30
     * @return array
31
     */
32 1
    public function jsonSerialize(): array
33
    {
34 1
        $json = parent::jsonSerialize();
35
        $json += [
36
            'payload' => [
37 1
                'template_type' => Template::TYPE_OPEN_GRAPH,
38 1
                'elements' => $this->elements,
39
            ],
40
        ];
41
42 1
        return $this->arrayFilter($json);
43
    }
44
}
45