Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/Capability/Registry/ReferenceHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,28 @@ private function prepareArguments(\ReflectionFunctionAbstract $reflection, array
$finalArgs = [];

foreach ($reflection->getParameters() as $parameter) {
// TODO: Handle variadic parameters.
$paramName = $parameter->getName();
$paramPosition = $parameter->getPosition();

// Handle variadic parameters
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is clear with the next line of code already and we can remove this comment

Suggested change
// Handle variadic parameters

if ($parameter->isVariadic()) {
// For variadic parameters, collect all remaining arguments
$variadicArgs = [];
foreach ($arguments as $key => $value) {
if (is_numeric($key) && $key >= $paramPosition) {
Comment on lines +95 to +96
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this reads like array_slice could be of help 👍

try {
$variadicArgs[] = $this->castArgumentType($value, $parameter);
} catch (InvalidArgumentException $e) {
throw RegistryException::invalidParams($e->getMessage(), $e);
} catch (\Throwable $e) {
throw RegistryException::internalError("Error processing variadic parameter `{$paramName}`: {$e->getMessage()}", $e);
}
Comment on lines +97 to +103
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is basically the same like in line 112-118 - does it make sense to shift the throw RegistryException into the castArgumentType method instead and skip the try-catch in both cases?

or somehow merge this block into lower if-else part as well?

}
}
$finalArgs[$paramPosition] = $variadicArgs;
continue;
}

if (isset($arguments[$paramName])) {
$argument = $arguments[$paramName];
try {
Expand Down