@@ -75,26 +75,15 @@ public static function create(
75
75
$ isReference = false ;
76
76
77
77
// if the first item that is encountered is not a variable; it is a type
78
- if ($ firstPart && $ firstPart [ 0 ] !== ' $ ' ) {
78
+ if ($ firstPart && ! self :: strStartsWithVariable ( $ firstPart ) ) {
79
79
$ type = $ typeResolver ->resolve ($ firstPart , $ context );
80
80
} else {
81
81
// first part is not a type; we should prepend it to the parts array for further processing
82
82
array_unshift ($ parts , $ firstPart );
83
83
}
84
84
85
85
// if the next item starts with a $ or ...$ or &$ or &...$ it must be the variable name
86
- if (isset ($ parts [0 ])
87
- &&
88
- (
89
- strpos ($ parts [0 ], '$ ' ) === 0
90
- ||
91
- strpos ($ parts [0 ], '...$ ' ) === 0
92
- ||
93
- strpos ($ parts [0 ], '&$ ' ) === 0
94
- ||
95
- strpos ($ parts [0 ], '&...$ ' ) === 0
96
- )
97
- ) {
86
+ if (isset ($ parts [0 ]) && self ::strStartsWithVariable ($ parts [0 ])) {
98
87
$ variableName = array_shift ($ parts );
99
88
array_shift ($ parts );
100
89
@@ -155,4 +144,20 @@ public function __toString() : string
155
144
. ($ this ->variableName !== null ? '$ ' . $ this ->variableName : '' )
156
145
. ($ this ->description ? ' ' . $ this ->description : '' );
157
146
}
147
+
148
+ /**
149
+ * @param string $str
150
+ *
151
+ * @return bool
152
+ */
153
+ private static function strStartsWithVariable (string $ str ): bool
154
+ {
155
+ return strpos ($ str , '$ ' ) === 0
156
+ ||
157
+ strpos ($ str , '...$ ' ) === 0
158
+ ||
159
+ strpos ($ str , '&$ ' ) === 0
160
+ ||
161
+ strpos ($ str , '&...$ ' ) === 0 ;
162
+ }
158
163
}
0 commit comments