Passed
Push — main ( 57e5ef...e75ff3 )
by Breno
02:48
created

VariadicParameterResolver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 25
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A resolve() 0 10 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Habemus\Autowiring\Parameter;
5
6
use ReflectionParameter;
7
8
class VariadicParameterResolver implements ParameterResolver
9
{
10
    /**
11
     * @var mixed
12
     */
13
    protected $value;
14
15
    public function __construct($value)
16
    {
17
        $this->value = $value;
18
    }
19
20
    /**
21
     * @inheritDoc
22
     */
23
    public function resolve(ReflectionParameter $parameter, array $arguments, array &$result): bool
24
    {
25
        if (!$parameter->isVariadic()) {
26
            $result[] = $this->value;
27
        } else {
28
            $argument = !is_array($this->value) ? [$this->value] : $this->value;
29
            $result = array_merge($result, $argument);
30
        }
31
32
        return true;
33
    }
34
}
35