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
Push — master ( 53cd30...da90f7 )
by Gallice
43s
created

Element::validateElement()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 8.8571
cc 5
eloc 7
nc 4
nop 0
crap 5
1
<?php
2
3
namespace Tgallice\FBMessenger\Model\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
     * @param null|string $itemUrl
37
     * @param null|string $imageUrl
38
     * @param null|string $subtitle
39
     * @param null|Button[] $buttons
40
     */
41 10
    public function __construct($title, $itemUrl = null, $imageUrl = null, $subtitle = null, array $buttons = null)
42
    {
43 10
        $this->title = $title;
44 10
        $this->itemUrl = $itemUrl;
45 10
        $this->imageUrl = $imageUrl;
46 10
        $this->subtitle = $subtitle;
47 10
        $this->buttons = $buttons;
48
49 10
        $this->validateElement();
50 7
    }
51
52
    /**
53
     * @return string
54
     */
55 1
    public function getTitle()
56
    {
57 1
        return $this->title;
58
    }
59
60
    /**
61
     * @return null|string
62
     */
63 1
    public function getItemUrl()
64
    {
65 1
        return $this->itemUrl;
66
    }
67
68
    /**
69
     * @return null|string
70
     */
71 1
    public function getImageUrl()
72
    {
73 1
        return $this->imageUrl;
74
    }
75
76
    /**
77
     * @return null|string
78
     */
79 1
    public function getSubtitle()
80
    {
81 1
        return $this->subtitle;
82
    }
83
84
    /**
85
     * @return null|Button[]
86
     */
87 1
    public function getButtons()
88
    {
89 1
        return $this->buttons;
90
    }
91
92
    /**
93
     * @return array
94
     */
95 1
    public function jsonSerialize()
96
    {
97
        return [
98 1
            'title' => $this->title,
99 1
            'item_url' => $this->itemUrl,
100 1
            'image_url' => $this->imageUrl,
101 1
            'subtitle' => $this->subtitle,
102 1
            'buttons' => $this->buttons,
103 1
        ];
104
    }
105
106 10
    private function validateElement()
107
    {
108 10
        if (strlen($this->title) > 45) {
109 1
            throw new \InvalidArgumentException('In a generic element, the "title" field should not exceed 45 characters');
110
        }
111
112 9
        if (!empty($this->subtitle) && strlen($this->subtitle) > 80) {
113 1
            throw new \InvalidArgumentException('In a generic element, the "subtitle" field should not exceed 80 characters');
114
        }
115
116 8
        if (count($this->buttons) > 3) {
117 1
            throw new \InvalidArgumentException('A generic element can not have more than 3 buttons');
118
        }
119 7
    }
120
}
121