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 ( 5e9a17...b42b77 )
by Artem
02:36
created

PushSubscriberManager::processMessage()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 30
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 18
nc 2
nop 1
1
<?php
2
3
namespace Ozean12\GooglePubSubBundle\Service\Subscriber;
4
5
use Ozean12\GooglePubSubBundle\DTO\PushMessageRequestDTO;
6
use Ozean12\GooglePubSubBundle\Service\LoggerTrait;
7
8
/**
9
 * Class PushSubscriberManager
10
 */
11
class PushSubscriberManager
12
{
13
    use LoggerTrait;
14
15
    /**
16
     * @var string
17
     */
18
    private $projectId;
19
20
    /**
21
     * @var PushSubscriberInterface[]
22
     */
23
    private $subscribers;
24
25
    /**
26
     * PushSubscriberManager constructor.
27
     *
28
     * @param string $projectId
29
     */
30
    public function __construct($projectId)
31
    {
32
        $this->projectId = $projectId;
33
    }
34
35
    /**
36
     * @param PushMessageRequestDTO $messageRequest
37
     * @return bool
38
     */
39
    public function processMessage(PushMessageRequestDTO $messageRequest)
40
    {
41
        $subscription = str_replace(
42
            sprintf('projects/%s/subscriptions/', $this->projectId),
43
            '',
44
            $messageRequest->getSubscription()
45
        );
46
47
        $message = $messageRequest->getMessage();
48
49
        if (isset($this->subscribers[$subscription])) {
50
            $subscriber = $this->subscribers[$subscription];
51
            $subscriber->process($message);
52
53
            $this->logInfo('Received message : {subscription}[{message}]; Processed with {subscriberClass} subscriber', [
54
                'message' => $message->getMessageId(),
55
                'subscription' => $subscription,
56
                'subscriberClass' => get_class($subscriber),
57
            ]);
58
59
            return true;
60
        }
61
62
        $this->logInfo('Received message : {subscription}[{message}]; Subscriber not found', [
63
            'message' => $message->getMessageId(),
64
            'subscription' => $subscription,
65
        ]);
66
67
        return false;
68
    }
69
70
    /**
71
     * @param string                  $subscriptionName
72
     * @param PushSubscriberInterface $subscriber
73
     */
74
    public function addSubscriber($subscriptionName, PushSubscriberInterface $subscriber)
75
    {
76
        $this->subscribers[$subscriptionName] = $subscriber;
77
    }
78
}
79