Passed
Pull Request — master (#93)
by Sergei
04:47 queued 02:36
created

ParameterDefinition::getParameter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
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