Passed
Push — master ( 30deca...3a280d )
by Alexander
25:00 queued 23:29
created

CallableDefinition::resolve()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 8
ccs 4
cts 5
cp 0.8
crap 2.032
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Factory\Definitions;
6
7
use Psr\Container\ContainerInterface;
8
use Yiisoft\Injector\Injector;
9
10
class CallableDefinition implements DefinitionInterface
11
{
12
    private $method;
13
14 2
    public function __construct(callable $method)
15
    {
16 2
        $this->method = $method;
17 2
    }
18
19 2
    public function resolve(ContainerInterface $container)
20
    {
21 2
        $callback = $this->method;
22 2
        if ($container->has(Injector::class)) {
23 2
            return $container->get(Injector::class)->invoke($callback);
24
        }
25
26
        return $callback($container);
27
    }
28
}
29