mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 01:57:13 +00:00
Fix invalid void type default for arguments
This commit is contained in:
@@ -19,6 +19,7 @@ use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
|||||||
use phpDocumentor\Reflection\Type;
|
use phpDocumentor\Reflection\Type;
|
||||||
use phpDocumentor\Reflection\TypeResolver;
|
use phpDocumentor\Reflection\TypeResolver;
|
||||||
use phpDocumentor\Reflection\Types\Context as TypeContext;
|
use phpDocumentor\Reflection\Types\Context as TypeContext;
|
||||||
|
use phpDocumentor\Reflection\Types\Mixed_;
|
||||||
use phpDocumentor\Reflection\Types\Void_;
|
use phpDocumentor\Reflection\Types\Void_;
|
||||||
use Webmozart\Assert\Assert;
|
use Webmozart\Assert\Assert;
|
||||||
use function array_keys;
|
use function array_keys;
|
||||||
@@ -153,7 +154,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
|
|||||||
$argument = explode(' ', self::stripRestArg(trim($argument)), 2);
|
$argument = explode(' ', self::stripRestArg(trim($argument)), 2);
|
||||||
if ($argument[0][0] === '$') {
|
if ($argument[0][0] === '$') {
|
||||||
$argumentName = substr($argument[0], 1);
|
$argumentName = substr($argument[0], 1);
|
||||||
$argumentType = new Void_();
|
$argumentType = new Mixed_();
|
||||||
} else {
|
} else {
|
||||||
$argumentType = $typeResolver->resolve($argument[0], $context);
|
$argumentType = $typeResolver->resolve($argument[0], $context);
|
||||||
$argumentName = '';
|
$argumentName = '';
|
||||||
@@ -234,7 +235,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($argument['type'])) {
|
if (!isset($argument['type'])) {
|
||||||
$argument['type'] = new Void_();
|
$argument['type'] = new Mixed_();
|
||||||
}
|
}
|
||||||
|
|
||||||
$keys = array_keys($argument);
|
$keys = array_keys($argument);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ use phpDocumentor\Reflection\Types\Array_;
|
|||||||
use phpDocumentor\Reflection\Types\Compound;
|
use phpDocumentor\Reflection\Types\Compound;
|
||||||
use phpDocumentor\Reflection\Types\Context;
|
use phpDocumentor\Reflection\Types\Context;
|
||||||
use phpDocumentor\Reflection\Types\Integer;
|
use phpDocumentor\Reflection\Types\Integer;
|
||||||
|
use phpDocumentor\Reflection\Types\Mixed_;
|
||||||
use phpDocumentor\Reflection\Types\Object_;
|
use phpDocumentor\Reflection\Types\Object_;
|
||||||
use phpDocumentor\Reflection\Types\String_;
|
use phpDocumentor\Reflection\Types\String_;
|
||||||
use phpDocumentor\Reflection\Types\This;
|
use phpDocumentor\Reflection\Types\This;
|
||||||
@@ -137,7 +138,7 @@ class MethodTest extends TestCase
|
|||||||
{
|
{
|
||||||
$arguments = ['argument1'];
|
$arguments = ['argument1'];
|
||||||
$expected = [
|
$expected = [
|
||||||
['name' => $arguments[0], 'type' => new Void_()],
|
['name' => $arguments[0], 'type' => new Mixed_()],
|
||||||
];
|
];
|
||||||
|
|
||||||
$fixture = new Method('myMethod', $arguments);
|
$fixture = new Method('myMethod', $arguments);
|
||||||
@@ -149,11 +150,11 @@ class MethodTest extends TestCase
|
|||||||
* @covers ::__construct
|
* @covers ::__construct
|
||||||
* @covers ::getArguments
|
* @covers ::getArguments
|
||||||
*/
|
*/
|
||||||
public function testArgumentTypeCanBeInferredAsVoid() : void
|
public function testArgumentTypeCanBeInferredAsMixed() : void
|
||||||
{
|
{
|
||||||
$arguments = [['name' => 'argument1']];
|
$arguments = [['name' => 'argument1']];
|
||||||
$expected = [
|
$expected = [
|
||||||
['name' => $arguments[0]['name'], 'type' => new Void_()],
|
['name' => $arguments[0]['name'], 'type' => new Mixed_()],
|
||||||
];
|
];
|
||||||
|
|
||||||
$fixture = new Method('myMethod', $arguments);
|
$fixture = new Method('myMethod', $arguments);
|
||||||
@@ -171,8 +172,8 @@ class MethodTest extends TestCase
|
|||||||
public function testRestArgumentIsParsedAsRegularArg() : void
|
public function testRestArgumentIsParsedAsRegularArg() : void
|
||||||
{
|
{
|
||||||
$expected = [
|
$expected = [
|
||||||
['name' => 'arg1', 'type' => new Void_()],
|
['name' => 'arg1', 'type' => new Mixed_()],
|
||||||
['name' => 'rest', 'type' => new Void_()],
|
['name' => 'rest', 'type' => new Mixed_()],
|
||||||
['name' => 'rest2', 'type' => new Array_()],
|
['name' => 'rest2', 'type' => new Array_()],
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -286,7 +287,7 @@ class MethodTest extends TestCase
|
|||||||
$description = new Description('My Description');
|
$description = new Description('My Description');
|
||||||
$expectedArguments = [
|
$expectedArguments = [
|
||||||
['name' => 'argument1', 'type' => new String_()],
|
['name' => 'argument1', 'type' => new String_()],
|
||||||
['name' => 'argument2', 'type' => new Void_()],
|
['name' => 'argument2', 'type' => new Mixed_()],
|
||||||
];
|
];
|
||||||
|
|
||||||
$descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description);
|
$descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description);
|
||||||
@@ -298,7 +299,7 @@ class MethodTest extends TestCase
|
|||||||
$context
|
$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->assertSame('myMethod', $fixture->getMethodName());
|
||||||
$this->assertEquals($expectedArguments, $fixture->getArguments());
|
$this->assertEquals($expectedArguments, $fixture->getArguments());
|
||||||
$this->assertInstanceOf(Void_::class, $fixture->getReturnType());
|
$this->assertInstanceOf(Void_::class, $fixture->getReturnType());
|
||||||
|
|||||||
Reference in New Issue
Block a user