OpenGraphTemplate::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 1
crap 1
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