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
created

Message::setMetadata()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.2
cc 4
eloc 4
nc 3
nop 1
crap 4
1
<?php
2
3
namespace Tgallice\FBMessenger\Model;
4
5
use Tgallice\FBMessenger\Model\Attachment\File;
6
7
class Message implements \JsonSerializable
8
{
9
    const TYPE_TEXT = 'text';
10
11
    const TYPE_ATTACHMENT = 'attachment';
12
13
    /**
14
     * @var string[Attachment
15
     */
16
    private $type;
17
18
    /**
19
     * @var string[Attachment
20
     */
21
    private $data;
22
23
    /**
24
     * @var null|QuickReply[]
25
     */
26
    private $quickReplies;
27
28
    /**
29
     * @var null|string
30
     */
31
    private $metadata;
32
33
    /**
34
     * @param string $type
0 ignored issues
show
Bug introduced by
There is no parameter named $type. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
35
     * @param string|Attachment $data
36
     */
37 18
    public function __construct($data)
38
    {
39 18
        if (is_string($data)) {
40 12
            $this->type = self::TYPE_TEXT;
41 18
        } elseif ($data instanceOf Attachment) {
42 5
            $this->type = self::TYPE_ATTACHMENT;
43 5
        } else {
44 1
            throw new \InvalidArgumentException('Invalid $data. It must be a string or an Attachment');
45
        }
46
47 17
        $this->data = $data;
48 17
    }
49
50
    /**
51
     * @return string
52
     */
53 1
    public function getType()
54
    {
55 1
        return $this->type;
56
    }
57
58
    /**
59
     * @return string|Attachment
60
     */
61 4
    public function getData()
62
    {
63 4
        return $this->data;
64
    }
65
66
    /**
67
     * @return null|QuickReply[]
68
     */
69 3
    public function getQuickReplies()
70
    {
71 3
        return $this->quickReplies;
72
    }
73
74
    /**
75
     * @return null|string
76
     */
77 2
    public function getMetadata()
78
    {
79 2
        return $this->metadata;
80
    }
81
82
    /**
83
     * @param null|QuickReply[] $quickReplies
84
     */
85 4
    public function setQuickReplies(array $quickReplies = null)
86
    {
87 4
        if (count($quickReplies) > 10) {
88 1
            throw new \InvalidArgumentException('A message can not have more than 10 quick replies.');
89
        }
90
91 3
        $this->quickReplies = empty($quickReplies) ? null : $quickReplies;
92 3
    }
93
94
    /**
95
     * @param QuickReply $quickReplies
0 ignored issues
show
Bug introduced by
There is no parameter named $quickReplies. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
96
     */
97 3
    public function addQuickReply(QuickReply $quickReply)
98
    {
99 3
        if (count($this->quickReplies) >= 10) {
100 1
            throw new \InvalidArgumentException('A message can not have more than 10 quick replies.');
101
        }
102
103 2
        if (!is_array($this->quickReplies)) {
104 1
            $this->quickReplies = [];
105 1
        }
106
107 2
        $this->quickReplies[] = $quickReply;
108 2
    }
109
110
    /**
111
     * @param null|string $metadata
112
     */
113 3
    public function setMetadata($metadata = null)
114
    {
115 3
        if ($metadata !== null && mb_strlen($metadata) > 1000) {
116 1
            throw new \InvalidArgumentException('$metadata should not exceed 1000 characters.');
117
        }
118
119 2
        $this->metadata = empty($metadata) ? null : $metadata;
120 2
    }
121
122
    /**
123
     * Check if the message contains file
124
     *
125
     * @return bool
126
     */
127 5
    public function hasFileToUpload()
128
    {
129 5
        if (!$this->data instanceof File) {
130 4
            return false;
131
        }
132
133 1
        return !$this->data->isRemoteFile();
134
    }
135
136
    /**
137
     * Return a stream of the local file attachment
138
     *
139
     * @return resource|null
140
     */
141 1
    public function getFileStream()
142
    {
143 1
        if (!$this->data instanceof File) {
144
            return null;
145
        }
146
147 1
        return $this->data->getStream();
148
    }
149
150
    /**
151
     * @return array
152
     */
153 2
    public function jsonSerialize()
154
    {
155
        return [
156 2
            $this->type => $this->data,
157 2
            'quick_replies' => $this->quickReplies,
158 2
            'metadata' => $this->metadata,
159 2
        ];
160
    }
161
}
162