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.

PushSubscriberManager   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 77
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B processMessage() 0 32 2
A addSubscriber() 0 4 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
     * @var string
27
     */
28
    private $suffix;
29
30
    /**
31
     * PushSubscriberManager constructor.
32
     *
33
     * @param string $projectId
34
     * @param string $suffix
35
     */
36
    public function __construct($projectId, string $suffix = '')
37
    {
38
        $this->projectId = $projectId;
39
        $this->suffix = $suffix;
40
    }
41
42
    /**
43
     * @param PushMessageRequestDTO $messageRequest
44
     * @return bool
45
     */
46
    public function processMessage(PushMessageRequestDTO $messageRequest)
47
    {
48
        $subscription = str_replace(
49
            sprintf('projects/%s/subscriptions/', $this->projectId),
50
            '',
51
            $messageRequest->getSubscription()
52
        );
53
        // Remove suffix from subscription name
54
        $subscription = preg_replace('/^(.*)'.preg_quote($this->suffix, '/').'$/', "\\1", $subscription);
55
56
        $message = $messageRequest->getMessage();
57
58
        if (isset($this->subscribers[$subscription])) {
59
            $subscriber = $this->subscribers[$subscription];
60
            $subscriber->process($message);
61
62
            $this->logInfo('Received message : {subscription}[{message}]; Processed with {subscriberClass} subscriber', [
63
                'message' => $message->getMessageId(),
64
                'subscription' => $subscription,
65
                'subscriberClass' => get_class($subscriber),
66
            ]);
67
68
            return true;
69
        }
70
71
        $this->logInfo('Received message : {subscription}[{message}]; Subscriber not found', [
72
            'message' => $message->getMessageId(),
73
            'subscription' => $subscription,
74
        ]);
75
76
        return false;
77
    }
78
79
    /**
80
     * @param string                  $subscriptionName
81
     * @param PushSubscriberInterface $subscriber
82
     */
83
    public function addSubscriber($subscriptionName, PushSubscriberInterface $subscriber)
84
    {
85
        $this->subscribers[$subscriptionName] = $subscriber;
86
    }
87
}
88