SubscriberRegistry   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 92.86%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 1
cbo 0
dl 0
loc 47
ccs 13
cts 14
cp 0.9286
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A add() 0 4 1
A all() 0 4 1
A get() 0 8 2
1
<?php
2
3
namespace Zenstruck\Queue;
4
5
/**
6
 * @author Kevin Bond <[email protected]>
7
 */
8
final class SubscriberRegistry
9
{
10
    private $subscribers = [];
11
12
    /**
13
     * @param array|Subscriber[] $subscribers
14
     */
15 5
    public function __construct(array $subscribers = [])
16
    {
17 5
        foreach ($subscribers as $name => $subscriber) {
18 5
            $this->add($name, $subscriber);
19 5
        }
20 5
    }
21
22
    /**
23
     * @param string     $name
24
     * @param Subscriber $subscriber
25
     */
26 5
    public function add($name, Subscriber $subscriber)
27
    {
28 5
        $this->subscribers[$name] = $subscriber;
29 5
    }
30
31
    /**
32
     * @return array|Subscriber[]
33
     */
34 1
    public function all()
35
    {
36 1
        return $this->subscribers;
37
    }
38
39
    /**
40
     * @param string $name
41
     *
42
     * @return Subscriber
43
     *
44
     * @throws \InvalidArgumentException
45
     */
46 4
    public function get($name)
47
    {
48 4
        if (!isset($this->subscribers[$name])) {
49
            throw new \InvalidArgumentException(sprintf('Subscriber "%s" not found.', $name));
50
        }
51
52 4
        return $this->subscribers[$name];
53
    }
54
}
55