Test Failed
Pull Request — master (#39)
by Aleksandr
09:31
created

DeclarationsRegistry   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getBindingsByExchange() 0 4 3
A addQueue() 0 3 1
A addBinding() 0 3 1
A addExchange() 0 6 2
1
<?php
2
3
namespace OldSound\RabbitMqBundle\Declarations;
4
5
class DeclarationsRegistry
6
{
7
    /** @var ExchangeDeclaration[] */
8
    public $exchanges;
9
    /** @var QueueDeclaration[] */
10
    public $queues;
11
    /** @var BindingDeclaration[] */
12
    public $bindings = [];
13
    
14
    public function addExchange(ExchangeDeclaration $exchangeDeclaration)
15
    {
16
        if (isset($this->exchanges[$exchangeDeclaration->name])) {
17
            throw new \InvalidArgumentException(sprintf('Exchange declartion with %s name already registerd', $exchangeDeclaration->name));
18
        }
19
        $this->exchanges[$exchangeDeclaration->name] = $exchangeDeclaration;
20
    }
21
    
22
    public function addQueue(QueueDeclaration $queueDeclaration)
23
    {
24
        $this->queues[] = $queueDeclaration;    
25
    }
26
27
    public function addBinding(BindingDeclaration $bindingDeclaration)
28
    {
29
        $this->bindings[] = $bindingDeclaration;
30
    }
31
32
    /**
33
     * @param ExchangeDeclaration $exchange
34
     * @return BindingDeclaration[]
35
     */
36
    public function getBindingsByExchange(ExchangeDeclaration $exchange): array
37
    {
38
        return array_filter($this->bindings, function ($binding) use ($exchange) {
39
            return $binding->exchange === $exchange->name || ($binding->destinationIsExchange && $binding->destination === $exchange->name);
40
        });
41
    }
42
}