Completed
Branch 2.x (dc1b30)
by Akihito
02:25
created

UntargetedBind   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 7
c 4
b 1
f 0
lcom 0
cbo 1
dl 0
loc 34
ccs 16
cts 16
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 7 2
A addConcreteClass() 0 7 2
A getTypeHint() 0 10 3
1
<?php
2
/**
3
 * This file is part of the Ray.Di package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace Ray\Di;
8
9
final class UntargetedBind
10
{
11 8
    public function __invoke(Container $container, \ReflectionMethod $method)
12
    {
13 8
        $parameters = $method->getParameters();
14 8
        foreach ($parameters as $parameter) {
15 8
            $this->addConcreteClass($container, $parameter);
16 8
        }
17 8
    }
18
19 8
    private function addConcreteClass(Container $container, \ReflectionParameter $parameter)
20
    {
21 8
        $class = $this->getTypeHint($parameter);
22 8
        if (class_exists($class)) {
23 2
            new Bind($container, $class);
24 2
        }
25 8
    }
26
27
    /**
28
     * @param \ReflectionParameter $parameter
29
     *
30
     * @return string
31
     */
32 8
    private function getTypeHint(\ReflectionParameter $parameter)
33
    {
34 8
        if (defined('HHVM_VERSION')) {
35
            /* @noinspection PhpUndefinedFieldInspection */
36
            return $parameter->info['type_hint']; // @codeCoverageIgnore
1 ignored issue
show
Bug introduced by
The property info does not seem to exist in ReflectionParameter.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
37
        }
38 8
        $typeHintClass = $parameter->getClass();
39
40 8
        return $typeHintClass ? $typeHintClass->name : '';
41
    }
42
}
43