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

Generic::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
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;
3
4
use Kerox\Messenger\Model\Message\Attachment\Template;
5
6
class Generic extends Template
7
{
8
9
    /**
10
     * @var \Kerox\Messenger\Model\Message\Attachment\Template\Element\GenericElement[]
11
     */
12
    protected $elements;
13
14
    /**
15
     * Generic constructor.
16
     * @param \Kerox\Messenger\Model\Message\Attachment\Template\Element\GenericElement[] $elements
17
     */
18
    public function __construct(array $elements)
19
    {
20
        parent::__construct();
21
22
        $this->isValidArray($elements, 10);
23
24
        $this->elements = $elements;
25
    }
26
27
    /**
28
     * @return array
29
     */
30
    public function jsonSerialize(): array
31
    {
32
        $payload = [
33
            'template_type' => Template::TYPE_GENERIC,
34
            'elements' => $this->elements,
35
        ];
36
37
        $json = parent::jsonSerialize();
38
        $json += [
39
            'payload' => array_filter($payload),
40
        ];
41
42
        return $json;
43
    }
44
}
45