29
29
/**
30
30
* Reflection class for the {@}param tag in a Docblock.
31
31
*/
32
- final class Param extends BaseTag implements Factory \StaticMethod
32
+ final class Param extends TagWithType implements Factory \StaticMethod
33
33
{
34
- /** @var string */
35
- protected $ name = 'param ' ;
36
-
37
- /** @var Type|null */
38
- private $ type ;
39
-
40
34
/** @var string|null */
41
35
private $ variableName ;
42
36
@@ -49,6 +43,7 @@ public function __construct(
49
43
bool $ isVariadic = false ,
50
44
?Description $ description = null
51
45
) {
46
+ $ this ->name = 'param ' ;
52
47
$ this ->variableName = $ variableName ;
53
48
$ this ->type = $ type ;
54
49
$ this ->isVariadic = $ isVariadic ;
@@ -68,21 +63,24 @@ public static function create(
68
63
Assert::notNull ($ typeResolver );
69
64
Assert::notNull ($ descriptionFactory );
70
65
71
- $ parts = preg_split ( ' /(\s+)/Su ' , $ body, 3 , PREG_SPLIT_DELIM_CAPTURE );
72
- Assert:: isArray ( $ parts ) ;
73
- $ type = null ;
66
+ list ( $ firstPart , $ body) = self :: extractTypeFromBody ( $ body );
67
+ $ type = null ;
68
+ $ parts = preg_split ( ' /(\s+)/Su ' , $ body , 2 , PREG_SPLIT_DELIM_CAPTURE ) ;
74
69
$ variableName = '' ;
75
70
$ isVariadic = false ;
76
71
77
72
// if the first item that is encountered is not a variable; it is a type
78
- if (isset ($ parts [0 ]) && ($ parts [0 ] !== '' ) && ($ parts [0 ][0 ] !== '$ ' )) {
79
- $ type = $ typeResolver ->resolve (array_shift ($ parts ), $ context );
80
- array_shift ($ parts );
73
+ if ($ firstPart && (strlen ($ firstPart ) > 0 ) && ($ firstPart [0 ] !== '$ ' )) {
74
+ $ type = $ typeResolver ->resolve ($ firstPart , $ context );
75
+ } else {
76
+ // first part is not a type; we should prepend it to the parts array for further processing
77
+ array_unshift ($ parts , $ firstPart );
81
78
}
82
79
83
80
// if the next item starts with a $ or ...$ it must be the variable name
84
- if (isset ($ parts [0 ]) && ($ parts [0 ] !== '' ) &&
85
- (strpos ($ parts [0 ], '$ ' ) === 0 || strpos ($ parts [0 ], '...$ ' ) === 0 )
81
+ if (isset ($ parts [0 ])
82
+ && (strlen ($ parts [0 ]) > 0 )
83
+ && ($ parts [0 ][0 ] === '$ ' || substr ($ parts [0 ], 0 , 4 ) === '...$ ' )
86
84
) {
87
85
$ variableName = array_shift ($ parts );
88
86
array_shift ($ parts );
@@ -110,14 +108,6 @@ public function getVariableName() : ?string
110
108
return $ this ->variableName ;
111
109
}
112
110
113
- /**
114
- * Returns the variable's type or null if unknown.
115
- */
116
- public function getType () : ?Type
117
- {
118
- return $ this ->type ;
119
- }
120
-
121
111
/**
122
112
* Returns whether this tag is variadic.
123
113
*/
0 commit comments