File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -127,14 +127,15 @@ public static function create(
127
127
if ('' !== $ arguments ) {
128
128
$ arguments = explode (', ' , $ arguments );
129
129
foreach ($ arguments as &$ argument ) {
130
- $ argument = explode (' ' , trim ($ argument ));
130
+ $ argument = explode (' ' , self :: stripRestArg ( trim ($ argument )), 2 );
131
131
if ($ argument [0 ][0 ] === '$ ' ) {
132
132
$ argumentName = substr ($ argument [0 ], 1 );
133
133
$ argumentType = new Void_ ();
134
134
} else {
135
135
$ argumentType = $ typeResolver ->resolve ($ argument [0 ], $ context );
136
136
$ argumentName = '' ;
137
137
if (isset ($ argument [1 ])) {
138
+ $ argument [1 ] = self ::stripRestArg ($ argument [1 ]);
138
139
$ argumentName = substr ($ argument [1 ], 1 );
139
140
}
140
141
}
@@ -217,4 +218,13 @@ private function filterArguments($arguments)
217
218
218
219
return $ arguments ;
219
220
}
221
+
222
+ private static function stripRestArg ($ argument )
223
+ {
224
+ if (strpos ($ argument , '... ' ) === 0 ) {
225
+ $ argument = trim (substr ($ argument , 3 ));
226
+ }
227
+
228
+ return $ argument ;
229
+ }
220
230
}
Original file line number Diff line number Diff line change @@ -139,6 +139,33 @@ public function testArgumentTypeCanBeInferredAsVoid()
139
139
$ this ->assertEquals ($ expected , $ fixture ->getArguments ());
140
140
}
141
141
142
+ /**
143
+ * @covers ::create
144
+ */
145
+ public function testRestArgumentIsParsedAsRegularArg ()
146
+ {
147
+ $ expected = [
148
+ [ 'name ' => 'arg1 ' , 'type ' => new Void_ () ],
149
+ [ 'name ' => 'rest ' , 'type ' => new Void_ () ],
150
+ [ 'name ' => 'rest2 ' , 'type ' => new Array_ () ],
151
+ ];
152
+
153
+ $ descriptionFactory = m::mock (DescriptionFactory::class);
154
+ $ resolver = new TypeResolver ();
155
+ $ context = new Context ('' );
156
+ $ description = new Description ('' );
157
+ $ descriptionFactory ->shouldReceive ('create ' )->with ('' , $ context )->andReturn ($ description );
158
+
159
+ $ fixture = Method::create (
160
+ 'void myMethod($arg1, ...$rest, array ... $rest2) ' ,
161
+ $ resolver ,
162
+ $ descriptionFactory ,
163
+ $ context
164
+ );
165
+
166
+ $ this ->assertEquals ($ expected , $ fixture ->getArguments ());
167
+ }
168
+
142
169
/**
143
170
* @covers ::__construct
144
171
* @covers ::getReturnType
You can’t perform that action at this time.
0 commit comments