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.

AutoDeclare   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 67
ccs 31
cts 31
cp 1
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A declareThrough() 0 19 2
A close() 0 4 1
A closed() 0 3 1
A __construct() 0 14 1
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
use function Innmind\Immutable\assertSet;
17
18
final class AutoDeclare implements Client
19
{
20
    private $client;
21
    private $exchanges;
22
    private $queues;
23
    private $bindings;
24
    private $declared = false;
25
26
    /**
27
     * @param SetInterface<Exchange>|null $exchanges
28
     * @param SetInterface<Queue>|null $queues
29
     * @param SetInterface<Binding>|null $bindings
30
     */
31 16
    public function __construct(
32
        Client $client,
33
        SetInterface $exchanges = null,
34
        SetInterface $queues = null,
35
        SetInterface $bindings = null
36
    ) {
37 16
        $this->client = $client;
38 16
        $this->exchanges = $exchanges ?? Set::of(Exchange::class);
39 16
        $this->queues = $queues ?? Set::of(Queue::class);
40 16
        $this->bindings = $bindings ?? Set::of(Binding::class);
41
42 16
        assertSet(Exchange::class, $this->exchanges, 2);
43 14
        assertSet(Queue::class, $this->queues, 3);
44 12
        assertSet(Binding::class, $this->bindings, 4);
45 10
    }
46
47 4
    public function channel(): Channel
48
    {
49 4
        $channel = $this->client->channel();
50 4
        $this->declareThrough($channel);
51
52 4
        return $channel;
53
    }
54
55 2
    public function closed(): bool
56
    {
57 2
        return $this->client->closed();
58
    }
59
60 2
    public function close(): void
61
    {
62 2
        $this->client->close();
63 2
        $this->declared = true;
64 2
    }
65
66 4
    private function declareThrough(Channel $channel): void
67
    {
68 4
        if ($this->declared) {
69 4
            return;
70
        }
71
72 2
        $exchange = $channel->exchange();
73 2
        $queue = $channel->queue();
74
75
        $this->exchanges->foreach(static function(Exchange $command) use ($exchange): void {
76 2
            $exchange->declare($command);
77 2
        });
78
        $this->queues->foreach(static function(Queue $command) use ($queue): void {
79 2
            $queue->declare($command);
80 2
        });
81
        $this->bindings->foreach(static function(Binding $command) use ($queue): void {
82 2
            $queue->bind($command);
83 2
        });
84 2
        $this->declared = true;
85 2
    }
86
}
87