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

ParameterDefinition   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 11
c 1
b 0
f 0
dl 0
loc 41
ccs 15
cts 15
cp 1
rs 10

5 Methods

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