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::__construct()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 16
nc 4
nop 4
dl 0
loc 29
ccs 17
cts 17
cp 1
crap 4
rs 8.5806
c 0
b 0
f 0
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