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.

GCM   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 67
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isSupported() 0 4 1
A createPayload() 0 22 2
A packPayload() 0 4 1
A checkIfDryRun() 0 8 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\PayloadHandler;
11
12
use Zbox\UnifiedPush\Message\MessageInterface;
13
use Zbox\UnifiedPush\Notification\PayloadHandler;
14
use Zbox\UnifiedPush\Message\Type\GCM as GCMMessage;
15
use Zbox\UnifiedPush\Utils\JsonEncoder;
16
17
/**
18
 * Class GCM
19
 * @package Zbox\UnifiedPush\Notification\PayloadHandler
20
 */
21
class GCM extends PayloadHandler
22
{
23
    /**
24
     * The maximum size allowed for an Android notification payload is 4096 bytes
25
     */
26
    const PAYLOAD_MAX_LENGTH = 4096;
27
28
    /**
29
     * @param MessageInterface $message
30
     * @return bool
31
     */
32
    public function isSupported(MessageInterface $message)
33
    {
34
        return $message instanceof GCMMessage;
35
    }
36
37
    /**
38
     * @return array
39
     */
40
    public function createPayload()
41
    {
42
        $registrationIds = array();
43
44
        /** @var GCMMessage $message */
45
        $message = $this->message;
46
47
        foreach ($message->getRecipientDeviceCollection() as $recipient) {
48
            $registrationIds[] = $recipient->getIdentifier();
49
        }
50
51
        $payload =
52
            array(
53
                'collapse_key'      => $message->getCollapseKey(),
54
                'delay_while_idle'  => $message->isDelayWhileIdle(),
55
                'registration_ids'  => $registrationIds,
56
                'data'              => $message->getPayloadData(),
57
                'time_to_live'      => $message->getExpirationTime()->format('U') - time()
58
            );
59
60
        return $this->checkIfDryRun($message, $payload);
61
    }
62
63
    /**
64
     * Pack message body into a json representation
65
     *
66
     * @param array $payload
67
     * @return string
68
     */
69
    public function packPayload($payload)
70
    {
71
        return JsonEncoder::jsonEncode($payload);
72
    }
73
74
    /**
75
     * @param GCMMessage $message
76
     * @param array $payload
77
     * @return array
78
     */
79
    protected function checkIfDryRun(GCMMessage $message, $payload)
80
    {
81
        if ($message->isDryRun()) {
82
            $payload['dry_run'] = $message->isDryRun();
83
        }
84
85
        return $payload;
86
    }
87
}
88