OpenGraphTemplate   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 46
loc 46
rs 10
c 0
b 0
f 0
ccs 12
cts 12
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 12 12 1
A __construct() 8 8 1
A create() 4 4 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
/**
10
 * @deprecated Since version 3.2.0 and will be removed in version 4.0.0.
11
 */
12 View Code Duplication
class OpenGraphTemplate 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...
13
{
14
    /**
15
     * @var \Kerox\Messenger\Model\Message\Attachment\Template\Element\OpenGraphElement[]
16
     */
17
    protected $elements = [];
18
19
    /**
20
     * OpenGraph constructor.
21
     *
22
     * @param \Kerox\Messenger\Model\Message\Attachment\Template\Element\OpenGraphElement[] $elements
23
     *
24
     * @throws \Kerox\Messenger\Exception\MessengerException
25
     */
26 1
    public function __construct(array $elements)
27
    {
28 1
        parent::__construct();
29
30 1
        $this->isValidArray($elements, 1);
31
32 1
        $this->elements = $elements;
33 1
    }
34
35
    /**
36
     *@throws \Kerox\Messenger\Exception\MessengerException
37
     *
38
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\OpenGraphTemplate
39
     */
40 1
    public static function create(array $elements): self
41
    {
42 1
        return new self($elements);
0 ignored issues
show
Deprecated Code introduced by
The class Kerox\Messenger\Model\Me...plate\OpenGraphTemplate has been deprecated with message: Since version 3.2.0 and will be removed in version 4.0.0.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
43
    }
44
45 1
    public function toArray(): array
46
    {
47 1
        $array = parent::toArray();
48
        $array += [
49
            'payload' => [
50 1
                'template_type' => AbstractTemplate::TYPE_OPEN_GRAPH,
51 1
                'elements' => $this->elements,
52
            ],
53
        ];
54
55 1
        return $this->arrayFilter($array);
56
    }
57
}
58