Completed
Push — master ( 3661d0...5a2a79 )
by Miloš
01:12
created

AliasResolver::resolve()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.7085

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 0
loc 14
ccs 4
cts 7
cp 0.5714
crap 3.7085
rs 9.7998
c 0
b 0
f 0
1
<?php
2
3
namespace Laganica\Di\Resolver;
4
5
use InvalidArgumentException;
6
use Laganica\Di\Definition\AliasDefinition;
7
8
/**
9
 * Class AliasResolver
10
 *
11
 * @package Laganica\Di\Resolver
12
 */
13
class AliasResolver extends ReflectionResolver
14
{
15
    /**
16
     * @inheritDoc
17
     */
18 1
    public function resolve($definition)
19
    {
20 1
        if (!$definition instanceof AliasDefinition) {
21
            $definitionClass = AliasDefinition::class;
22
23
            throw new InvalidArgumentException("Argument \$definition must be $definitionClass");
24
        }
25
26 1
        if (!is_string($definition->getValue())) {
27
            throw new InvalidArgumentException('Value of $definition->getValue() must be string');
28
        }
29
30 1
        return $this->getContainer()->get($definition->getValue());
31
    }
32
}
33