Manager::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 3
nc 3
nop 1
1
<?php
2
/**
3
 * Created by solly [03.11.17 12:06]
4
 */
5
6
namespace insolita\cqueue;
7
8
use insolita\cqueue\Contracts\QueueInterface;
9
use insolita\cqueue\Contracts\DelayingInterface;
10
use InvalidArgumentException;
11
12
class Manager
13
{
14
    
15
    /**
16
     * @var array|QueueInterface[]|DelayingInterface[]|CircularQueue[]
17
     */
18
    private $queues = [];
19
    
20
    public function __construct($queues = [])
21
    {
22
        if (!empty($queues)) {
23
            foreach ($queues as $queue) {
24
                $this->add($queue);
25
            }
26
        }
27
    }
28
    
29
    /**
30
     * @param QueueInterface|CircularQueue $queue
31
     */
32
    public function add(QueueInterface $queue)
33
    {
34
        $this->queues[$queue->getName()] = $queue;
35
    }
36
    
37
    /**
38
     * @param string $queueName
39
     *
40
     * @throws \InvalidArgumentException
41
     */
42
    public function remove(string $queueName)
43
    {
44
        if (isset($this->queues[$queueName])) {
45
            unset($this->queues[$queueName]);
46
        } else {
47
            throw new InvalidArgumentException('Queue ' . $queueName . ' not registered');
48
        }
49
    }
50
    
51
    public function has(string $queueName): bool
52
    {
53
        return isset($this->queues[$queueName]);
54
    }
55
    
56
    /**
57
     * @param string $queueName
58
     *
59
     * @return CircularQueue|DelayingInterface|QueueInterface
60
     * @throws \InvalidArgumentException
61
     */
62
    public function queue(string $queueName)
63
    {
64
        if (isset($this->queues[$queueName])) {
65
            return $this->queues[$queueName];
66
        }
67
68
        throw new InvalidArgumentException('Queue ' . $queueName . ' not registered');
69
    }
70
}
71