Fix invalid void type default for arguments

This commit is contained in:
Jaapio
2020-02-09 09:31:53 +01:00
parent a8dc047f21
commit 1e5bd86da1
2 changed files with 11 additions and 9 deletions
+3 -2
View File
@@ -19,6 +19,7 @@ use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\TypeResolver;
use phpDocumentor\Reflection\Types\Context as TypeContext;
use phpDocumentor\Reflection\Types\Mixed_;
use phpDocumentor\Reflection\Types\Void_;
use Webmozart\Assert\Assert;
use function array_keys;
@@ -153,7 +154,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
$argument = explode(' ', self::stripRestArg(trim($argument)), 2);
if ($argument[0][0] === '$') {
$argumentName = substr($argument[0], 1);
$argumentType = new Void_();
$argumentType = new Mixed_();
} else {
$argumentType = $typeResolver->resolve($argument[0], $context);
$argumentName = '';
@@ -234,7 +235,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
}
if (!isset($argument['type'])) {
$argument['type'] = new Void_();
$argument['type'] = new Mixed_();
}
$keys = array_keys($argument);
+8 -7
View File
@@ -22,6 +22,7 @@ use phpDocumentor\Reflection\Types\Array_;
use phpDocumentor\Reflection\Types\Compound;
use phpDocumentor\Reflection\Types\Context;
use phpDocumentor\Reflection\Types\Integer;
use phpDocumentor\Reflection\Types\Mixed_;
use phpDocumentor\Reflection\Types\Object_;
use phpDocumentor\Reflection\Types\String_;
use phpDocumentor\Reflection\Types\This;
@@ -137,7 +138,7 @@ class MethodTest extends TestCase
{
$arguments = ['argument1'];
$expected = [
['name' => $arguments[0], 'type' => new Void_()],
['name' => $arguments[0], 'type' => new Mixed_()],
];
$fixture = new Method('myMethod', $arguments);
@@ -149,11 +150,11 @@ class MethodTest extends TestCase
* @covers ::__construct
* @covers ::getArguments
*/
public function testArgumentTypeCanBeInferredAsVoid() : void
public function testArgumentTypeCanBeInferredAsMixed() : void
{
$arguments = [['name' => 'argument1']];
$expected = [
['name' => $arguments[0]['name'], 'type' => new Void_()],
['name' => $arguments[0]['name'], 'type' => new Mixed_()],
];
$fixture = new Method('myMethod', $arguments);
@@ -171,8 +172,8 @@ class MethodTest extends TestCase
public function testRestArgumentIsParsedAsRegularArg() : void
{
$expected = [
['name' => 'arg1', 'type' => new Void_()],
['name' => 'rest', 'type' => new Void_()],
['name' => 'arg1', 'type' => new Mixed_()],
['name' => 'rest', 'type' => new Mixed_()],
['name' => 'rest2', 'type' => new Array_()],
];
@@ -286,7 +287,7 @@ class MethodTest extends TestCase
$description = new Description('My Description');
$expectedArguments = [
['name' => 'argument1', 'type' => new String_()],
['name' => 'argument2', 'type' => new Void_()],
['name' => 'argument2', 'type' => new Mixed_()],
];
$descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description);
@@ -298,7 +299,7 @@ class MethodTest extends TestCase
$context
);
$this->assertSame('static void myMethod(string $argument1, void $argument2) My Description', (string) $fixture);
$this->assertSame('static void myMethod(string $argument1, mixed $argument2) My Description', (string) $fixture);
$this->assertSame('myMethod', $fixture->getMethodName());
$this->assertEquals($expectedArguments, $fixture->getArguments());
$this->assertInstanceOf(Void_::class, $fixture->getReturnType());