GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#9)
by Gallice
02:33
created

Element   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 145
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 17
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 145
ccs 43
cts 43
cp 1
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getTitle() 0 4 1
A getItemUrl() 0 4 1
A getImageUrl() 0 4 1
A getSubtitle() 0 4 1
A getButtons() 0 4 1
A setItemUrl() 0 4 1
A setImageUrl() 0 4 1
A setSubtitle() 0 8 3
A setButtons() 0 8 2
A addButton() 0 8 2
A jsonSerialize() 0 10 1
1
<?php
2
3
namespace Tgallice\FBMessenger\Model\Attachment\Template\Generic;
4
5
use Tgallice\FBMessenger\Model\Button;
6
7
class Element implements \JsonSerializable
8
{
9
    /**
10
     * @var string
11
     */
12
    private $title;
13
14
    /**
15
     * @var null|string
16
     */
17
    private $itemUrl;
18
19
    /**
20
     * @var null|string
21
     */
22
    private $imageUrl;
23
24
    /**
25
     * @var null|string
26
     */
27
    private $subtitle;
28
29
    /**
30
     * @var null|Button[]
31
     */
32
    private $buttons;
33
34
    /**
35
     * @param string $title
36
     */
37 14
    public function __construct($title)
38
    {
39 14
        if (mb_strlen($title) > 80) {
40 1
            throw new \InvalidArgumentException('In a generic element, the "title" field should not exceed 80 characters.');
41
        }
42
43 13
        $this->title = $title;
44 13
    }
45
46
    /**
47
     * @return string
48
     */
49 1
    public function getTitle()
50
    {
51 1
        return $this->title;
52
    }
53
54
    /**
55
     * @return null|string
56
     */
57 2
    public function getItemUrl()
58
    {
59 2
        return $this->itemUrl;
60
    }
61
62
    /**
63
     * @return null|string
64
     */
65 2
    public function getImageUrl()
66
    {
67 2
        return $this->imageUrl;
68
    }
69
70
    /**
71
     * @return null|string
72
     */
73 2
    public function getSubtitle()
74
    {
75 2
        return $this->subtitle;
76
    }
77
78
    /**
79
     * @return null|Button[]
80
     */
81 2
    public function getButtons()
82
    {
83 2
        return $this->buttons;
84
    }
85
86
    /**
87
     * @param null|string $itemUrl
88
     */
89 1
    public function setItemUrl($itemUrl)
90
    {
91 1
        $this->itemUrl = $itemUrl;
92 1
    }
93
94
    /**
95
     * @param null|string $imageUrl
96
     */
97 1
    public function setImageUrl($imageUrl)
98
    {
99 1
        $this->imageUrl = $imageUrl;
100 1
    }
101
102
    /**
103
     * @param null|string $subtitle
104
     */
105 2
    public function setSubtitle($subtitle)
106
    {
107 2
        if (!empty($subtitle) && mb_strlen($subtitle) > 80) {
108 1
            throw new \InvalidArgumentException('In a generic element, the "subtitle" field should not exceed 80 characters.');
109
        }
110
111 1
        $this->subtitle = $subtitle;
112 1
    }
113
114
    /**
115
     * @param Button[] $buttons
116
     */
117 2
    public function setButtons(array $buttons)
118
    {
119 2
        if (count($buttons) > 3) {
120 1
            throw new \InvalidArgumentException('A generic element can not have more than 3 buttons.');
121
        }
122
123 2
        $this->buttons = $buttons;
124 2
    }
125
126
    /**
127
     * @param Button $button
128
     */
129 2
    public function addButton(Button $button)
130
    {
131 2
        if (count($this->buttons) >= 2 ) {
132 1
            throw new \InvalidArgumentException('A generic element can not have more than 3 buttons.');
133
        }
134
135 1
        $this->buttons[] = $button;
136 1
    }
137
138
    /**
139
     * @return array
140
     */
141 1
    public function jsonSerialize()
142
    {
143
        return [
144 1
            'title' => $this->title,
145 1
            'item_url' => $this->itemUrl,
146 1
            'image_url' => $this->imageUrl,
147 1
            'subtitle' => $this->subtitle,
148 1
            'buttons' => $this->buttons,
149 1
        ];
150
    }
151
}
152