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 ( 71c569...6c5ffd )
by Alexander
02:31
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 2
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\Notification\Type;
11
12
use Zbox\UnifiedPush\Message\Type\APNS as APNSMessage;
13
use Zbox\UnifiedPush\Utils\JsonEncoder;
14
15
/**
16
 * Class APNS
17
 * @package Zbox\UnifiedPush\Notification\Type
18
 */
19
class APNS
20
{
21
    /**
22
     * The maximum size allowed for an iOS notification payload is 2 kilobytes
23
     * Prior to iOS 8 and in OS X, the maximum payload size is 256 bytes
24
     */
25
    const PAYLOAD_MAX_LENGTH = 2048;
26
27
    /**
28
     * @param APNSMessage $message
29
     * @return array
30
     */
31
    public function createPayload(APNSMessage $message)
32
    {
33
        $payload = array(
34
            'aps' => array(
35
                'alert' => $message->getAlert(),
36
                'badge' => $message->getBadge(),
37
                'sound' => $message->getSound(),
38
                'category' => $message->getCategory(),
39
            )
40
        );
41
42
        if ($message->isContentAvailable() === true) {
43
            $payload['aps']['content-available'] = 1;
44
        }
45
46
        return array_merge($payload, $message->getCustomPayloadData());
47
    }
48
49
    /**
50
     * Pack message body into binary string
51
     *
52
     * @param array $payload
53
     * @param APNSMessage $message
54
     * @return string
55
     */
56
    public function packPayload($payload, APNSMessage $message)
57
    {
58
        $payload = JsonEncoder::jsonEncode($payload);
59
60
        $recipientId = $message->getRecipientDevice()->getIdentifier();
61
62
        $messageRecipientId = $message->getMessageIdentifier() . '_' . $recipientId;
63
64
        $packedPayload =
65
            pack('C', 1). // Command push
66
            pack('N', $messageRecipientId).
67
            pack('N', $message->getExpirationTime()->format('U')).
68
            pack('n', 32). // Token binary length
69
            pack('H*', $recipientId);
70
        pack('n', strlen($payload));
71
72
        $packedPayload .= $payload;
73
74
        return $packedPayload;
75
    }
76
}
77