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 ( 6c5ffd...9c9abb )
by Alexander
02:23
created

APNS::packPayload()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
rs 9.4285
cc 1
eloc 13
nc 1
nop 1
1
<?php
2
3
/*
4
 * (c) Alexander Zhukov <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Zbox\UnifiedPush\Message\Type;
11
12
use Zbox\UnifiedPush\Message\MessageBase;
13
use Zbox\UnifiedPush\NotificationService\NotificationServices;
14
use Zbox\UnifiedPush\Exception\InvalidArgumentException;
15
16
/**
17
 * Class APNS
18
 * @package Zbox\UnifiedPush\Message\Type
19
 */
20
class APNS extends MessageBase
21
{
22
    /**
23
     * APNs does not support multicast sending
24
     */
25
    const MAX_RECIPIENTS_PER_MESSAGE_COUNT = 1;
26
27
    /**
28
     * The message’s priority. Provide one of the following values:
29
     * - 10 The push message is sent immediately
30
     * - 5 The push message is sent at a time that conserves power on the device receiving it
31
     *
32
     * @var integer
33
     */
34
    protected $priority;
35
36
    /**
37
     * Message text of an alert
38
     *
39
     * @var string
40
     */
41
    private $alert;
42
43
    /**
44
     * The number to display as the badge of the application icon
45
     *
46
     * @var integer
47
     */
48
    private $badge;
49
50
    /**
51
     * The name of a sound file in the application bundle
52
     *
53
     * @var string
54
     */
55
    private $sound;
56
57
    /**
58
     * Category option for custom notification actions (iOS 8+)
59
     *
60
     * @var string
61
     */
62
    private $category;
63
64
    /**
65
     * Provide this key with a value of 1 to indicate that new content is available
66
     *
67
     * @var bool
68
     */
69
    private $contentAvailable;
70
71
    /**
72
     * Custom properties
73
     *
74
     * @var array
75
     */
76
    private $customPayloadData = array();
77
78
    /**
79
     * Gets message type
80
     *
81
     * @return string
82
     */
83
    public function getMessageType()
84
    {
85
        return NotificationServices::APPLE_PUSH_NOTIFICATIONS_SERVICE;
86
    }
87
88
    /**
89
     * @return string
90
     */
91
    public function getAlert()
92
    {
93
        return $this->alert;
94
    }
95
96
    /**
97
     * @param string $alert
98
     * @return $this
99
     */
100
    public function setAlert($alert)
101
    {
102
        if (!is_scalar($alert)) {
103
            $this->invalidArgumentException('Alert', 'a string');
104
        }
105
        $this->alert = $alert;
106
107
        return $this;
108
    }
109
110
    /**
111
     * @return int
112
     */
113
    public function getBadge()
114
    {
115
        return $this->badge;
116
    }
117
118
    /**
119
     * @param int $badge
120
     * @return $this
121
     */
122
    public function setBadge($badge)
123
    {
124
        if (!is_int($badge)) {
125
            $this->invalidArgumentException('Badge', 'an integer');
126
        }
127
128
        $this->badge = $badge;
129
130
        return $this;
131
    }
132
133
    /**
134
     * @return array
135
     */
136
    public function getCustomPayloadData()
137
    {
138
        return $this->customPayloadData;
139
    }
140
141
    /**
142
     * @param array $customPayloadData
143
     */
144
    public function setCustomPayloadData($customPayloadData)
145
    {
146
        $this->customPayloadData = $customPayloadData;
147
    }
148
149
    /**
150
     * @return boolean
151
     */
152
    public function isContentAvailable()
153
    {
154
        return $this->contentAvailable;
155
    }
156
157
    /**
158
     * @param boolean $contentAvailable
159
     * @return $this
160
     */
161
    public function setContentAvailable($contentAvailable)
162
    {
163
        if (!is_bool($contentAvailable)) {
164
            $this->invalidArgumentException('ContentAvailable', 'a boolean');
165
        }
166
167
        $this->contentAvailable = $contentAvailable;
168
169
        return $this;
170
    }
171
172
    /**
173
     * @return int
174
     */
175
    public function getPriority()
176
    {
177
        return $this->priority;
178
    }
179
180
    /**
181
     * @param int $priority
182
     */
183
    public function setPriority($priority)
184
    {
185
        $this->priority = $priority;
186
    }
187
188
    /**
189
     * @return string
190
     */
191
    public function getSound()
192
    {
193
        return $this->sound;
194
    }
195
196
    /**
197
     * @param string $sound
198
     * @return $this
199
     */
200
    public function setSound($sound)
201
    {
202
        if (!is_scalar($sound)) {
203
            $this->invalidArgumentException('Sound', 'an string');
204
        }
205
        $this->sound = $sound;
206
207
        return $this;
208
    }
209
210
    /**
211
     * @return string
212
     */
213
    public function getCategory()
214
    {
215
        return $this->category;
216
    }
217
218
    /**
219
     * @param string $category
220
     * @return $this
221
     */
222
    public function setCategory($category)
223
    {
224
        if (!is_scalar($category)) {
225
            $this->invalidArgumentException('Category', 'an string');
226
        }
227
        $this->category = $category;
228
229
        return $this;
230
    }
231
232
    /**
233
     * {@inheritdoc}
234
     */
235
    public function validateRecipient($token)
236
    {
237
        if (!ctype_xdigit($token)) {
238
            throw new InvalidArgumentException(sprintf(
239
                'Device token must be a hexadecimal digit. Token given: "%s"',
240
                $token
241
            ));
242
        }
243
244
        if (strlen($token) != 64) {
245
            throw new InvalidArgumentException(sprintf(
246
                'Device token must be a 64 charsets, Token length given: %d.',
247
                mb_strlen($token)
248
            ));
249
        }
250
        return true;
251
    }
252
}
253