2222/**
2323 * Reflection class for the {@}param tag in a Docblock.
2424 */
25- final class Param extends BaseTag implements Factory \StaticMethod
25+ final class Param extends TagWithType implements Factory \StaticMethod
2626{
27- /** @var string */
28- protected $ name = 'param ' ;
29-
30- /** @var Type */
31- private $ type ;
32-
3327 /** @var string */
3428 private $ variableName = '' ;
3529
@@ -47,6 +41,7 @@ public function __construct($variableName, Type $type = null, $isVariadic = fals
4741 Assert::string ($ variableName );
4842 Assert::boolean ($ isVariadic );
4943
44+ $ this ->name = 'param ' ;
5045 $ this ->variableName = $ variableName ;
5146 $ this ->type = $ type ;
5247 $ this ->isVariadic = $ isVariadic ;
@@ -65,19 +60,25 @@ public static function create(
6560 Assert::stringNotEmpty ($ body );
6661 Assert::allNotNull ([$ typeResolver , $ descriptionFactory ]);
6762
68- $ parts = preg_split ( ' /(\s+)/Su ' , $ body, 3 , PREG_SPLIT_DELIM_CAPTURE );
63+ list ( $ firstPart , $ body) = self :: extractTypeFromBody ( $ body );
6964 $ type = null ;
65+ $ parts = preg_split ('/(\s+)/Su ' , $ body , 2 , PREG_SPLIT_DELIM_CAPTURE );
7066 $ variableName = '' ;
7167 $ isVariadic = false ;
7268
7369 // if the first item that is encountered is not a variable; it is a type
74- if (isset ($ parts [0 ]) && (strlen ($ parts [0 ]) > 0 ) && ($ parts [0 ][0 ] !== '$ ' )) {
75- $ type = $ typeResolver ->resolve (array_shift ($ parts ), $ context );
76- array_shift ($ parts );
70+ if ($ firstPart && (strlen ($ firstPart ) > 0 ) && ($ firstPart [0 ] !== '$ ' )) {
71+ $ type = $ typeResolver ->resolve ($ firstPart , $ context );
72+ } else {
73+ // first part is not a type; we should prepend it to the parts array for further processing
74+ array_unshift ($ parts , $ firstPart );
7775 }
7876
7977 // if the next item starts with a $ or ...$ it must be the variable name
80- if (isset ($ parts [0 ]) && (strlen ($ parts [0 ]) > 0 ) && ($ parts [0 ][0 ] === '$ ' || substr ($ parts [0 ], 0 , 4 ) === '...$ ' )) {
78+ if (isset ($ parts [0 ])
79+ && (strlen ($ parts [0 ]) > 0 )
80+ && ($ parts [0 ][0 ] === '$ ' || substr ($ parts [0 ], 0 , 4 ) === '...$ ' )
81+ ) {
8182 $ variableName = array_shift ($ parts );
8283 array_shift ($ parts );
8384
@@ -106,16 +107,6 @@ public function getVariableName()
106107 return $ this ->variableName ;
107108 }
108109
109- /**
110- * Returns the variable's type or null if unknown.
111- *
112- * @return Type|null
113- */
114- public function getType ()
115- {
116- return $ this ->type ;
117- }
118-
119110 /**
120111 * Returns whether this tag is variadic.
121112 *
@@ -134,8 +125,8 @@ public function isVariadic()
134125 public function __toString ()
135126 {
136127 return ($ this ->type ? $ this ->type . ' ' : '' )
137- . ($ this ->isVariadic () ? '... ' : '' )
138- . '$ ' . $ this ->variableName
139- . ($ this ->description ? ' ' . $ this ->description : '' );
128+ . ($ this ->isVariadic () ? '... ' : '' )
129+ . '$ ' . $ this ->variableName
130+ . ($ this ->description ? ' ' . $ this ->description : '' );
140131 }
141132}
0 commit comments