Completed
Push — master ( 5a2a79...584535 )
by Miloš
01:11
created

ClassResolver   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 5
cts 6
cp 0.8333
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 12 2
1
<?php
2
3
namespace Laganica\Di\Resolver;
4
5
use Laganica\Di\Definition\DefinitionInterface;
6
use Laganica\Di\Exception\NotFoundException;
7
8
/**
9
 * Class AutowireResolver
10
 *
11
 * @package Laganica\Di\Resolver
12
 */
13
class ClassResolver extends ReflectionResolver
14
{
15
    /**
16
     * @inheritDoc
17
     */
18 4
    public function resolve(DefinitionInterface $definition)
19
    {
20 4
        $class = $definition->getValue();
21
22 4
        if (class_exists($class)) {
23 4
            $params = $this->getConstructorParams($class);
0 ignored issues
show
Bug introduced by
It seems like $class defined by $definition->getValue() on line 20 can also be of type object<Closure>; however, Laganica\Di\Resolver\Ref...:getConstructorParams() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
24
25 4
            return new $class(...$params);
26
        }
27
28
        throw NotFoundException::create($class);
0 ignored issues
show
Bug introduced by
It seems like $class defined by $definition->getValue() on line 20 can also be of type object<Closure>; however, Laganica\Di\Exception\NotFoundException::create() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
29
    }
30
}
31