@@ -8,11 +8,15 @@ class PhpDocParser
88 public const PROPERTY_TYPE_VARIABLE = 'VARIABLE ' ;
99 public const PROPERTY_TYPE_METHOD = 'METHOD ' ;
1010
11- public function parseDocComment (string $ phpDoc , $ type = self ::PROPERTY_TYPE_VARIABLE , $ includeTypeNullable = false ): string
12- {
11+ public function parseDocComment (
12+ string $ phpDoc ,
13+ $ type = self ::PROPERTY_TYPE_VARIABLE ,
14+ $ includeTypeNullable = false
15+ ): string {
1316 $ varRegex = '/@var\s+(?P<var>[^\s*]+)?/ ' ;
1417 $ methodRegex = '/@return\s+(?P<var>[^\s*]+)?/ ' ;
1518 $ typeRegex = '/(?P<type>[^\[\]\s]+)(?P<array>\[\])?/i ' ;
19+ $ psalmTypeRegex = '/array\<(?P<psalmType>[^\s*]+)?\>/i ' ;
1620
1721 if (empty ($ phpDoc )) {
1822 return 'any ' ;
@@ -28,7 +32,12 @@ public function parseDocComment(string $phpDoc, $type = self::PROPERTY_TYPE_VARI
2832 foreach ($ types as $ phpType ) {
2933 $ tsType = $ phpType ;
3034
31- if (preg_match ($ typeRegex , $ phpType , $ typeMatch )) {
35+ if (preg_match ($ psalmTypeRegex , $ phpType , $ typeMatch )) {
36+ $ tsType = $ this ->getTypeEquivalent ($ typeMatch ['psalmType ' ], $ includeTypeNullable );
37+ if ($ tsType !== null ) {
38+ $ tsType .= '[] ' ;
39+ }
40+ } else if (preg_match ($ typeRegex , $ phpType , $ typeMatch )) {
3241 $ tsType = $ this ->getTypeEquivalent ($ typeMatch ['type ' ], $ includeTypeNullable );
3342 if ($ tsType === null ) {
3443 continue ;
0 commit comments