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

UntargetedBind::addConcreteClass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 2
Bugs 1 Features 0
Metric Value
dl 0
loc 7
cc 2
eloc 4
c 2
b 1
f 0
nc 2
nop 2
ccs 6
cts 6
cp 1
crap 2
rs 9.4285
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