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 b1ef941 commit b9ba414
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 @@ -388,7 +388,10 @@ private function setupFunction($function, Node\FunctionLike $node): void
$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 b9ba414

Please sign in to comment.