@@ -47,7 +47,7 @@ public function getVarTypeName(): string {
4747 $ vars = $ phpDocNode ->getVarTagValues ();
4848 if (count ($ vars ) > 0 ) {
4949 if ( ! empty ($ vars [0 ]->type )) {
50- return $ vars [0 ]->type ->__toString ();
50+ return $ this -> convertUnionExpression ( $ vars [0 ]->type ->__toString () );
5151 }
5252 }
5353 return '' ;
@@ -60,7 +60,7 @@ public function getParamTypeName(string $paramName): string {
6060 }); // ParamTagValueNode[]
6161 if (count ($ paramTags ) > 0 ) {
6262 if ( ! empty ($ paramTags [0 ]->type )) {
63- return $ paramTags [0 ]->type ->__toString ();
63+ return $ this -> convertUnionExpression ( $ paramTags [0 ]->type ->__toString () );
6464 }
6565 }
6666 return '' ;
@@ -71,7 +71,7 @@ public function getReturnTypeName(): string {
7171 $ returns = $ phpDocNode ->getReturnTagValues ();
7272 if (count ($ returns ) > 0 ) {
7373 if ( ! empty ($ returns [0 ]->type )) {
74- return $ returns [0 ]->type ->__toString ();
74+ return $ this -> convertUnionExpression ( $ returns [0 ]->type ->__toString () );
7575 }
7676 }
7777 return '' ;
@@ -86,4 +86,13 @@ private function getParseResult(): PhpDocNode
8686 $ tokens = new TokenIterator ($ lexer ->tokenize ('/** ' . $ this ->text . ' */ ' ));
8787 return $ phpDocParser ->parse ($ tokens ); // PhpDocNode
8888 }
89+
90+ private function convertUnionExpression (string $ difinition ): string
91+ {
92+ $ difinition = preg_replace ('/^\((.*)\)$/ ' , '$1 ' , $ difinition );
93+ $ typeStrings = array_map (function (string $ x ){
94+ return trim ($ x );
95+ }, explode ('| ' , $ difinition ));
96+ return implode ('| ' , $ typeStrings );
97+ }
8998}
0 commit comments