AutoWiringAware   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
eloc 10
dl 0
loc 37
ccs 11
cts 11
cp 1
rs 10
c 2
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A argumentWithoutType() 0 7 2
A autoWiringArguments() 0 14 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gravatalonga\Container;
6
7
use Psr\Container\ContainerInterface;
8
use ReflectionException;
9
use ReflectionNamedType;
10
use ReflectionParameter;
11
12
abstract class AutoWiringAware implements ContainerInterface
13
{
14
    /**
15
     * @throws ContainerException
16
     * @throws ReflectionException
17
     *
18
     * @return mixed
19
     */
20 18
    protected function argumentWithoutType(ReflectionParameter $reflector)
21
    {
22 18
        if (!$reflector->isOptional()) {
23 6
            throw ContainerException::findType($reflector->getName());
24
        }
25
26 12
        return $reflector->getDefaultValue();
27
    }
28
29
    /**
30
     * @throws ContainerException
31
     * @throws ReflectionException
32
     *
33
     * @return mixed|null
34
     */
35 36
    protected function autoWiringArguments(ReflectionParameter $reflector)
36
    {
37 36
        if ($this->has($reflector->getName())) {
38 15
            return $this->get($reflector->getName());
39
        }
40
41
        /** @var ReflectionNamedType|null $type */
42 24
        $type = $reflector->getType();
43
44 24
        if (null !== $type && !$type->isBuiltin()) {
45 9
            return $this->get($type->getName());
46
        }
47
48 18
        return $this->argumentWithoutType($reflector);
49
    }
50
}
51