mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 01:57:13 +00:00
Implement fallback option for params without variable
This commit is contained in:
@@ -13,6 +13,7 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\InvalidTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\TypelessParamTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
use function trim;
|
||||
@@ -34,17 +35,22 @@ final class ParamFactory implements PHPStanFactory
|
||||
public function create(PhpDocTagNode $node, Context $context): Tag
|
||||
{
|
||||
$tagValue = $node->value;
|
||||
|
||||
if ($tagValue instanceof InvalidTagValueNode) {
|
||||
return Param::create($tagValue->value, $this->typeResolver, $this->descriptionFactory, $context);
|
||||
}
|
||||
|
||||
Assert::isInstanceOfAny(
|
||||
$tagValue,
|
||||
[
|
||||
ParamTagValueNode::class,
|
||||
TypelessParamTagValueNode::class
|
||||
TypelessParamTagValueNode::class,
|
||||
]
|
||||
);
|
||||
|
||||
return new Param(
|
||||
trim($tagValue->parameterName, '$'),
|
||||
$this->typeResolver->createType($tagValue->type, $context),
|
||||
$this->typeResolver->createType($tagValue->type ?? new IdentifierTypeNode('mixed'), $context),
|
||||
$tagValue->isVariadic,
|
||||
$this->descriptionFactory->create($tagValue->description, $context),
|
||||
$tagValue->isReference
|
||||
@@ -54,6 +60,7 @@ final class ParamFactory implements PHPStanFactory
|
||||
public function supports(PhpDocTagNode $node, Context $context): bool
|
||||
{
|
||||
return $node->value instanceof ParamTagValueNode
|
||||
|| $node->value instanceof TypelessParamTagValueNode;
|
||||
|| $node->value instanceof TypelessParamTagValueNode
|
||||
|| $node->name === '@param';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
use phpDocumentor\Reflection\DocBlock\Description;
|
||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||
use phpDocumentor\Reflection\Type;
|
||||
@@ -26,9 +27,7 @@ use function array_unshift;
|
||||
use function implode;
|
||||
use function strpos;
|
||||
use function substr;
|
||||
use function trigger_error;
|
||||
|
||||
use const E_USER_DEPRECATED;
|
||||
use const PREG_SPLIT_DELIM_CAPTURE;
|
||||
|
||||
/**
|
||||
@@ -69,11 +68,13 @@ final class Param extends TagWithType implements Factory\StaticMethod
|
||||
?DescriptionFactory $descriptionFactory = null,
|
||||
?TypeContext $context = null
|
||||
): self {
|
||||
trigger_error(
|
||||
Deprecation::triggerIfCalledFromOutside(
|
||||
'phpdocumentor/reflection-docblock',
|
||||
'https://github.com/phpDocumentor/ReflectionDocBlock/issues/361',
|
||||
'Create using static factory is deprecated, this method should not be called directly
|
||||
by library consumers',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
|
||||
Assert::stringNotEmpty($body);
|
||||
Assert::notNull($typeResolver);
|
||||
Assert::notNull($descriptionFactory);
|
||||
|
||||
@@ -13,6 +13,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
use phpDocumentor\Reflection\DocBlock\Description;
|
||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||
use phpDocumentor\Reflection\Type;
|
||||
@@ -26,9 +27,7 @@ use function array_unshift;
|
||||
use function implode;
|
||||
use function strpos;
|
||||
use function substr;
|
||||
use function trigger_error;
|
||||
|
||||
use const E_USER_DEPRECATED;
|
||||
use const PREG_SPLIT_DELIM_CAPTURE;
|
||||
|
||||
/**
|
||||
@@ -58,11 +57,13 @@ final class Property extends TagWithType implements Factory\StaticMethod
|
||||
?DescriptionFactory $descriptionFactory = null,
|
||||
?TypeContext $context = null
|
||||
): self {
|
||||
trigger_error(
|
||||
Deprecation::triggerIfCalledFromOutside(
|
||||
'phpdocumentor/reflection-docblock',
|
||||
'https://github.com/phpDocumentor/ReflectionDocBlock/issues/361',
|
||||
'Create using static factory is deprecated, this method should not be called directly
|
||||
by library consumers',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
|
||||
Assert::stringNotEmpty($body);
|
||||
Assert::notNull($typeResolver);
|
||||
Assert::notNull($descriptionFactory);
|
||||
|
||||
@@ -13,6 +13,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
use phpDocumentor\Reflection\DocBlock\Description;
|
||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||
use phpDocumentor\Reflection\Type;
|
||||
@@ -26,9 +27,7 @@ use function array_unshift;
|
||||
use function implode;
|
||||
use function strpos;
|
||||
use function substr;
|
||||
use function trigger_error;
|
||||
|
||||
use const E_USER_DEPRECATED;
|
||||
use const PREG_SPLIT_DELIM_CAPTURE;
|
||||
|
||||
/**
|
||||
@@ -58,11 +57,13 @@ final class PropertyRead extends TagWithType implements Factory\StaticMethod
|
||||
?DescriptionFactory $descriptionFactory = null,
|
||||
?TypeContext $context = null
|
||||
): self {
|
||||
trigger_error(
|
||||
Deprecation::triggerIfCalledFromOutside(
|
||||
'phpdocumentor/reflection-docblock',
|
||||
'https://github.com/phpDocumentor/ReflectionDocBlock/issues/361',
|
||||
'Create using static factory is deprecated, this method should not be called directly
|
||||
by library consumers',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
|
||||
Assert::stringNotEmpty($body);
|
||||
Assert::notNull($typeResolver);
|
||||
Assert::notNull($descriptionFactory);
|
||||
|
||||
@@ -13,6 +13,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
use phpDocumentor\Reflection\DocBlock\Description;
|
||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||
use phpDocumentor\Reflection\Type;
|
||||
@@ -26,9 +27,7 @@ use function array_unshift;
|
||||
use function implode;
|
||||
use function strpos;
|
||||
use function substr;
|
||||
use function trigger_error;
|
||||
|
||||
use const E_USER_DEPRECATED;
|
||||
use const PREG_SPLIT_DELIM_CAPTURE;
|
||||
|
||||
/**
|
||||
@@ -58,11 +57,13 @@ final class PropertyWrite extends TagWithType implements Factory\StaticMethod
|
||||
?DescriptionFactory $descriptionFactory = null,
|
||||
?TypeContext $context = null
|
||||
): self {
|
||||
trigger_error(
|
||||
Deprecation::triggerIfCalledFromOutside(
|
||||
'phpdocumentor/reflection-docblock',
|
||||
'https://github.com/phpDocumentor/ReflectionDocBlock/issues/361',
|
||||
'Create using static factory is deprecated, this method should not be called directly
|
||||
by library consumers',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
|
||||
Assert::stringNotEmpty($body);
|
||||
Assert::notNull($typeResolver);
|
||||
Assert::notNull($descriptionFactory);
|
||||
|
||||
@@ -13,6 +13,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
use phpDocumentor\Reflection\DocBlock\Description;
|
||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||
use phpDocumentor\Reflection\Type;
|
||||
@@ -20,10 +21,6 @@ use phpDocumentor\Reflection\TypeResolver;
|
||||
use phpDocumentor\Reflection\Types\Context as TypeContext;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
use function trigger_error;
|
||||
|
||||
use const E_USER_DEPRECATED;
|
||||
|
||||
/**
|
||||
* Reflection class for a {@}return tag in a Docblock.
|
||||
*/
|
||||
@@ -46,11 +43,13 @@ final class Return_ extends TagWithType implements Factory\StaticMethod
|
||||
?DescriptionFactory $descriptionFactory = null,
|
||||
?TypeContext $context = null
|
||||
): self {
|
||||
trigger_error(
|
||||
Deprecation::triggerIfCalledFromOutside(
|
||||
'phpdocumentor/reflection-docblock',
|
||||
'https://github.com/phpDocumentor/ReflectionDocBlock/issues/361',
|
||||
'Create using static factory is deprecated, this method should not be called directly
|
||||
by library consumers',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
|
||||
Assert::notNull($typeResolver);
|
||||
Assert::notNull($descriptionFactory);
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
use phpDocumentor\Reflection\DocBlock\Description;
|
||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||
use phpDocumentor\Reflection\Type;
|
||||
@@ -26,9 +27,7 @@ use function array_unshift;
|
||||
use function implode;
|
||||
use function strpos;
|
||||
use function substr;
|
||||
use function trigger_error;
|
||||
|
||||
use const E_USER_DEPRECATED;
|
||||
use const PREG_SPLIT_DELIM_CAPTURE;
|
||||
|
||||
/**
|
||||
@@ -58,10 +57,11 @@ final class Var_ extends TagWithType implements Factory\StaticMethod
|
||||
?DescriptionFactory $descriptionFactory = null,
|
||||
?TypeContext $context = null
|
||||
): self {
|
||||
trigger_error(
|
||||
Deprecation::triggerIfCalledFromOutside(
|
||||
'phpdocumentor/reflection-docblock',
|
||||
'https://github.com/phpDocumentor/ReflectionDocBlock/issues/361',
|
||||
'Create using static factory is deprecated, this method should not be called directly
|
||||
by library consumers',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
Assert::stringNotEmpty($body);
|
||||
Assert::notNull($typeResolver);
|
||||
|
||||
Reference in New Issue
Block a user