Completed
Push — master ( 3347ae...8ec7fe )
by Romain
9s
created

AbstractElement   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A setSubtitle() 0 7 1
A setImageUrl() 0 7 1
A jsonSerialize() 0 8 1
1
<?php
2
namespace Kerox\Messenger\Model\Message\Attachment\Template\Element;
3
4
use Kerox\Messenger\ValidatorTrait;
5
6
abstract class AbstractElement implements \JsonSerializable, ElementInterface
7
{
8
9
    use ValidatorTrait;
10
11
    /**
12
     * @var string
13
     */
14
    protected $title;
15
16
    /**
17
     * @var null|string
18
     */
19
    protected $subtitle;
20
21
    /**
22
     * @var null|string
23
     */
24
    protected $imageUrl;
25
26
    /**
27
     * AbstractElement constructor.
28
     *
29
     * @param string $title
30
     */
31
    public function __construct(string $title)
32
    {
33
        $this->isValidString($title, 80);
34
35
        $this->title = $title;
36
    }
37
38
    /**
39
     * @param mixed $subtitle
40
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\AbstractElement
41
     */
42
    public function setSubtitle(string $subtitle): AbstractElement
43
    {
44
        $this->isValidString($subtitle, 80);
45
        $this->subtitle = $subtitle;
46
47
        return $this;
48
    }
49
50
    /**
51
     * @param mixed $imageUrl
52
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\AbstractElement
53
     */
54
    public function setImageUrl(string $imageUrl): AbstractElement
55
    {
56
        $this->isValidUrl($imageUrl);
57
        $this->imageUrl = $imageUrl;
58
59
        return $this;
60
    }
61
62
    /**
63
     * @return array
64
     */
65
    public function jsonSerialize(): array
66
    {
67
        $json = [
68
            'title' => $this->title,
69
        ];
70
71
        return $json;
72
    }
73
}
74