Test Failed
Pull Request — master (#129)
by Sergei
06:59
created

ParameterDefinition::isOptional()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

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