@@ -75,26 +75,15 @@ public static function create(
7575 $ isReference = false ;
7676
7777 // 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 ) ) {
7979 $ type = $ typeResolver ->resolve ($ firstPart , $ context );
8080 } else {
8181 // first part is not a type; we should prepend it to the parts array for further processing
8282 array_unshift ($ parts , $ firstPart );
8383 }
8484
8585 // 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 ])) {
9887 $ variableName = array_shift ($ parts );
9988 array_shift ($ parts );
10089
@@ -155,4 +144,20 @@ public function __toString() : string
155144 . ($ this ->variableName !== null ? '$ ' . $ this ->variableName : '' )
156145 . ($ this ->description ? ' ' . $ this ->description : '' );
157146 }
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+ }
158163}
0 commit comments