Passed
Pull Request — master (#92)
by Sergei
02:35
created

ParameterDefinition::resolve()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.1406

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 3
cts 4
cp 0.75
rs 10
cc 3
nc 2
nop 1
crap 3.1406
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 7
    public function __construct(ReflectionParameter $parameter)
24
    {
25 7
        $this->parameter = $parameter;
26 7
    }
27
28
    /**
29
     * @param mixed $value
30
     */
31 6
    public function setValue($value): void
32
    {
33 6
        $this->hasValue = true;
34 6
        $this->value = $value;
35 6
    }
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 29
    public function resolve(ContainerInterface $container)
48
    {
49 29
        if ($container instanceof FactoryInterface && is_object($this->value)) {
50
            return clone $this->value;
51
        }
52
53 29
        return $this->value;
54
    }
55
}
56