Skip to content

Include default argument value when argument has no type #278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion src/DocBlock/Tags/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static function create(
foreach ($argumentsExploded as $argument) {
$argument = explode(' ', self::stripRestArg(trim($argument)), 2);
if (strpos($argument[0], '$') === 0) {
$argumentName = substr($argument[0], 1);
$argumentName = substr(implode(' ', $argument), 1);
$argumentType = new Mixed_();
} else {
$argumentType = $typeResolver->resolve($argument[0], $context);
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/DocBlock/Tags/MethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,31 @@ public function testRestArgumentIsParsedAsRegularArg() : void
$this->assertEquals($expected, $fixture->getArguments());
}

public function testArgumentHasDefaultValue() : void
{
$expected = [
['name' => "arg1 = ''", 'type' => new Mixed_()],
['name' => "arg2 = ['value']", 'type' => new Mixed_()],
['name' => "arg3 = 'test'", 'type' => new String_()],
['name' => "arg4 = ['value']", '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 = \'\', $arg2 = [\'value\'], string $arg3 = \'test\', array $arg4 = [\'value\'])',
$resolver,
$descriptionFactory,
$context
);

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

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