Completed
Push — master ( 4700f8...b32d7e )
by Tomasz
02:09
created

RootElementProviderUtility   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 27
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 8 2
A __construct() 0 13 4
1
<?php
2
namespace Thunder\Serializard\Utility;
3
4
final class RootElementProviderUtility
5
{
6
    private $aliases;
7
8 13
    public function __construct(array $aliases)
9
    {
10 13
        foreach($aliases as $key => $alias) {
11 10
            if(false === is_string($key)) {
12 1
                throw new \InvalidArgumentException('Invalid alias class name, string required!');
13
            }
14 9
            if(false === is_string($alias)) {
15 1
                throw new \InvalidArgumentException(sprintf('Invalid alias for class %s, string required!', $key));
16
            }
17 11
        }
18
19 11
        $this->aliases = $aliases;
20 11
    }
21
22 3
    public function __invoke($class)
23
    {
24 3
        if(false === array_key_exists($class, $this->aliases)) {
25 1
            throw new \RuntimeException(sprintf('No root element alias for class %s!', $class));
26
        }
27
28 2
        return $this->aliases[$class];
29
    }
30
}
31