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

NullableParameterResolver::resolve()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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