Passed
Pull Request — master (#78)
by Dmitriy
02:32
created

ParameterDefinition   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 8
eloc 14
dl 0
loc 48
ccs 15
cts 18
cp 0.8333
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setValue() 0 4 1
A getParameter() 0 3 1
A __construct() 0 4 1
A resolve() 0 7 3
A getType() 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 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 6
    public function __construct(ReflectionParameter $parameter, string $type = null)
24
    {
25 6
        $this->parameter = $parameter;
26 6
        $this->type = $type;
27 6
    }
28
29
    /**
30
     * @param mixed $value
31
     */
32 6
    public function setValue($value): void
33
    {
34 6
        $this->hasValue = true;
35 6
        $this->value = $value;
36 6
    }
37
38 32
    public function getParameter(): ReflectionParameter
39
    {
40 32
        return $this->parameter;
41
    }
42
43 28
    public function hasValue(): bool
44
    {
45 28
        return $this->hasValue;
46
    }
47
48
    public function getType(): ?string
49
    {
50
        return $this->type;
51
    }
52
53 28
    public function resolve(ContainerInterface $container)
54
    {
55 28
        if ($container instanceof FactoryInterface && is_object($this->value)) {
56
            return clone $this->value;
57
        }
58
59 28
        return $this->value;
60
    }
61
}
62