Passed
Push — master ( ca5e6e...04ea7b )
by Sergei
55:45
created

ParameterDefinition::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 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
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 ReflectionParameter;
9
use Yiisoft\Factory\FactoryInterface;
10
11
use function is_object;
12
13
class ParameterDefinition implements DefinitionInterface
14
{
15
    private ReflectionParameter $parameter;
16
    private bool $hasValue = false;
17
18
    /**
19
     * @var mixed
20
     */
21
    private $value = null;
22
23 8
    public function __construct(ReflectionParameter $parameter)
24
    {
25 8
        $this->parameter = $parameter;
26 8
    }
27
28
    /**
29
     * @param mixed $value
30
     */
31 7
    public function setValue($value): void
32
    {
33 7
        $this->hasValue = true;
34 7
        $this->value = $value;
35 7
    }
36
37 37
    public function getParameter(): ReflectionParameter
38
    {
39 37
        return $this->parameter;
40
    }
41
42 32
    public function hasValue(): bool
43
    {
44 32
        return $this->hasValue;
45
    }
46
47 30
    public function resolve(ContainerInterface $container)
48
    {
49 30
        if ($container instanceof FactoryInterface && is_object($this->value)) {
50 1
            return clone $this->value;
51
        }
52
53 29
        return $this->value;
54
    }
55
}
56