AbstractElement   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 3
cbo 1
dl 0
loc 67
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A setSubtitle() 0 6 1
A setImageUrl() 0 6 1
A toArray() 0 6 1
A jsonSerialize() 0 4 1
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 string|null
20
     */
21
    protected $subtitle;
22
23
    /**
24
     * @var string|null
25
     */
26
    protected $imageUrl;
27
28
    /**
29
     * AbstractElement constructor.
30
     *
31
     * @throws \Kerox\Messenger\Exception\MessengerException
32
     */
33 11
    public function __construct(string $title)
34
    {
35 11
        $this->isValidString($title, 80);
36
37 11
        $this->title = $title;
38 11
    }
39
40
    /**
41
     * @throws \Kerox\Messenger\Exception\MessengerException
42
     *
43
     * @return mixed
44
     */
45 11
    public function setSubtitle(string $subtitle)
46
    {
47 11
        $this->isValidString($subtitle, 80);
48
49 11
        $this->subtitle = $subtitle;
50 11
    }
51
52
    /**
53
     * @throws \Kerox\Messenger\Exception\MessengerException
54
     *
55
     * @return mixed
56
     */
57 11
    public function setImageUrl(string $imageUrl)
58
    {
59 11
        $this->isValidUrl($imageUrl);
60
61 11
        $this->imageUrl = $imageUrl;
62 11
    }
63
64 9
    public function toArray(): array
65
    {
66
        return [
67 9
            'title' => $this->title,
68
        ];
69
    }
70
71 9
    public function jsonSerialize(): array
72
    {
73 9
        return $this->toArray();
74
    }
75
}
76