Passed
Pull Request — master (#78)
by Dmitriy
07:47
created

ValueDefinition::resolve()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.1406

Importance

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