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 (#15)
by Gallice
02:50
created

Button::getData()   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 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Tgallice\FBMessenger\Model;
4
5
abstract class Button implements \JsonSerializable
6
{
7
    const TYPE_POSTBACK = 'postback';
8
    const TYPE_PHONE_NUMBER = 'phone_number';
9
    const TYPE_WEB_URL = 'web_url';
10
    const TYPE_SHARE = 'element_share';
11
    const TYPE_PAYMENT = 'payment';
12
13
    /**
14
     * @var string
15
     */
16
    private $type;
17
18
    /**
19
     * @param string $type
20
     */
21 42
    public function __construct($type)
22
    {
23 42
        $this->type = $type;
24 42
    }
25
26
    /**
27
     * @return string
28
     */
29 5
    public function getType()
30
    {
31 5
        return $this->type;
32
    }
33
34
    /**
35
     * @inheritdoc
36
     */
37 6
    public function jsonSerialize()
38
    {
39
        $json = [
40 6
            'type' => $this->type,
41 6
        ];
42
43 6
        return $json;
44
    }
45
46
    /**
47
     * @param string $title
48
     *
49
     * @throws \InvalidArgumentException
50
     */
51 31
    public static function validateTitleSize($title)
52
    {
53 31
        if (mb_strlen($title) > 20) {
54 3
            throw new \InvalidArgumentException('The button title field should not exceed 20 characters.');
55
        }
56 28
    }
57
58
    /**
59
     * @param $payload
60
     *
61
     * @throws \InvalidArgumentException
62
     */
63 7
    public static function validatePayload($payload)
64
    {
65 7
        if (mb_strlen($payload) > 1000) {
66 1
            throw new \InvalidArgumentException(sprintf(
67 1
                    'Payload should not exceed 1000 characters.', $payload)
68 1
            );
69
        }
70 6
    }
71
72
    /**
73
     * @param $phoneNumber
74
     *
75
     * @throws \InvalidArgumentException
76
     */
77 7
    public static function validatePhoneNumber($phoneNumber)
78
    {
79
        // Dummy phone number check
80 7
        if (strpos($phoneNumber, '+') !== 0) {
81 1
            throw new \InvalidArgumentException(sprintf(
82 1
                    'The phone number "%s" seem to be invalid. Please check the documentation to format the phone number.', $phoneNumber)
83 1
            );
84
        }
85 6
    }
86
}
87