TypeHintParameterResolver   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 10
c 3
b 1
f 0
dl 0
loc 30
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A resolve() 0 9 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Habemus\Autowiring\Parameter;
5
6
use Habemus\Autowiring\Reflector;
7
use Psr\Container\ContainerInterface;
8
use ReflectionParameter;
9
10
class TypeHintParameterResolver implements ParameterResolver
11
{
12
    /**
13
     * @var ContainerInterface
14
     */
15
    protected $container;
16
17
    /**
18
     * @var Reflector
19
     */
20
    protected $reflector;
21
22
    public function __construct(ContainerInterface $container, Reflector $reflector)
23
    {
24
        $this->container = $container;
25
        $this->reflector = $reflector;
26
    }
27
28
    /**
29
     * @inheritDoc
30
     */
31
    public function resolve(ReflectionParameter $parameter, array $arguments, array &$result): bool
32
    {
33
        $typeHint = $this->reflector->getTypeHint($parameter, false);
34
        if (!is_string($typeHint) || !$this->container->has($typeHint)) {
35
            return false;
36
        }
37
38
        $value = $this->container->get($typeHint);
39
        return (new VariadicParameterResolver($value))->resolve($parameter, $arguments, $result);
40
    }
41
}
42