Skip to content

Commit b9ba414

Browse files
committed
Extractor: supports promoted parameters [Closes #103]
1 parent b1ef941 commit b9ba414

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/PhpGenerator/Extractor.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,10 @@ private function setupFunction($function, Node\FunctionLike $node): void
388388
$function->setReturnReference($node->returnsByRef());
389389
$function->setReturnType($node->getReturnType() ? $this->toPhp($node->getReturnType()) : null);
390390
foreach ($node->getParams() as $item) {
391-
$param = $function->addParameter($item->var->name);
391+
$visibility = $this->toVisibility($item->flags);
392+
$param = $visibility
393+
? ($function->addPromotedParameter($item->var->name))->setVisibility($visibility)
394+
: $function->addParameter($item->var->name);
392395
$param->setType($item->type ? $this->toPhp($item->type) : null);
393396
$param->setReference($item->byRef);
394397
$function->setVariadic($item->variadic);

tests/PhpGenerator/expected/Extractor.classes.80.expect

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ namespace Abc;
66

77
class Class8
88
{
9-
public function __construct($a, int|string $b = 10, $c = null)
10-
{
9+
public function __construct(
10+
public $a,
11+
private int|string $b = 10,
12+
$c = null,
13+
) {
1114
}
1215
}
1316

0 commit comments

Comments
 (0)