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

ParameterDefinition   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

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

6 Methods

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