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

ValueDefinition   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 70%

Importance

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

3 Methods

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