Passed
Pull Request — master (#78)
by Alexander
02:06
created

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