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

ProductTemplate   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 40
loc 40
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 8 8 1
A create() 4 4 1
A toArray() 12 12 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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