DefaultMatcherRegistry   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 33
rs 10
wmc 5
lcom 1
cbo 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A register() 0 11 2
A toDictionary() 0 6 1
A count() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of expect package.
5
 *
6
 * (c) Noritaka Horio <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
namespace expect\registry;
12
13
use expect\Dictionary;
14
use expect\MatcherDictionary;
15
use expect\MatcherLookupTable;
16
use expect\MatcherRegistry;
17
use expect\package\MatcherClass;
18
19
final class DefaultMatcherRegistry implements MatcherRegistry
20
{
21
    use MatcherLookupTable;
22
23
    public function __construct(array $matchers = [])
24
    {
25
        $this->matchers = Dictionary::fromArray($matchers);
26
    }
27
28
    public function register(MatcherClass $matcherClass)
29
    {
30
        $name = $matcherClass->getClassName();
31
        $registerKeyName = lcfirst($name);
32
33
        if ($this->has($registerKeyName)) {
34
            throw new MatcherAlreadyRegisteredException("{$registerKeyName} is registered");
35
        }
36
37
        $this->matchers->set($registerKeyName, $matcherClass);
38
    }
39
40
    public function count()
41
    {
42
        return count($this->matchers);
43
    }
44
45
    public function toDictionary()
46
    {
47
        $matchers = $this->matchers->toArray();
48
49
        return new MatcherDictionary($matchers);
50
    }
51
}
52