Passed
Push — master ( 3633ed...8de50e )
by Alexander
21:09 queued 19:43
created

ValueDefinition::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
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
class ValueDefinition implements DefinitionInterface
11
{
12
    /**
13
     * @var mixed $value
14
     */
15
    private $value;
16
17
    private ?string $type;
18
19
    /**
20
     * @param mixed $value
21
     * @param string $type
22
     */
23 31
    public function __construct($value, string $type = null)
24
    {
25 31
        $this->value = $value;
26 31
        $this->type = $type;
27 31
    }
28
29
    public function getType(): ?string
30
    {
31
        return $this->type;
32
    }
33
34 39
    public function resolve(ContainerInterface $container)
35
    {
36 39
        if ($container instanceof FactoryInterface && is_object($this->value)) {
37 2
            return clone $this->value;
38
        }
39
40 38
        return $this->value;
41
    }
42
}
43