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 ( c42bc4...743bf3 )
by Alexander
02:32
created

PayloadHandler::validatePayload()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 2
eloc 9
nc 2
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\Notification;
11
12
use Zbox\UnifiedPush\Message\MessageInterface;
13
use Zbox\UnifiedPush\Exception\InvalidArgumentException;
14
use Zbox\UnifiedPush\Exception\MalformedNotificationException;
15
16
/**
17
 * Class PayloadHandler
18
 * @package Zbox\UnifiedPush\Notification
19
 */
20
abstract class PayloadHandler implements PayloadHandlerInterface
21
{
22
    /**
23
     * @var MessageInterface
24
     */
25
    protected $message;
26
27
    /**
28
     * @var int
29
     */
30
    protected $notificationId;
31
32
    /**
33
     * @param MessageInterface $message
34
     * @return bool
35
     */
36
    abstract public function isSupported(MessageInterface $message);
37
38
    /**
39
     * @param MessageInterface $message
40
     * @return $this
41
     */
42
    public function setMessage(MessageInterface $message)
43
    {
44
        if (!$this->isSupported($message)) {
45
            throw new InvalidArgumentException('Message type is not supported');
46
        }
47
48
        $this->message = $message;
49
50
        return $this;
51
    }
52
53
    /**
54
     * @param int $id
55
     * @return $this
56
     */
57
    public function setNotificationId($id)
58
    {
59
        $this->notificationId = $id;
60
        return $this;
61
    }
62
63
    /**
64
     * Gets maximum size allowed for notification payload
65
     *
66
     * @return int
67
     */
68
    public function getPayloadMaxLength()
69
    {
70
        return static::PAYLOAD_MAX_LENGTH;
71
    }
72
73
    /**
74
     * @return array
75
     */
76
    public function getCustomNotificationData()
77
    {
78
        return array();
79
    }
80
81
    /**
82
     * Check if maximum size allowed for a notification payload exceeded
83
     *
84
     * @param string $packedPayload
85
     * @throws MalformedNotificationException
86
     */
87
    public function validatePayload($packedPayload)
88
    {
89
        $messageType = $this->message->getMessageType();
90
        $maxLength   = $this->getPayloadMaxLength();
91
92
        if (strlen($packedPayload) > $maxLength) {
93
            throw new MalformedNotificationException(
94
                sprintf(
95
                    "The maximum size allowed for '%s' notification payload is %d bytes",
96
                    $messageType,
97
                    $maxLength
98
                )
99
            );
100
        }
101
    }
102
}
103