Passed
Push — main ( 2054fe...0c6c03 )
by Breno
02:23
created

UserDefinedParameterResolver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 5

1 Method

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