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

ParameterDefinition   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

6 Methods

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