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
03:41 queued 55s
created

MenuItem::getType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Tgallice\FBMessenger\Model\ThreadSetting;
4
5
class MenuItem implements \JsonSerializable
6
{
7
    const TYPE_POSTBACK = 'postback';
8
    const TYPE_WEB_URL = 'web_url';
9
10
    /**
11
     * @var string
12
     */
13
    private $title;
14
15
    /**
16
     * @var string
17
     */
18
    private $type;
19
20
    /**
21
     * Url or payload
22
     *
23
     * @var string
24
     */
25
    protected $data;
26
27
    /**
28
     * @param string $type
29
     * @param string $title
30
     * @param string $data Url or payload value
31
     */
32 14
    public function __construct($type, $title, $data)
33
    {
34 14
        $this->type = $type;
35
36 14
        $this->validateTitleSize($title);
37 13
        $this->title = $title;
38
39 13
        if ($this->type === self::TYPE_POSTBACK) {
40 5
            $this->validatePayload($data);
41 4
        }
42
43 12
        $this->data = $data;
44 12
    }
45
46
    /**
47
     * @return string
48
     */
49 1
    public function getType()
50
    {
51 1
        return $this->type;
52
    }
53
54
    /**
55
     * @return string
56
     */
57 1
    public function getTitle()
58
    {
59 1
        return $this->title;
60
    }
61
62
    /**
63
     * @return string
64
     */
65 1
    public function getData()
66
    {
67 1
        return $this->data;
68
    }
69
70
    /**
71
     * @inheritdoc
72
     */
73 2 View Code Duplication
    public function jsonSerialize()
74
    {
75
        $data = [
76 2
            'type' => $this->type,
77 2
            'title' => $this->title,
78 2
        ];
79
80 2
        if ($this->type === self::TYPE_WEB_URL) {
81 1
            $data['url'] = $this->data;
82 1
        } else {
83 1
            $data['payload'] = $this->data;
84
        }
85
86 2
        return $data;
87
    }
88
89
    /**
90
     * @param string $title
91
     *
92
     * @throws \InvalidArgumentException
93
     */
94 14
    private function validateTitleSize($title)
95
    {
96 14
        if (mb_strlen($title) > 30) {
97 1
            throw new \InvalidArgumentException('The menu item title field should not exceed 30 characters.');
98
        }
99 13
    }
100
101
    /**
102
     * @param $payload
103
     *
104
     * @throws \InvalidArgumentException
105
     */
106 5
    private function validatePayload($payload)
107
    {
108 5
        if (mb_strlen($payload) > 1000) {
109 1
            throw new \InvalidArgumentException(sprintf(
110 1
                    'Payload should not exceed 1000 characters.', $payload)
111 1
            );
112
        }
113 4
    }
114
}
115