mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 10:07:12 +00:00
Be more strict about type definitions on param
Throw on invalid type definitions and unexpected type definitions. Not all types resolved by phpstan's parser are valid for docblocks, they might in a more complex type system but I do not see how these types would ever apply to param tags.
This commit is contained in:
@@ -7,6 +7,7 @@ namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Param;
|
||||
use phpDocumentor\Reflection\TypeResolver;
|
||||
use phpDocumentor\Reflection\Types\Context;
|
||||
@@ -15,6 +16,7 @@ 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 PHPStan\PhpDocParser\Ast\Type\OffsetAccessTypeNode;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
use function sprintf;
|
||||
@@ -59,6 +61,13 @@ final class ParamFactory implements PHPStanFactory
|
||||
]
|
||||
);
|
||||
|
||||
if (($tagValue->type ?? null) instanceof OffsetAccessTypeNode) {
|
||||
return InvalidTag::create(
|
||||
(string) $tagValue,
|
||||
'param'
|
||||
);
|
||||
}
|
||||
|
||||
return new Param(
|
||||
trim($tagValue->parameterName, '$'),
|
||||
$this->typeResolver->createType($tagValue->type ?? new IdentifierTypeNode('mixed'), $context),
|
||||
|
||||
@@ -13,9 +13,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use phpDocumentor\Reflection\Type;
|
||||
|
||||
use function in_array;
|
||||
use function sprintf;
|
||||
use function strlen;
|
||||
use function substr;
|
||||
use function trim;
|
||||
@@ -59,6 +61,12 @@ abstract class TagWithType extends BaseTag
|
||||
}
|
||||
}
|
||||
|
||||
if ($nestingLevel < 0 || $nestingLevel > 0) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('Could not find type in %s, please check for malformed notations', $body)
|
||||
);
|
||||
}
|
||||
|
||||
$description = trim(substr($body, strlen($type)));
|
||||
|
||||
return [$type, $description];
|
||||
|
||||
Reference in New Issue
Block a user