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

ValueDefinition   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 31
ccs 8
cts 10
cp 0.8
rs 10
c 1
b 0
f 0
wmc 5

3 Methods

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