Skip to content

Commit

Permalink
Merge pull request #56 from jingu/fix-param-inject
Browse files Browse the repository at this point in the history
Support nullable param in ParamInjector
  • Loading branch information
koriym committed Apr 9, 2024
2 parents 242be73 + ae6d3f9 commit 9f79cab
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/ParamInjector.php
Expand Up @@ -37,7 +37,8 @@ public function getArgumentes(MethodInvocation $invocation): array
foreach ($parameters as $parameter) {
$pos = $parameter->getPosition();
/** @psalm-suppress MixedAssignment */
$namedArgs[$parameter->getName()] = $args[$pos] ?? $this->getInjectedParam($parameter);
$namedArgs[$parameter->getName()] = array_key_exists($pos, $args)
? $args[$pos] : $this->getInjectedParam($parameter);
}

return $namedArgs;
Expand Down
2 changes: 1 addition & 1 deletion tests/FakeParamInjectMethod.php
Expand Up @@ -12,7 +12,7 @@ public function noInject(int $a): void
{
}

public function paramInject(DateTimeInterface|null $dateTime = null): void
public function paramInject(string|null $nullableString, DateTimeInterface|null $dateTime = null): void
{
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ParamInjectorTest.php
Expand Up @@ -33,7 +33,7 @@ public function testNoInjection(): void

public function testGetArgumentes(): void
{
$namedArgs = $this->injector->getArgumentes(new ReflectiveMethodInvocation(new FakeParamInjectMethod(), 'paramInject', []));
$namedArgs = $this->injector->getArgumentes(new ReflectiveMethodInvocation(new FakeParamInjectMethod(), 'paramInject', [null]));
$this->assertInstanceOf(DateTimeImmutable::class, $namedArgs['dateTime']);
}

Expand Down

0 comments on commit 9f79cab

Please sign in to comment.