From 81553b535f45abf71b95312be297728cb806f7ae Mon Sep 17 00:00:00 2001 From: Jaapio Date: Fri, 28 Oct 2022 22:37:28 +0200 Subject: [PATCH] Add default types to method tag arguments --- src/DocBlock/Tags/Factory/MethodFactory.php | 3 ++- src/DocBlock/Tags/Method.php | 1 + .../Tags/Factory/MethodFactoryTest.php | 25 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/DocBlock/Tags/Factory/MethodFactory.php b/src/DocBlock/Tags/Factory/MethodFactory.php index cb2d463..6a12204 100644 --- a/src/DocBlock/Tags/Factory/MethodFactory.php +++ b/src/DocBlock/Tags/Factory/MethodFactory.php @@ -10,6 +10,7 @@ use phpDocumentor\Reflection\DocBlock\Tags\Method; use phpDocumentor\Reflection\DocBlock\Tags\MethodParameter; use phpDocumentor\Reflection\Type; use phpDocumentor\Reflection\Types\Context; +use phpDocumentor\Reflection\Types\Mixed_; use phpDocumentor\Reflection\Types\Void_; use PHPStan\PhpDocParser\Ast\PhpDoc\MethodTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\MethodTagValueParameterNode; @@ -49,7 +50,7 @@ final class MethodFactory implements PHPStanFactory function (MethodTagValueParameterNode $param) use ($context) { return new MethodParameter( trim($param->parameterName, '$'), - $this->typeFactory->createType($param->type, $context), + $this->typeFactory->createType($param->type, $context) ?? new Mixed_(), $param->isReference, $param->isVariadic, (string) $param->defaultValue diff --git a/src/DocBlock/Tags/Method.php b/src/DocBlock/Tags/Method.php index e97df45..701325d 100644 --- a/src/DocBlock/Tags/Method.php +++ b/src/DocBlock/Tags/Method.php @@ -328,6 +328,7 @@ final class Method extends BaseTag implements Factory\StaticMethod /** * @param array{name: string, type: Type} $arguments + * * @return MethodParameter[] */ private function fromLegacyArguments(array $arguments): array diff --git a/tests/unit/DocBlock/Tags/Factory/MethodFactoryTest.php b/tests/unit/DocBlock/Tags/Factory/MethodFactoryTest.php index c29f969..17ac469 100644 --- a/tests/unit/DocBlock/Tags/Factory/MethodFactoryTest.php +++ b/tests/unit/DocBlock/Tags/Factory/MethodFactoryTest.php @@ -18,6 +18,7 @@ use phpDocumentor\Reflection\DocBlock\Tags\Method; use phpDocumentor\Reflection\DocBlock\Tags\MethodParameter; use phpDocumentor\Reflection\Types\Context; use phpDocumentor\Reflection\Types\Integer; +use phpDocumentor\Reflection\Types\Mixed_; use phpDocumentor\Reflection\Types\String_; use phpDocumentor\Reflection\Types\Void_; @@ -82,6 +83,30 @@ final class MethodFactoryTest extends TagFactoryTestCase [] ), ], + [ + '@method myMethod($a)', + new Method( + 'myMethod', + [], + new Void_(), + false, + new Description(''), + false, + [new MethodParameter('a', new Mixed_())] + ), + ], + [ + '@method myMethod($a = 1)', + new Method( + 'myMethod', + [], + new Void_(), + false, + new Description(''), + false, + [new MethodParameter('a', new Mixed_(), false, false, '1')] + ), + ], [ '@method myMethod(int $a = 1)', new Method(