Passed
Pull Request — master (#93)
by Sergei
04:47 queued 02:36
created

ValueDefinition::resolve()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 1
crap 3
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 16
    public function __construct($value, string $type = null)
25
    {
26 16
        $this->value = $value;
27 16
        $this->type = $type;
28 16
    }
29
30 1
    public function getType(): ?string
31
    {
32 1
        return $this->type;
33
    }
34
35 14
    public function resolve(ContainerInterface $container)
36
    {
37 14
        if ($container instanceof FactoryInterface && is_object($this->value)) {
38 3
            return clone $this->value;
39
        }
40
41 11
        return $this->value;
42
    }
43
}
44