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

CallableDefinition   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 17
ccs 7
cts 8
cp 0.875
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A resolve() 0 8 2
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