Skip to content

Commit

Permalink
Reference: support variadic parameters
Browse files Browse the repository at this point in the history
Fixes #1484
  • Loading branch information
distantnative committed Nov 4, 2023
1 parent 86bc50d commit cfa6d7a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
19 changes: 13 additions & 6 deletions site/plugins/site/src/Reference/ReflectionPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function call(): string
}

$parameters = array_column($this->parameters(), 'export');
$parameters = empty($parameters) ? '' : implode(', ', $parameters);
$parameters = implode(', ', $parameters);
$call = $this->name() . '(' . $parameters . ')';

if ($return = $this->returnType()) {
Expand Down Expand Up @@ -206,7 +206,13 @@ function ($parameter) {
$type = (string)$doc->getType();
}

$param = trim($type . ' $' . $name);
$export = '$' . $name;

if ($parameter->isVariadic() === true) {
$export = '...' . $export;
}

$export = trim($type . ' ' . $export);
$default = null;
$optional = false;

Expand All @@ -221,16 +227,17 @@ function ($parameter) {
}

$optional = true;
$param .= ' = ' . $default;
$export .= ' = ' . $default;
}

return [
'name' => '$' . $name,
'required' => $optional === false,
'type' => Types::factory($type ?? 'mixed', $this),
'default' => $default,
'description' => (string)$doc?->getDescription(),
'export' => $param
'export' => $export,
'required' => $optional === false,
'type' => Types::factory($type ?? 'mixed', $this),
'variadic' => $parameter->isVariadic()
];
}
);
Expand Down
1 change: 1 addition & 0 deletions site/snippets/templates/reference/entry/parameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<?php foreach ($rows as $row): ?>
<tr>
<td>
<?= $row['variadic'] ? '...' : null ?>
<?= $row['name'] ?>
<?= Types::required($row['required']) ?>
</td>
Expand Down

0 comments on commit cfa6d7a

Please sign in to comment.