Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/DocBlock/Tags/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,15 @@ public static function create(
if ('' !== $arguments) {
$arguments = explode(',', $arguments);
foreach($arguments as &$argument) {
$argument = explode(' ', trim($argument));
$argument = explode(' ', self::stripRestArg(trim($argument)), 2);
if ($argument[0][0] === '$') {
$argumentName = substr($argument[0], 1);
$argumentType = new Void_();
} else {
$argumentType = $typeResolver->resolve($argument[0], $context);
$argumentName = '';
if (isset($argument[1])) {
$argument[1] = self::stripRestArg($argument[1]);
$argumentName = substr($argument[1], 1);
}
}
Expand Down Expand Up @@ -217,4 +218,13 @@ private function filterArguments($arguments)

return $arguments;
}

private static function stripRestArg($argument)
{
if (strpos($argument, '...') === 0) {
$argument = trim(substr($argument, 3));
}

return $argument;
}
}
27 changes: 27 additions & 0 deletions tests/unit/DocBlock/Tags/MethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,33 @@ public function testArgumentTypeCanBeInferredAsVoid()
$this->assertEquals($expected, $fixture->getArguments());
}

/**
* @covers ::create
*/
public function testRestArgumentIsParsedAsRegularArg()
{
$expected = [
[ 'name' => 'arg1', 'type' => new Void_() ],
[ 'name' => 'rest', 'type' => new Void_() ],
[ 'name' => 'rest2', 'type' => new Array_() ],
];

$descriptionFactory = m::mock(DescriptionFactory::class);
$resolver = new TypeResolver();
$context = new Context('');
$description = new Description('');
$descriptionFactory->shouldReceive('create')->with('', $context)->andReturn($description);

$fixture = Method::create(
'void myMethod($arg1, ...$rest, array ... $rest2)',
$resolver,
$descriptionFactory,
$context
);

$this->assertEquals($expected, $fixture->getArguments());
}

/**
* @covers ::__construct
* @covers ::getReturnType
Expand Down