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 ( 74f330...e0d346 )
by Alexander
02:35
created

ResponseHandler::addMessageResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
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\NotificationService;
11
12
use Zbox\UnifiedPush\Exception\InvalidArgumentException;
13
use Zbox\UnifiedPush\NotificationService\APNS\ResponseFeedback;
14
use Zbox\UnifiedPush\Exception\InvalidRecipientException,
15
    Zbox\UnifiedPush\Exception\DispatchMessageException,
16
    Zbox\UnifiedPush\Exception\MalformedNotificationException;
17
use Psr\Log\LoggerAwareInterface,
18
    Psr\Log\LoggerInterface,
19
    Psr\Log\NullLogger;
20
21
class ResponseHandler implements LoggerAwareInterface
22
{
23
    /**
24
     * @var \SplObjectStorage
25
     */
26
    private $responseCollection;
27
28
    /**
29
     * @var \ArrayIterator
30
     */
31
    private $invalidRecipients;
32
33
    /**
34
     * @var \ArrayIterator
35
     */
36
    private $messageErrors;
37
38
    /**
39
     * @var LoggerInterface
40
     */
41
    private $logger;
42
43
    public function __construct()
44
    {
45
        $this->responseCollection = new \ArrayIterator();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \ArrayIterator() of type object<ArrayIterator> is incompatible with the declared type object<SplObjectStorage> of property $responseCollection.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
46
        $this->setLogger(new NullLogger());
47
    }
48
49
    /**
50
     * @param string $messageIdentifier
51
     * @param ResponseInterface $response
52
     * @return $this
53
     */
54
    public function addIdentifiedResponse($messageIdentifier, ResponseInterface $response)
55
    {
56
        if (empty($messageIdentifier)) {
57
            throw new InvalidArgumentException('Identifier is required');
58
        }
59
60
        $this->responseCollection->attach($response, $messageIdentifier);
61
        return $this;
62
    }
63
64
    /**
65
     * @param ResponseInterface $response
66
     * @return $this
67
     */
68
    public function addResponse(ResponseInterface $response)
69
    {
70
        $this->responseCollection->attach($response);
71
        return $this;
72
    }
73
74
    public function handleResponseCollection()
75
    {
76
        $responses = $this->responseCollection;
77
78
        $responses->rewind();
79
80
        while ($responses->valid()) {
81
            $response   = $responses->getcurrent();
0 ignored issues
show
Bug introduced by
The method getcurrent() does not exist on SplObjectStorage. Did you maybe mean current()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
82
            $messageId  = $responses->getInfo();
83
            $this->handleResponse($response, $messageId);
84
            $responses->next();
85
        }
86
    }
87
88
    /**
89
     * @param ResponseInterface $response
90
     * @param string $messageIdentifier
91
     */
92
    public function handleResponse(ResponseInterface $response, $messageIdentifier)
93
    {
94
        try {
95
            $response->processResponse();
96
97
            if ($response instanceof ResponseFeedback) {
98
                throw new InvalidRecipientException(null, $response->getRecipients());
99
            }
100
        } catch (InvalidRecipientException $e) {
101
            foreach ($e->getRecipientCollection() as $recipient) {
102
                $this->invalidRecipients->append($recipient);
103
            }
104
105
        } catch (DispatchMessageException $e) {
106
            $this->messageErrors->offsetSet($messageIdentifier, $e->getCode());
107
108
            $this->logger->warning(
109
                sprintf("Dispatch message warning with code %d  '%s'", $e->getCode(), $e->getMessage())
110
            );
111
112
        } catch (MalformedNotificationException $e) {
113
            $this->messageErrors->offsetSet($messageIdentifier, $e->getCode());
114
115
            $this->logger->error(
116
                sprintf("Malformed Notification error: %s", $e->getMessage())
117
            );
118
        }
119
    }
120
121
    /**
122
     * @return \ArrayIterator
123
     */
124
    public function getMessageErrors()
125
    {
126
        return $this->messageErrors;
127
    }
128
129
    /**
130
     * @return \ArrayIterator
131
     */
132
    public function getInvalidRecipients()
133
    {
134
        return $this->invalidRecipients;
135
    }
136
137
    /**
138
     * @param LoggerInterface $logger
139
     * @return $this
140
     */
141
    public function setLogger(LoggerInterface $logger)
142
    {
143
        $this->logger = $logger;
144
        return $this;
145
    }
146
}
147