Skip to content

Commit 81553b5

Browse files
committed
Add default types to method tag arguments
1 parent e4ac07b commit 81553b5

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/DocBlock/Tags/Factory/MethodFactory.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use phpDocumentor\Reflection\DocBlock\Tags\MethodParameter;
1111
use phpDocumentor\Reflection\Type;
1212
use phpDocumentor\Reflection\Types\Context;
13+
use phpDocumentor\Reflection\Types\Mixed_;
1314
use phpDocumentor\Reflection\Types\Void_;
1415
use PHPStan\PhpDocParser\Ast\PhpDoc\MethodTagValueNode;
1516
use PHPStan\PhpDocParser\Ast\PhpDoc\MethodTagValueParameterNode;
@@ -49,7 +50,7 @@ public function create(PhpDocTagNode $node, ?Context $context): Tag
4950
function (MethodTagValueParameterNode $param) use ($context) {
5051
return new MethodParameter(
5152
trim($param->parameterName, '$'),
52-
$this->typeFactory->createType($param->type, $context),
53+
$this->typeFactory->createType($param->type, $context) ?? new Mixed_(),
5354
$param->isReference,
5455
$param->isVariadic,
5556
(string) $param->defaultValue

src/DocBlock/Tags/Method.php

+1
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ private static function stripRestArg(string $argument): string
328328

329329
/**
330330
* @param array{name: string, type: Type} $arguments
331+
*
331332
* @return MethodParameter[]
332333
*/
333334
private function fromLegacyArguments(array $arguments): array

tests/unit/DocBlock/Tags/Factory/MethodFactoryTest.php

+25
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use phpDocumentor\Reflection\DocBlock\Tags\MethodParameter;
1919
use phpDocumentor\Reflection\Types\Context;
2020
use phpDocumentor\Reflection\Types\Integer;
21+
use phpDocumentor\Reflection\Types\Mixed_;
2122
use phpDocumentor\Reflection\Types\String_;
2223
use phpDocumentor\Reflection\Types\Void_;
2324

@@ -82,6 +83,30 @@ public function tagProvider(): array
8283
[]
8384
),
8485
],
86+
[
87+
'@method myMethod($a)',
88+
new Method(
89+
'myMethod',
90+
[],
91+
new Void_(),
92+
false,
93+
new Description(''),
94+
false,
95+
[new MethodParameter('a', new Mixed_())]
96+
),
97+
],
98+
[
99+
'@method myMethod($a = 1)',
100+
new Method(
101+
'myMethod',
102+
[],
103+
new Void_(),
104+
false,
105+
new Description(''),
106+
false,
107+
[new MethodParameter('a', new Mixed_(), false, false, '1')]
108+
),
109+
],
85110
[
86111
'@method myMethod(int $a = 1)',
87112
new Method(

0 commit comments

Comments
 (0)