@@ -576,11 +576,23 @@ public function getValue(): string {
576
576
577
577
public function getVariableName (): string {
578
578
$ value = $ this ->getValue ();
579
- if ($ value === null || strlen ($ value ) === 0 || $ value [ 0 ] !== ' $ ' ) {
580
- throw new Exception ("@ $ this ->name not followed by variable name " );
579
+ if ($ value === null || strlen ($ value ) === 0 ) {
580
+ throw new Exception ("@ $ this ->name doesn't have any value " );
581
581
}
582
582
583
- return substr ($ value , 1 );
583
+ $ matches = [];
584
+
585
+ if ($ this ->name === "param " ) {
586
+ preg_match ('/^\s*[\w\| \\\\]+\s*\$(\w+).*$/ ' , $ value , $ matches );
587
+ } elseif ($ this ->name === "prefer-ref " ) {
588
+ preg_match ('/^\s*\$(\w+).*$/ ' , $ value , $ matches );
589
+ }
590
+
591
+ if (isset ($ matches [1 ]) === false ) {
592
+ throw new Exception ("@ $ this ->name doesn't contain variable name or has an invalid format \"$ value \"" );
593
+ }
594
+
595
+ return $ matches [1 ];
584
596
}
585
597
}
586
598
@@ -610,6 +622,7 @@ function parseFunctionLike(
610
622
$ alias = null ;
611
623
$ isDeprecated = false ;
612
624
$ haveDocReturnType = false ;
625
+ $ docParamTypes = [];
613
626
614
627
if ($ comment ) {
615
628
$ tags = parseDocComment ($ comment );
@@ -631,6 +644,8 @@ function parseFunctionLike(
631
644
$ isDeprecated = true ;
632
645
} else if ($ tag ->name === 'return ' ) {
633
646
$ haveDocReturnType = true ;
647
+ } else if ($ tag ->name === 'param ' ) {
648
+ $ docParamTypes [$ tag ->getVariableName ()] = true ;
634
649
}
635
650
}
636
651
}
@@ -656,6 +671,10 @@ function parseFunctionLike(
656
671
}
657
672
658
673
$ type = $ param ->type ? Type::fromNode ($ param ->type ) : null ;
674
+ if ($ type === null && !isset ($ docParamTypes [$ varName ])) {
675
+ throw new Exception ("Missing parameter type for function $ name() " );
676
+ }
677
+
659
678
if ($ param ->default instanceof Expr \ConstFetch &&
660
679
$ param ->default ->name ->toLowerString () === "null " &&
661
680
$ type && !$ type ->isNullable ()
@@ -1103,7 +1122,7 @@ function initPhpParser() {
1103
1122
$ optind = null ;
1104
1123
$ options = getopt ("f " , ["force-regeneration " ], $ optind );
1105
1124
$ forceRegeneration = isset ($ options ["f " ]) || isset ($ options ["force-regeneration " ]);
1106
- $ location = $ argv [$ optind + 1 ] ?? ". " ;
1125
+ $ location = $ argv [$ optind ] ?? ". " ;
1107
1126
1108
1127
if (is_file ($ location )) {
1109
1128
// Generate single file.
0 commit comments