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 ( fd1b65...2c3c0a )
by Alexander
02:20
created

Response::processResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
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\NotificationService\MPNS;
11
12
use Zbox\UnifiedPush\NotificationService\ResponseInterface;
13
use Zbox\UnifiedPush\Message\RecipientDevice;
14
use Zbox\UnifiedPush\Exception\InvalidRecipientException;
15
use Zbox\UnifiedPush\Exception\DispatchMessageException;
16
use Zbox\UnifiedPush\Exception\MalformedNotificationException;
17
use Zbox\UnifiedPush\Exception\RuntimeException;
18
19
/**
20
 * Class Response
21
 * @package Zbox\UnifiedPush\NotificationService\MPNS
22
 */
23
class Response implements ResponseInterface
24
{
25
    const REQUEST_HAS_SUCCEED_CODE       = 200;
26
    const MALFORMED_NOTIFICATION_CODE    = 400;
27
    const AUTHENTICATION_ERROR_CODE      = 401;
28
    const INVALID_RECIPIENT_ERROR_CODE   = 404;
29
    const INVALID_METHOD_ERROR_CODE      = 405;
30
    const QUOTA_EXCEEDED_ERROR_CODE      = 406;
31
    const DEVICE_INACTIVE_ERROR_CODE     = 412;
32
    const SERVER_UNAVAILABLE_ERROR_CODE  = 503;
33
34
    /**
35
     * @var \Buzz\Message\Response
36
     */
37
    protected $response;
38
39
    /**
40
     * @var \ArrayIterator
41
     */
42
    protected $recipients;
43
44
    /**
45
     * @param \Buzz\Message\Response $response
46
     * @param \ArrayIterator $recipients
47
     */
48
    public function __construct(\Buzz\Message\Response $response, \ArrayIterator $recipients)
49
    {
50
        $this->response     = $response;
51
        $this->recipients   = $recipients;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function processResponse()
58
    {
59
        $statusCode = $this->response->getStatusCode();
60
        $this->checkResponseCode($statusCode, $this->recipients);
61
    }
62
63
    /**
64
     * Checks if response has succeed code or request was rejected
65
     *
66
     * @param int $responseCode
67
     * @param \ArrayIterator $recipients
68
     * @throws \Zbox\UnifiedPush\Exception\MalformedNotificationException
69
     * @throws \Zbox\UnifiedPush\Exception\DispatchMessageException
70
     * @throws \Zbox\UnifiedPush\Exception\RuntimeException
71
     */
72
    private function checkResponseCode($responseCode, \ArrayIterator $recipients)
73
    {
74
        switch ($responseCode) {
75
            case self::REQUEST_HAS_SUCCEED_CODE:
76
                break;
77
78
            case self::MALFORMED_NOTIFICATION_CODE:
79
                throw new MalformedNotificationException(
80
                    "Notification request with a bad XML document or malformed notification URI"
81
                );
82
83
            case self::AUTHENTICATION_ERROR_CODE:
84
                throw new DispatchMessageException(
85
                    "Sending this notification is unauthorized"
86
                );
87
88
            case self::INVALID_RECIPIENT_ERROR_CODE:
89
                $recipients->current()->setIdentifierStatus(RecipientDevice::DEVICE_NOT_REGISTERED);
90
91
                throw new InvalidRecipientException(
92
                    "The subscription is invalid and is not present on the Push Notification Service",
93
                    $recipients
94
                );
95
96
            case self::INVALID_METHOD_ERROR_CODE:
97
                throw new DispatchMessageException(
98
                    "Invalid method. Only POST is allowed when sending a notification request"
99
                );
100
101
            case self::QUOTA_EXCEEDED_ERROR_CODE:
102
                throw new DispatchMessageException(
103
                    "Unauthenticated service has reached the per-day throttling limit or there are many notifications per second"
104
                );
105
106
            case self::DEVICE_INACTIVE_ERROR_CODE:
107
                throw new DispatchMessageException(
108
                    "The device is in a disconnected state"
109
                );
110
111
            case self::SERVER_UNAVAILABLE_ERROR_CODE:
112
                throw new DispatchMessageException(
113
                    "The Push Notification Service is unable to process the request"
114
                );
115
116
            default:
117
                throw new RuntimeException(
118
                    "Unknown error occurred while sending notification."
119
                );
120
        }
121
    }
122
}
123