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

NullableParameterResolver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

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

1 Method

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