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

GCM   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 56
rs 10

3 Methods

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