mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 01:57:13 +00:00
Add default types to method tag arguments
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user