Completed
Push — master ( eb575e...c103e9 )
by Romain
13s
created

AbstractElement::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 0
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Model\Message\Attachment\Template\Element;
6
7
use Kerox\Messenger\Helper\ValidatorTrait;
8
9
abstract class AbstractElement implements \JsonSerializable
10
{
11
    use ValidatorTrait;
12
13
    /**
14
     * @var string
15
     */
16
    protected $title;
17
18
    /**
19
     * @var null|string
20
     */
21
    protected $subtitle;
22
23
    /**
24
     * @var null|string
25
     */
26
    protected $imageUrl;
27
28
    /**
29
     * AbstractElement constructor.
30
     *
31 8
     * @param string $title
32
     *
33 8
     * @throws \InvalidArgumentException
34
     */
35 8
    public function __construct(string $title)
36 8
    {
37
        $this->isValidString($title, 80);
38
39
        $this->title = $title;
40
    }
41 8
42
    /**
43 8
     * @param mixed $subtitle
44
     *
45 8
     * @throws \InvalidArgumentException
46 8
     *
47
     * @return mixed
48
     */
49
    public function setSubtitle(string $subtitle)
50
    {
51 8
        $this->isValidString($subtitle, 80);
52
53 8
        $this->subtitle = $subtitle;
54
    }
55 8
56 8
    /**
57
     * @param mixed $imageUrl
58
     *
59
     * @throws \InvalidArgumentException
60
     *
61 7
     * @return mixed
62
     */
63
    public function setImageUrl(string $imageUrl)
64 7
    {
65
        $this->isValidUrl($imageUrl);
66
67 7
        $this->imageUrl = $imageUrl;
68
    }
69
70
    /**
71
     * @return array
72
     */
73
    public function toArray(): array
74
    {
75
        $array = [
76
            'title' => $this->title,
77
        ];
78
79
        return $array;
80
    }
81
82
    /**
83
     * @return array
84
     */
85
    public function jsonSerialize(): array
86
    {
87
        return $this->toArray();
88
    }
89
}
90