22
22
/**
23
23
* Reflection class for the {@}param tag in a Docblock.
24
24
*/
25
- final class Param extends BaseTag implements Factory \StaticMethod
25
+ final class Param extends TagWithType implements Factory \StaticMethod
26
26
{
27
- /** @var string */
28
- protected $ name = 'param ' ;
29
-
30
- /** @var Type */
31
- private $ type ;
32
-
33
27
/** @var string */
34
28
private $ variableName = '' ;
35
29
@@ -47,6 +41,7 @@ public function __construct($variableName, Type $type = null, $isVariadic = fals
47
41
Assert::string ($ variableName );
48
42
Assert::boolean ($ isVariadic );
49
43
44
+ $ this ->name = 'param ' ;
50
45
$ this ->variableName = $ variableName ;
51
46
$ this ->type = $ type ;
52
47
$ this ->isVariadic = $ isVariadic ;
@@ -65,19 +60,25 @@ public static function create(
65
60
Assert::stringNotEmpty ($ body );
66
61
Assert::allNotNull ([$ typeResolver , $ descriptionFactory ]);
67
62
68
- $ parts = preg_split ( ' /(\s+)/Su ' , $ body, 3 , PREG_SPLIT_DELIM_CAPTURE );
63
+ list ( $ firstPart , $ body) = self :: extractTypeFromBody ( $ body );
69
64
$ type = null ;
65
+ $ parts = preg_split ('/(\s+)/Su ' , $ body , 2 , PREG_SPLIT_DELIM_CAPTURE );
70
66
$ variableName = '' ;
71
67
$ isVariadic = false ;
72
68
73
69
// 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 );
77
75
}
78
76
79
77
// 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
+ ) {
81
82
$ variableName = array_shift ($ parts );
82
83
array_shift ($ parts );
83
84
@@ -106,16 +107,6 @@ public function getVariableName()
106
107
return $ this ->variableName ;
107
108
}
108
109
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
-
119
110
/**
120
111
* Returns whether this tag is variadic.
121
112
*
@@ -134,8 +125,8 @@ public function isVariadic()
134
125
public function __toString ()
135
126
{
136
127
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 : '' );
140
131
}
141
132
}
0 commit comments