Skip to content

Commit 06467b9

Browse files
committed
build/gen_stub.php: generate prop decls for ctor promoted props
1 parent ee85fc3 commit 06467b9

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

build/gen_stub.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,7 +2369,7 @@ function parseFunctionLike(
23692369
function parseProperty(
23702370
Name $class,
23712371
int $flags,
2372-
Stmt\PropertyProperty $property,
2372+
Stmt\PropertyProperty|Node\Param $property,
23732373
?Node $type,
23742374
?DocComment $comment,
23752375
PrettyPrinterAbstract $prettyPrinter
@@ -2404,13 +2404,23 @@ function parseProperty(
24042404
}
24052405
}
24062406

2407+
$default = $property->default;
2408+
if ($property instanceof Node\Param) {
2409+
$name = $property->var->name;
2410+
if ($property->flags & Stmt\Class_::MODIFIER_READONLY) {
2411+
$default = null;
2412+
}
2413+
} else {
2414+
$name = $property->name;
2415+
}
2416+
24072417
return new PropertyInfo(
2408-
new PropertyName($class, $property->name->__toString()),
2418+
new PropertyName($class, (string) $name),
24092419
$flags,
24102420
$propertyType,
24112421
$phpDocType ? Type::fromString($phpDocType) : null,
2412-
$property->default,
2413-
$property->default ? $prettyPrinter->prettyPrintExpr($property->default) : null,
2422+
$default,
2423+
$default ? $prettyPrinter->prettyPrintExpr($default) : null,
24142424
$isDocReadonly
24152425
);
24162426
}
@@ -2594,6 +2604,20 @@ function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstrac
25942604
$classStmt,
25952605
$cond
25962606
);
2607+
if ($classStmt->name->toString() === "__construct") {
2608+
foreach ($classStmt->params as $param) {
2609+
if ($param->flags) {
2610+
$propertyInfos[] = parseProperty(
2611+
$className,
2612+
$param->flags,
2613+
$param,
2614+
$param->type,
2615+
$param->getDocComment(),
2616+
$prettyPrinter
2617+
);
2618+
}
2619+
}
2620+
}
25972621
} else if ($classStmt instanceof Stmt\EnumCase) {
25982622
$enumCaseInfos[] = new EnumCaseInfo(
25992623
$classStmt->name->toString(), $classStmt->expr);

0 commit comments

Comments
 (0)