Completed
Push — master ( 7671f5...371846 )
by Romain
32s queued 12s
created

ProductTemplate::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Model\Message\Attachment\Template;
6
7
use Kerox\Messenger\Model\Message\Attachment\AbstractTemplate;
8
9 View Code Duplication
class ProductTemplate extends AbstractTemplate
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
    /**
12
     * @var \Kerox\Messenger\Model\Message\Attachment\Template\Element\ProductElement[]
13
     */
14
    private $elements;
15
16
    /**
17
     * @throws \Kerox\Messenger\Exception\InvalidArrayException
18
     */
19
    public function __construct(array $elements)
20
    {
21
        parent::__construct();
22
23
        $this->isValidArray($elements, 10);
24
25
        $this->elements = $elements;
26
    }
27
28
    /**
29
     * @throws \Kerox\Messenger\Exception\InvalidArrayException
30
     */
31
    public static function create(array $elements): self
32
    {
33
        return new self($elements);
34
    }
35
36
    public function toArray(): array
37
    {
38
        $array = parent::toArray();
39
        $array += [
40
            'payload' => [
41
                'template_type' => AbstractTemplate::TYPE_PRODUCT,
42
                'elements' => $this->elements,
43
            ],
44
        ];
45
46
        return $this->arrayFilter($array);
47
    }
48
}
49