Passed
Push — master ( ca5e6e...04ea7b )
by Sergei
55:45
created

ValueDefinition   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 8
c 0
b 0
f 0
dl 0
loc 30
ccs 10
cts 10
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A resolve() 0 7 3
A getType() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Factory\Definition;
6
7
use Psr\Container\ContainerInterface;
8
use Yiisoft\Factory\FactoryInterface;
9
10
use function is_object;
11
12
class ValueDefinition implements DefinitionInterface
13
{
14
    /**
15
     * @var mixed
16
     */
17
    private $value;
18
19
    private ?string $type;
20
21
    /**
22
     * @param mixed $value
23
     */
24 17
    public function __construct($value, string $type = null)
25
    {
26 17
        $this->value = $value;
27 17
        $this->type = $type;
28 17
    }
29
30 1
    public function getType(): ?string
31
    {
32 1
        return $this->type;
33
    }
34
35 15
    public function resolve(ContainerInterface $container)
36
    {
37 15
        if ($container instanceof FactoryInterface && is_object($this->value)) {
38 4
            return clone $this->value;
39
        }
40
41 11
        return $this->value;
42
    }
43
}
44