Skip to content

Commit 1e5bd86

Browse files
committed
Fix invalid void type default for arguments
1 parent a8dc047 commit 1e5bd86

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/DocBlock/Tags/Method.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use phpDocumentor\Reflection\Type;
2020
use phpDocumentor\Reflection\TypeResolver;
2121
use phpDocumentor\Reflection\Types\Context as TypeContext;
22+
use phpDocumentor\Reflection\Types\Mixed_;
2223
use phpDocumentor\Reflection\Types\Void_;
2324
use Webmozart\Assert\Assert;
2425
use function array_keys;
@@ -153,7 +154,7 @@ public static function create(
153154
$argument = explode(' ', self::stripRestArg(trim($argument)), 2);
154155
if ($argument[0][0] === '$') {
155156
$argumentName = substr($argument[0], 1);
156-
$argumentType = new Void_();
157+
$argumentType = new Mixed_();
157158
} else {
158159
$argumentType = $typeResolver->resolve($argument[0], $context);
159160
$argumentName = '';
@@ -234,7 +235,7 @@ private function filterArguments(array $arguments = []) : array
234235
}
235236

236237
if (!isset($argument['type'])) {
237-
$argument['type'] = new Void_();
238+
$argument['type'] = new Mixed_();
238239
}
239240

240241
$keys = array_keys($argument);

tests/unit/DocBlock/Tags/MethodTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use phpDocumentor\Reflection\Types\Compound;
2323
use phpDocumentor\Reflection\Types\Context;
2424
use phpDocumentor\Reflection\Types\Integer;
25+
use phpDocumentor\Reflection\Types\Mixed_;
2526
use phpDocumentor\Reflection\Types\Object_;
2627
use phpDocumentor\Reflection\Types\String_;
2728
use phpDocumentor\Reflection\Types\This;
@@ -137,7 +138,7 @@ public function testArgumentsMayBePassedAsString() : void
137138
{
138139
$arguments = ['argument1'];
139140
$expected = [
140-
['name' => $arguments[0], 'type' => new Void_()],
141+
['name' => $arguments[0], 'type' => new Mixed_()],
141142
];
142143

143144
$fixture = new Method('myMethod', $arguments);
@@ -149,11 +150,11 @@ public function testArgumentsMayBePassedAsString() : void
149150
* @covers ::__construct
150151
* @covers ::getArguments
151152
*/
152-
public function testArgumentTypeCanBeInferredAsVoid() : void
153+
public function testArgumentTypeCanBeInferredAsMixed() : void
153154
{
154155
$arguments = [['name' => 'argument1']];
155156
$expected = [
156-
['name' => $arguments[0]['name'], 'type' => new Void_()],
157+
['name' => $arguments[0]['name'], 'type' => new Mixed_()],
157158
];
158159

159160
$fixture = new Method('myMethod', $arguments);
@@ -171,8 +172,8 @@ public function testArgumentTypeCanBeInferredAsVoid() : void
171172
public function testRestArgumentIsParsedAsRegularArg() : void
172173
{
173174
$expected = [
174-
['name' => 'arg1', 'type' => new Void_()],
175-
['name' => 'rest', 'type' => new Void_()],
175+
['name' => 'arg1', 'type' => new Mixed_()],
176+
['name' => 'rest', 'type' => new Mixed_()],
176177
['name' => 'rest2', 'type' => new Array_()],
177178
];
178179

@@ -286,7 +287,7 @@ public function testFactoryMethod() : void
286287
$description = new Description('My Description');
287288
$expectedArguments = [
288289
['name' => 'argument1', 'type' => new String_()],
289-
['name' => 'argument2', 'type' => new Void_()],
290+
['name' => 'argument2', 'type' => new Mixed_()],
290291
];
291292

292293
$descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description);
@@ -298,7 +299,7 @@ public function testFactoryMethod() : void
298299
$context
299300
);
300301

301-
$this->assertSame('static void myMethod(string $argument1, void $argument2) My Description', (string) $fixture);
302+
$this->assertSame('static void myMethod(string $argument1, mixed $argument2) My Description', (string) $fixture);
302303
$this->assertSame('myMethod', $fixture->getMethodName());
303304
$this->assertEquals($expectedArguments, $fixture->getArguments());
304305
$this->assertInstanceOf(Void_::class, $fixture->getReturnType());

0 commit comments

Comments
 (0)