@@ -2369,7 +2369,7 @@ function parseFunctionLike(
2369
2369
function parseProperty (
2370
2370
Name $ class ,
2371
2371
int $ flags ,
2372
- Stmt \PropertyProperty $ property ,
2372
+ Stmt \PropertyProperty | Node \ Param $ property ,
2373
2373
?Node $ type ,
2374
2374
?DocComment $ comment ,
2375
2375
PrettyPrinterAbstract $ prettyPrinter
@@ -2404,13 +2404,23 @@ function parseProperty(
2404
2404
}
2405
2405
}
2406
2406
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
+
2407
2417
return new PropertyInfo (
2408
- new PropertyName ($ class , $ property -> name -> __toString () ),
2418
+ new PropertyName ($ class , ( string ) $ name ),
2409
2419
$ flags ,
2410
2420
$ propertyType ,
2411
2421
$ phpDocType ? Type::fromString ($ phpDocType ) : null ,
2412
- $ property -> default ,
2413
- $ property -> default ? $ prettyPrinter ->prettyPrintExpr ($ property -> default ) : null ,
2422
+ $ default ,
2423
+ $ default ? $ prettyPrinter ->prettyPrintExpr ($ default ) : null ,
2414
2424
$ isDocReadonly
2415
2425
);
2416
2426
}
@@ -2594,6 +2604,20 @@ function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstrac
2594
2604
$ classStmt ,
2595
2605
$ cond
2596
2606
);
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
+ }
2597
2621
} else if ($ classStmt instanceof Stmt \EnumCase) {
2598
2622
$ enumCaseInfos [] = new EnumCaseInfo (
2599
2623
$ classStmt ->name ->toString (), $ classStmt ->expr );
0 commit comments