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 ( fc45f0...dd0edf )
by Baptiste
02:38
created

AutoDeclare   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 84
ccs 43
cts 43
cp 1
rs 10
c 0
b 0
f 0
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A declareThrough() 0 19 2
A close() 0 4 1
A closed() 0 3 1
B __construct() 0 29 4
A channel() 0 6 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\AMQP\Client;
5
6
use Innmind\AMQP\{
7
    Client,
8
    Model\Exchange\Declaration as Exchange,
9
    Model\Queue\Declaration as Queue,
10
    Model\Queue\Binding,
11
};
12
use Innmind\Immutable\{
13
    SetInterface,
14
    Set,
15
};
16
17
final class AutoDeclare implements Client
18
{
19
    private $client;
20
    private $exchanges;
21
    private $queues;
22
    private $bindings;
23
    private $declared = false;
24
25
    /**
26
     * @param SetInterface<Exchange>|null $exchanges
27
     * @param SetInterface<Queue>|null $queues
28
     * @param SetInterface<Binding>|null $bindings
29
     */
30 8
    public function __construct(
31
        Client $client,
32
        SetInterface $exchanges = null,
33
        SetInterface $queues = null,
34
        SetInterface $bindings = null
35
    ) {
36 8
        $this->client = $client;
37 8
        $this->exchanges = $exchanges ?? Set::of(Exchange::class);
38 8
        $this->queues = $queues ?? Set::of(Queue::class);
39 8
        $this->bindings = $bindings ?? Set::of(Binding::class);
40
41 8
        if ((string) $this->exchanges->type() !== Exchange::class) {
42 1
            throw new \TypeError(sprintf(
43 1
                'Argument 2 must be of type SetInterface<%s>',
44 1
                Exchange::class
45
            ));
46
        }
47
48 7
        if ((string) $this->queues->type() !== Queue::class) {
49 1
            throw new \TypeError(sprintf(
50 1
                'Argument 3 must be of type SetInterface<%s>',
51 1
                Queue::class
52
            ));
53
        }
54
55 6
        if ((string) $this->bindings->type() !== Binding::class) {
56 1
            throw new \TypeError(sprintf(
57 1
                'Argument 4 must be of type SetInterface<%s>',
58 1
                Binding::class
59
            ));
60
        }
61 5
    }
62
63 2
    public function channel(): Channel
64
    {
65 2
        $channel = $this->client->channel();
66 2
        $this->declareThrough($channel);
67
68 2
        return $channel;
69
    }
70
71 1
    public function closed(): bool
72
    {
73 1
        return $this->client->closed();
74
    }
75
76 1
    public function close(): void
77
    {
78 1
        $this->client->close();
79 1
        $this->declared = true;
80 1
    }
81
82 2
    private function declareThrough(Channel $channel): void
83
    {
84 2
        if ($this->declared) {
85 2
            return;
86
        }
87
88 1
        $exchange = $channel->exchange();
89 1
        $queue = $channel->queue();
90
91 1
        $this->exchanges->foreach(static function(Exchange $command) use ($exchange): void {
92 1
            $exchange->declare($command);
93 1
        });
94 1
        $this->queues->foreach(static function(Queue $command) use ($queue): void {
95 1
            $queue->declare($command);
96 1
        });
97 1
        $this->bindings->foreach(static function(Binding $command) use ($queue): void {
98 1
            $queue->bind($command);
99 1
        });
100 1
        $this->declared = true;
101 1
    }
102
}
103