TypehintedClassRegistry   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 78.95%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 42
ccs 15
cts 19
cp 0.7895
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B register() 0 30 6
A find() 0 6 1
1
<?php namespace Cairns\Radiate\Registry;
2
3
use ReflectionClass;
4
5
final class TypehintedClassRegistry implements Registry
6
{
7
    private $listeners;
8
9 1
    public function register($listener)
10
    {
11 1
        $class = new ReflectionClass($listener);
12
13 1
        $methods = $class->getMethods();
14
15 1
        foreach ($methods as $method) {
16 1
            if (! $method->isPublic()) {
17
                continue;
18
            }
19
20 1
            if ($method->getNumberOfParameters() !== 1) {
21
                continue;
22
            }
23
24 1
            if ($method->getNumberOfRequiredParameters() !== 1) {
25
                continue;
26
            }
27
28 1
            $param = $method->getParameters()[0];
29
30 1
            $type = $param->getType();
31
32 1
            if ($type->isBuiltin()) {
33
                continue;
34
            }
35
36 1
            $this->listeners[(string) $type][] = $listener;
37
        }
38 1
    }
39
40 1
    public function find($event)
41
    {
42 1
        $eventClassName = get_class($event);
43
44 1
        return $this->listeners[$eventClassName];
45
    }
46
}
47