Skip to content

Commit

Permalink
Extractor: supports promoted parameters [Closes #103]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Mar 10, 2022
1 parent e4e32ef commit 23110dd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/PhpGenerator/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,10 @@ private function setupFunction(GlobalFunction|Method $function, Node\FunctionLik
$function->setReturnReference($node->returnsByRef());
$function->setReturnType($node->getReturnType() ? $this->toPhp($node->getReturnType()) : null);
foreach ($node->getParams() as $item) {
$param = $function->addParameter($item->var->name);
$visibility = $this->toVisibility($item->flags);
$param = $visibility
? ($function->addPromotedParameter($item->var->name))->setVisibility($visibility)
: $function->addParameter($item->var->name);
$param->setType($item->type ? $this->toPhp($item->type) : null);
$param->setReference($item->byRef);
$function->setVariadic($item->variadic);
Expand Down
7 changes: 5 additions & 2 deletions tests/PhpGenerator/expected/Extractor.classes.80.expect
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ namespace Abc;

class Class8
{
public function __construct($a, int|string $b = 10, $c = null)
{
public function __construct(
public $a,
private int|string $b = 10,
$c = null,
) {
}
}

Expand Down

0 comments on commit 23110dd

Please sign in to comment.