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

VariadicParameterResolver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
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

 

OSZAR »