Skip to content

Commit 8a2a88e

Browse files
committed
build/gen_stub.php: generate prop decls for ctor promoted props
1 parent f93fc83 commit 8a2a88e

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
@@ -2373,7 +2373,7 @@ function parseFunctionLike(
23732373
function parseProperty(
23742374
Name $class,
23752375
int $flags,
2376-
Stmt\PropertyProperty $property,
2376+
Stmt\PropertyProperty|Node\Param $property,
23772377
?Node $type,
23782378
?DocComment $comment,
23792379
PrettyPrinterAbstract $prettyPrinter
@@ -2411,13 +2411,23 @@ function parseProperty(
24112411
}
24122412
}
24132413

2414+
$default = $property->default;
2415+
if ($property instanceof Node\Param) {
2416+
$name = $property->var->name;
2417+
if ($property->flags & Stmt\Class_::MODIFIER_READONLY) {
2418+
$default = null;
2419+
}
2420+
} else {
2421+
$name = $property->name;
2422+
}
2423+
24142424
return new PropertyInfo(
2415-
new PropertyName($class, $property->name->__toString()),
2425+
new PropertyName($class, (string) $name),
24162426
$flags,
24172427
$propertyType,
24182428
$phpDocType ? Type::fromString($phpDocType) : null,
2419-
$property->default,
2420-
$property->default ? $prettyPrinter->prettyPrintExpr($property->default) : null,
2429+
$default,
2430+
$default ? $prettyPrinter->prettyPrintExpr($default) : null,
24212431
$isDocReadonly,
24222432
$link
24232433
);
@@ -2602,6 +2612,20 @@ function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstrac
26022612
$classStmt,
26032613
$cond
26042614
);
2615+
if ($classStmt->name->toString() === "__construct") {
2616+
foreach ($classStmt->params as $param) {
2617+
if ($param->flags) {
2618+
$propertyInfos[] = parseProperty(
2619+
$className,
2620+
$param->flags,
2621+
$param,
2622+
$param->type,
2623+
$param->getDocComment(),
2624+
$prettyPrinter
2625+
);
2626+
}
2627+
}
2628+
}
26052629
} else if ($classStmt instanceof Stmt\EnumCase) {
26062630
$enumCaseInfos[] = new EnumCaseInfo(
26072631
$classStmt->name->toString(), $classStmt->expr);

0 commit comments

Comments
 (0)