Skip to content

Commit 7eb80d7

Browse files
committed
[BUGFIX] Mitigate "Using null as an array offset is deprecated"
Using `DocBlockFactory->create()` with a phpdocblock hanging a `@throws` tag followed by a exception class name emits following PHP 8.5.0 deprecation: ``` Using null as an array offset is deprecated, use an empty string instead ``` in `StandardTagFactory->getArgumentsForParametersFromWiring()`. This change uses the null-coalsce operator to fallback to an empty string for the value which should be used as an array key instead of using `null` to mitigate the deprecation notice with PHP8.5.0 and matches the behaviour in earlier PHP versions without the deprecation message.
1 parent 90a04bc commit 7eb80d7

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/DocBlock/StandardTagFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ private function getArgumentsForParametersFromWiring(array $parameters, array $l
282282
}
283283

284284
$parameterName = $parameter->getName();
285-
if (isset($locator[$typeHint])) {
286-
$arguments[$parameterName] = $locator[$typeHint];
285+
if (isset($locator[$typeHint ?? ''])) {
286+
$arguments[$parameterName] = $locator[$typeHint ?? ''];
287287
continue;
288288
}
289289

@@ -292,7 +292,7 @@ private function getArgumentsForParametersFromWiring(array $parameters, array $l
292292
continue;
293293
}
294294

295-
$arguments[$parameterName] = null;
295+
$arguments[$parameterName ?? ''] = null;
296296
}
297297

298298
return $arguments;

tests/unit/DocBlock/StandardTagFactoryTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,11 @@ public function validTagProvider(): array
525525
'tag',
526526
'@tag (is valid)',
527527
],
528+
'full-qualified-class-name following a tag name is valid' => [
529+
'@tag \InvalidArgumentException',
530+
'tag',
531+
'@tag \InvalidArgumentException',
532+
],
528533
];
529534
}
530535

0 commit comments

Comments
 (0)