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

Generic   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A jsonSerialize() 0 14 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