From 02f9ed7a8f1f0eaa342a71efff4b0a9dd0ad42bb Mon Sep 17 00:00:00 2001 From: Jaapio Date: Tue, 23 Dec 2025 21:51:08 +0100 Subject: [PATCH] Remove deprecated code paths Typed tags are no longer creatable via the create method. The parsing has become to complex to handle per tag. This logic has been moved into factories. --- src/DocBlock/Tags/Author.php | 2 +- src/DocBlock/Tags/Covers.php | 2 +- src/DocBlock/Tags/Deprecated.php | 2 +- src/DocBlock/Tags/Example.php | 2 +- src/DocBlock/Tags/Extends_.php | 18 -- .../Tags/Factory/AbstractPHPStanFactory.php | 1 - src/DocBlock/Tags/Factory/ParamFactory.php | 13 +- src/DocBlock/Tags/Factory/StaticMethod.php | 25 -- src/DocBlock/Tags/Generic.php | 2 +- src/DocBlock/Tags/Implements_.php | 18 -- src/DocBlock/Tags/Link.php | 2 +- src/DocBlock/Tags/Method.php | 2 +- src/DocBlock/Tags/Mixin.php | 2 +- src/DocBlock/Tags/Param.php | 91 +----- src/DocBlock/Tags/Property.php | 66 +---- src/DocBlock/Tags/PropertyRead.php | 66 +---- src/DocBlock/Tags/PropertyWrite.php | 66 +---- src/DocBlock/Tags/Return_.php | 35 +-- src/DocBlock/Tags/See.php | 2 +- src/DocBlock/Tags/Since.php | 2 +- src/DocBlock/Tags/Source.php | 2 +- src/DocBlock/Tags/TagWithType.php | 7 + src/DocBlock/Tags/TemplateCovariant.php | 2 +- src/DocBlock/Tags/Throws.php | 2 +- src/DocBlock/Tags/Uses.php | 2 +- src/DocBlock/Tags/Var_.php | 66 +---- src/DocBlock/Tags/Version.php | 2 +- src/Exception/CannotCreateTag.php | 11 + tests/unit/Assets/CustomParam.php | 3 +- tests/unit/Assets/CustomServiceClass.php | 2 +- tests/unit/Assets/CustomServiceInterface.php | 2 +- .../Tags/Factory/ParamFactoryTest.php | 11 - tests/unit/DocBlock/Tags/ParamTest.php | 275 ------------------ tests/unit/DocBlock/Tags/PropertyReadTest.php | 128 -------- tests/unit/DocBlock/Tags/PropertyTest.php | 123 -------- .../unit/DocBlock/Tags/PropertyWriteTest.php | 128 -------- tests/unit/DocBlock/Tags/ReturnTest.php | 152 ---------- tests/unit/DocBlock/Tags/VarTest.php | 152 ---------- 38 files changed, 43 insertions(+), 1446 deletions(-) delete mode 100644 src/DocBlock/Tags/Factory/StaticMethod.php create mode 100644 src/Exception/CannotCreateTag.php diff --git a/src/DocBlock/Tags/Author.php b/src/DocBlock/Tags/Author.php index 290e5a9..e604ac8 100644 --- a/src/DocBlock/Tags/Author.php +++ b/src/DocBlock/Tags/Author.php @@ -24,7 +24,7 @@ use const FILTER_VALIDATE_EMAIL; /** * Reflection class for an {@}author tag in a Docblock. */ -final class Author extends BaseTag implements Factory\StaticMethod +final class Author extends BaseTag { /** @var string register that this is the author tag. */ protected string $name = 'author'; diff --git a/src/DocBlock/Tags/Covers.php b/src/DocBlock/Tags/Covers.php index 022594e..ba2384f 100644 --- a/src/DocBlock/Tags/Covers.php +++ b/src/DocBlock/Tags/Covers.php @@ -27,7 +27,7 @@ use function explode; /** * Reflection class for a @covers tag in a Docblock. */ -final class Covers extends BaseTag implements Factory\StaticMethod +final class Covers extends BaseTag { protected string $name = 'covers'; diff --git a/src/DocBlock/Tags/Deprecated.php b/src/DocBlock/Tags/Deprecated.php index fff591f..8ae8322 100644 --- a/src/DocBlock/Tags/Deprecated.php +++ b/src/DocBlock/Tags/Deprecated.php @@ -23,7 +23,7 @@ use function preg_match; /** * Reflection class for a {@}deprecated tag in a Docblock. */ -final class Deprecated extends BaseTag implements Factory\StaticMethod +final class Deprecated extends BaseTag { protected string $name = 'deprecated'; diff --git a/src/DocBlock/Tags/Example.php b/src/DocBlock/Tags/Example.php index 3ddbb68..06ecf8c 100644 --- a/src/DocBlock/Tags/Example.php +++ b/src/DocBlock/Tags/Example.php @@ -26,7 +26,7 @@ use function trim; /** * Reflection class for a {@}example tag in a Docblock. */ -final class Example implements Tag, Factory\StaticMethod +final class Example implements Tag { /** @var string Path to a file to use as an example. May also be an absolute URI. */ private string $filePath; diff --git a/src/DocBlock/Tags/Extends_.php b/src/DocBlock/Tags/Extends_.php index 831af03..583d791 100644 --- a/src/DocBlock/Tags/Extends_.php +++ b/src/DocBlock/Tags/Extends_.php @@ -13,9 +13,7 @@ declare(strict_types=1); namespace phpDocumentor\Reflection\DocBlock\Tags; -use Doctrine\Deprecations\Deprecation; use phpDocumentor\Reflection\DocBlock\Description; -use phpDocumentor\Reflection\DocBlock\Tag; use phpDocumentor\Reflection\Type; /** @@ -29,20 +27,4 @@ class Extends_ extends TagWithType $this->type = $type; $this->description = $description; } - - /** - * @deprecated Create using static factory is deprecated, - * this method should not be called directly by library consumers - */ - public static function create(string $body): ?Tag - { - Deprecation::trigger( - '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', - ); - - return null; - } } diff --git a/src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php b/src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php index f061adf..71cd61d 100644 --- a/src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php +++ b/src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php @@ -24,7 +24,6 @@ use PHPStan\PhpDocParser\Parser\TypeParser; use PHPStan\PhpDocParser\ParserConfig; use RuntimeException; -use function class_exists; use function ltrim; use function property_exists; use function rtrim; diff --git a/src/DocBlock/Tags/Factory/ParamFactory.php b/src/DocBlock/Tags/Factory/ParamFactory.php index 7d680d9..a0970d9 100644 --- a/src/DocBlock/Tags/Factory/ParamFactory.php +++ b/src/DocBlock/Tags/Factory/ParamFactory.php @@ -4,7 +4,6 @@ declare(strict_types=1); 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; @@ -20,7 +19,6 @@ use PHPStan\PhpDocParser\Ast\Type\OffsetAccessTypeNode; use Webmozart\Assert\Assert; use function is_string; -use function sprintf; use function trim; /** @@ -42,16 +40,7 @@ final class ParamFactory implements PHPStanFactory $tagValue = $node->value; if ($tagValue instanceof InvalidTagValueNode) { - Deprecation::trigger( - 'phpdocumentor/reflection-docblock', - 'https://github.com/phpDocumentor/ReflectionDocBlock/issues/362', - sprintf( - 'Param tag value "%s" is invalid, falling back to legacy parsing. Please update your docblocks.', - $tagValue->value - ) - ); - - return Param::create($tagValue->value, $this->typeResolver, $this->descriptionFactory, $context); + return InvalidTag::create($tagValue->value, 'param')->withError($tagValue->exception); } Assert::isInstanceOfAny( diff --git a/src/DocBlock/Tags/Factory/StaticMethod.php b/src/DocBlock/Tags/Factory/StaticMethod.php deleted file mode 100644 index f6f0bb5..0000000 --- a/src/DocBlock/Tags/Factory/StaticMethod.php +++ /dev/null @@ -1,25 +0,0 @@ -type = $type; $this->description = $description; } - - /** - * @deprecated Create using static factory is deprecated, - * this method should not be called directly by library consumers - */ - public static function create(string $body): ?Tag - { - Deprecation::trigger( - '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', - ); - - return null; - } } diff --git a/src/DocBlock/Tags/Link.php b/src/DocBlock/Tags/Link.php index fcb6ec1..8ce615d 100644 --- a/src/DocBlock/Tags/Link.php +++ b/src/DocBlock/Tags/Link.php @@ -22,7 +22,7 @@ use Webmozart\Assert\Assert; /** * Reflection class for a {@}link tag in a Docblock. */ -final class Link extends BaseTag implements Factory\StaticMethod +final class Link extends BaseTag { protected string $name = 'link'; diff --git a/src/DocBlock/Tags/Method.php b/src/DocBlock/Tags/Method.php index 41e0eed..d2c0c82 100644 --- a/src/DocBlock/Tags/Method.php +++ b/src/DocBlock/Tags/Method.php @@ -41,7 +41,7 @@ use const E_USER_DEPRECATED; /** * Reflection class for an {@}method in a Docblock. */ -final class Method extends BaseTag implements Factory\StaticMethod +final class Method extends BaseTag { protected string $name = 'method'; diff --git a/src/DocBlock/Tags/Mixin.php b/src/DocBlock/Tags/Mixin.php index c15d30c..4dd8a47 100644 --- a/src/DocBlock/Tags/Mixin.php +++ b/src/DocBlock/Tags/Mixin.php @@ -23,7 +23,7 @@ use Webmozart\Assert\Assert; /** * Reflection class for a {@}mixin tag in a Docblock. */ -final class Mixin extends TagWithType implements Factory\StaticMethod +final class Mixin extends TagWithType { public function __construct(Type $type, ?Description $description = null) { diff --git a/src/DocBlock/Tags/Param.php b/src/DocBlock/Tags/Param.php index 6d46686..bb513ca 100644 --- a/src/DocBlock/Tags/Param.php +++ b/src/DocBlock/Tags/Param.php @@ -13,27 +13,15 @@ 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; -use phpDocumentor\Reflection\TypeResolver; -use phpDocumentor\Reflection\Types\Context as TypeContext; -use phpDocumentor\Reflection\Utils; -use Webmozart\Assert\Assert; -use function array_shift; -use function array_unshift; -use function implode; use function strpos; -use function substr; - -use const PREG_SPLIT_DELIM_CAPTURE; /** * Reflection class for the {@}param tag in a Docblock. */ -final class Param extends TagWithType implements Factory\StaticMethod +final class Param extends TagWithType { private ?string $variableName = null; @@ -58,72 +46,6 @@ final class Param extends TagWithType implements Factory\StaticMethod $this->isReference = $isReference; } - /** - * @deprecated Create using static factory is deprecated, - * this method should not be called directly by library consumers - */ - public static function create( - string $body, - ?TypeResolver $typeResolver = null, - ?DescriptionFactory $descriptionFactory = null, - ?TypeContext $context = null - ): self { - 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', - ); - - Assert::stringNotEmpty($body); - Assert::notNull($typeResolver); - Assert::notNull($descriptionFactory); - - [$firstPart, $body] = self::extractTypeFromBody($body); - - $type = null; - $parts = Utils::pregSplit('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE); - $variableName = ''; - $isVariadic = false; - $isReference = false; - - // if the first item that is encountered is not a variable; it is a type - if ($firstPart && !self::strStartsWithVariable($firstPart)) { - $type = $typeResolver->resolve($firstPart, $context); - } else { - // first part is not a type; we should prepend it to the parts array for further processing - array_unshift($parts, $firstPart); - } - - // if the next item starts with a $ or ...$ or &$ or &...$ it must be the variable name - if (isset($parts[0]) && self::strStartsWithVariable($parts[0])) { - $variableName = array_shift($parts); - if ($type) { - array_shift($parts); - } - - Assert::notNull($variableName); - - if (strpos($variableName, '$') === 0) { - $variableName = substr($variableName, 1); - } elseif (strpos($variableName, '&$') === 0) { - $isReference = true; - $variableName = substr($variableName, 2); - } elseif (strpos($variableName, '...$') === 0) { - $isVariadic = true; - $variableName = substr($variableName, 4); - } elseif (strpos($variableName, '&...$') === 0) { - $isVariadic = true; - $isReference = true; - $variableName = substr($variableName, 5); - } - } - - $description = $descriptionFactory->create(implode('', $parts), $context); - - return new static($variableName, $type, $isVariadic, $description, $isReference); - } - /** * Returns the variable's name. */ @@ -171,15 +93,4 @@ final class Param extends TagWithType implements Factory\StaticMethod . ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '') . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : ''); } - - private static function strStartsWithVariable(string $str): bool - { - return strpos($str, '$') === 0 - || - strpos($str, '...$') === 0 - || - strpos($str, '&$') === 0 - || - strpos($str, '&...$') === 0; - } } diff --git a/src/DocBlock/Tags/Property.php b/src/DocBlock/Tags/Property.php index 3328b08..b7bd958 100644 --- a/src/DocBlock/Tags/Property.php +++ b/src/DocBlock/Tags/Property.php @@ -13,27 +13,14 @@ 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; -use phpDocumentor\Reflection\TypeResolver; -use phpDocumentor\Reflection\Types\Context as TypeContext; -use phpDocumentor\Reflection\Utils; use Webmozart\Assert\Assert; -use function array_shift; -use function array_unshift; -use function implode; -use function strpos; -use function substr; - -use const PREG_SPLIT_DELIM_CAPTURE; - /** * Reflection class for a {@}property tag in a Docblock. */ -final class Property extends TagWithType implements Factory\StaticMethod +final class Property extends TagWithType { protected ?string $variableName = null; @@ -47,57 +34,6 @@ final class Property extends TagWithType implements Factory\StaticMethod $this->description = $description; } - /** - * @deprecated Create using static factory is deprecated, - * this method should not be called directly by library consumers - */ - public static function create( - string $body, - ?TypeResolver $typeResolver = null, - ?DescriptionFactory $descriptionFactory = null, - ?TypeContext $context = null - ): self { - 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', - ); - - Assert::stringNotEmpty($body); - Assert::notNull($typeResolver); - Assert::notNull($descriptionFactory); - - [$firstPart, $body] = self::extractTypeFromBody($body); - $type = null; - $parts = Utils::pregSplit('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE); - $variableName = ''; - - // if the first item that is encountered is not a variable; it is a type - if ($firstPart && $firstPart[0] !== '$') { - $type = $typeResolver->resolve($firstPart, $context); - } else { - // first part is not a type; we should prepend it to the parts array for further processing - array_unshift($parts, $firstPart); - } - - // if the next item starts with a $ it must be the variable name - if (isset($parts[0]) && strpos($parts[0], '$') === 0) { - $variableName = array_shift($parts); - if ($type) { - array_shift($parts); - } - - Assert::notNull($variableName); - - $variableName = substr($variableName, 1); - } - - $description = $descriptionFactory->create(implode('', $parts), $context); - - return new static($variableName, $type, $description); - } - /** * Returns the variable's name. */ diff --git a/src/DocBlock/Tags/PropertyRead.php b/src/DocBlock/Tags/PropertyRead.php index 8ac1eb0..bcb0e0d 100644 --- a/src/DocBlock/Tags/PropertyRead.php +++ b/src/DocBlock/Tags/PropertyRead.php @@ -13,27 +13,14 @@ 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; -use phpDocumentor\Reflection\TypeResolver; -use phpDocumentor\Reflection\Types\Context as TypeContext; -use phpDocumentor\Reflection\Utils; use Webmozart\Assert\Assert; -use function array_shift; -use function array_unshift; -use function implode; -use function strpos; -use function substr; - -use const PREG_SPLIT_DELIM_CAPTURE; - /** * Reflection class for a {@}property-read tag in a Docblock. */ -final class PropertyRead extends TagWithType implements Factory\StaticMethod +final class PropertyRead extends TagWithType { protected ?string $variableName = null; @@ -47,57 +34,6 @@ final class PropertyRead extends TagWithType implements Factory\StaticMethod $this->description = $description; } - /** - * @deprecated Create using static factory is deprecated, - * this method should not be called directly by library consumers - */ - public static function create( - string $body, - ?TypeResolver $typeResolver = null, - ?DescriptionFactory $descriptionFactory = null, - ?TypeContext $context = null - ): self { - 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', - ); - - Assert::stringNotEmpty($body); - Assert::notNull($typeResolver); - Assert::notNull($descriptionFactory); - - [$firstPart, $body] = self::extractTypeFromBody($body); - $type = null; - $parts = Utils::pregSplit('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE); - $variableName = ''; - - // if the first item that is encountered is not a variable; it is a type - if ($firstPart && $firstPart[0] !== '$') { - $type = $typeResolver->resolve($firstPart, $context); - } else { - // first part is not a type; we should prepend it to the parts array for further processing - array_unshift($parts, $firstPart); - } - - // if the next item starts with a $ it must be the variable name - if (isset($parts[0]) && strpos($parts[0], '$') === 0) { - $variableName = array_shift($parts); - if ($type) { - array_shift($parts); - } - - Assert::notNull($variableName); - - $variableName = substr($variableName, 1); - } - - $description = $descriptionFactory->create(implode('', $parts), $context); - - return new static($variableName, $type, $description); - } - /** * Returns the variable's name. */ diff --git a/src/DocBlock/Tags/PropertyWrite.php b/src/DocBlock/Tags/PropertyWrite.php index 57e7eb1..a5ee9e9 100644 --- a/src/DocBlock/Tags/PropertyWrite.php +++ b/src/DocBlock/Tags/PropertyWrite.php @@ -13,27 +13,14 @@ 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; -use phpDocumentor\Reflection\TypeResolver; -use phpDocumentor\Reflection\Types\Context as TypeContext; -use phpDocumentor\Reflection\Utils; use Webmozart\Assert\Assert; -use function array_shift; -use function array_unshift; -use function implode; -use function strpos; -use function substr; - -use const PREG_SPLIT_DELIM_CAPTURE; - /** * Reflection class for a {@}property-write tag in a Docblock. */ -final class PropertyWrite extends TagWithType implements Factory\StaticMethod +final class PropertyWrite extends TagWithType { protected string $variableName; @@ -47,57 +34,6 @@ final class PropertyWrite extends TagWithType implements Factory\StaticMethod $this->description = $description; } - /** - * @deprecated Create using static factory is deprecated, - * this method should not be called directly by library consumers - */ - public static function create( - string $body, - ?TypeResolver $typeResolver = null, - ?DescriptionFactory $descriptionFactory = null, - ?TypeContext $context = null - ): self { - 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', - ); - - Assert::stringNotEmpty($body); - Assert::notNull($typeResolver); - Assert::notNull($descriptionFactory); - - [$firstPart, $body] = self::extractTypeFromBody($body); - $type = null; - $parts = Utils::pregSplit('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE); - $variableName = ''; - - // if the first item that is encountered is not a variable; it is a type - if ($firstPart && $firstPart[0] !== '$') { - $type = $typeResolver->resolve($firstPart, $context); - } else { - // first part is not a type; we should prepend it to the parts array for further processing - array_unshift($parts, $firstPart); - } - - // if the next item starts with a $ it must be the variable name - if (isset($parts[0]) && strpos($parts[0], '$') === 0) { - $variableName = array_shift($parts); - if ($type) { - array_shift($parts); - } - - Assert::notNull($variableName); - - $variableName = substr($variableName, 1); - } - - $description = $descriptionFactory->create(implode('', $parts), $context); - - return new static($variableName, $type, $description); - } - /** * Returns the variable's name. */ diff --git a/src/DocBlock/Tags/Return_.php b/src/DocBlock/Tags/Return_.php index 7e9b0c7..bc93a79 100644 --- a/src/DocBlock/Tags/Return_.php +++ b/src/DocBlock/Tags/Return_.php @@ -13,18 +13,13 @@ 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; -use phpDocumentor\Reflection\TypeResolver; -use phpDocumentor\Reflection\Types\Context as TypeContext; -use Webmozart\Assert\Assert; /** * Reflection class for a {@}return tag in a Docblock. */ -final class Return_ extends TagWithType implements Factory\StaticMethod +final class Return_ extends TagWithType { public function __construct(Type $type, ?Description $description = null) { @@ -32,32 +27,4 @@ final class Return_ extends TagWithType implements Factory\StaticMethod $this->type = $type; $this->description = $description; } - - /** - * @deprecated Create using static factory is deprecated, - * this method should not be called directly by library consumers - */ - public static function create( - string $body, - ?TypeResolver $typeResolver = null, - ?DescriptionFactory $descriptionFactory = null, - ?TypeContext $context = null - ): self { - 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', - ); - - Assert::notNull($typeResolver); - Assert::notNull($descriptionFactory); - - [$type, $description] = self::extractTypeFromBody($body); - - $type = $typeResolver->resolve($type, $context); - $description = $descriptionFactory->create($description, $context); - - return new static($type, $description); - } } diff --git a/src/DocBlock/Tags/See.php b/src/DocBlock/Tags/See.php index e7330e8..f8242d4 100644 --- a/src/DocBlock/Tags/See.php +++ b/src/DocBlock/Tags/See.php @@ -31,7 +31,7 @@ use function preg_match; /** * Reflection class for an {@}see tag in a Docblock. */ -final class See extends BaseTag implements Factory\StaticMethod +final class See extends BaseTag { protected string $name = 'see'; diff --git a/src/DocBlock/Tags/Since.php b/src/DocBlock/Tags/Since.php index 8ec59e9..abfc750 100644 --- a/src/DocBlock/Tags/Since.php +++ b/src/DocBlock/Tags/Since.php @@ -23,7 +23,7 @@ use function preg_match; /** * Reflection class for a {@}since tag in a Docblock. */ -final class Since extends BaseTag implements Factory\StaticMethod +final class Since extends BaseTag { protected string $name = 'since'; diff --git a/src/DocBlock/Tags/Source.php b/src/DocBlock/Tags/Source.php index f6b4f57..71eefcd 100644 --- a/src/DocBlock/Tags/Source.php +++ b/src/DocBlock/Tags/Source.php @@ -23,7 +23,7 @@ use function preg_match; /** * Reflection class for a {@}source tag in a Docblock. */ -final class Source extends BaseTag implements Factory\StaticMethod +final class Source extends BaseTag { protected string $name = 'source'; diff --git a/src/DocBlock/Tags/TagWithType.php b/src/DocBlock/Tags/TagWithType.php index 89e29e5..2923cf2 100644 --- a/src/DocBlock/Tags/TagWithType.php +++ b/src/DocBlock/Tags/TagWithType.php @@ -14,6 +14,8 @@ declare(strict_types=1); namespace phpDocumentor\Reflection\DocBlock\Tags; use InvalidArgumentException; +use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\Exception\CannotCreateTag; use phpDocumentor\Reflection\Type; use function in_array; @@ -35,6 +37,11 @@ abstract class TagWithType extends BaseTag return $this->type; } + public static function create(string $body): Tag + { + throw new CannotCreateTag('Typed tag cannot be created'); + } + /** * @return string[] */ diff --git a/src/DocBlock/Tags/TemplateCovariant.php b/src/DocBlock/Tags/TemplateCovariant.php index d5d5098..9a0bfc3 100644 --- a/src/DocBlock/Tags/TemplateCovariant.php +++ b/src/DocBlock/Tags/TemplateCovariant.php @@ -23,7 +23,7 @@ use Webmozart\Assert\Assert; /** * Reflection class for a {@}template-covariant tag in a Docblock. */ -final class TemplateCovariant extends TagWithType implements Factory\StaticMethod +final class TemplateCovariant extends TagWithType { public function __construct(Type $type, ?Description $description = null) { diff --git a/src/DocBlock/Tags/Throws.php b/src/DocBlock/Tags/Throws.php index e081846..6ce75de 100644 --- a/src/DocBlock/Tags/Throws.php +++ b/src/DocBlock/Tags/Throws.php @@ -23,7 +23,7 @@ use Webmozart\Assert\Assert; /** * Reflection class for a {@}throws tag in a Docblock. */ -final class Throws extends TagWithType implements Factory\StaticMethod +final class Throws extends TagWithType { public function __construct(Type $type, ?Description $description = null) { diff --git a/src/DocBlock/Tags/Uses.php b/src/DocBlock/Tags/Uses.php index d9aa360..8a9849a 100644 --- a/src/DocBlock/Tags/Uses.php +++ b/src/DocBlock/Tags/Uses.php @@ -27,7 +27,7 @@ use function explode; /** * Reflection class for a {@}uses tag in a Docblock. */ -final class Uses extends BaseTag implements Factory\StaticMethod +final class Uses extends BaseTag { protected string $name = 'uses'; diff --git a/src/DocBlock/Tags/Var_.php b/src/DocBlock/Tags/Var_.php index b0bd8c2..495d16f 100644 --- a/src/DocBlock/Tags/Var_.php +++ b/src/DocBlock/Tags/Var_.php @@ -13,27 +13,14 @@ 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; -use phpDocumentor\Reflection\TypeResolver; -use phpDocumentor\Reflection\Types\Context as TypeContext; -use phpDocumentor\Reflection\Utils; use Webmozart\Assert\Assert; -use function array_shift; -use function array_unshift; -use function implode; -use function strpos; -use function substr; - -use const PREG_SPLIT_DELIM_CAPTURE; - /** * Reflection class for a {@}var tag in a Docblock. */ -final class Var_ extends TagWithType implements Factory\StaticMethod +final class Var_ extends TagWithType { protected ?string $variableName = ''; @@ -47,57 +34,6 @@ final class Var_ extends TagWithType implements Factory\StaticMethod $this->description = $description; } - /** - * @deprecated Create using static factory is deprecated, - * this method should not be called directly by library consumers - */ - public static function create( - string $body, - ?TypeResolver $typeResolver = null, - ?DescriptionFactory $descriptionFactory = null, - ?TypeContext $context = null - ): self { - 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', - ); - Assert::stringNotEmpty($body); - Assert::notNull($typeResolver); - Assert::notNull($descriptionFactory); - - [$firstPart, $body] = self::extractTypeFromBody($body); - - $parts = Utils::pregSplit('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE); - $type = null; - $variableName = ''; - - // if the first item that is encountered is not a variable; it is a type - if ($firstPart && $firstPart[0] !== '$') { - $type = $typeResolver->resolve($firstPart, $context); - } else { - // first part is not a type; we should prepend it to the parts array for further processing - array_unshift($parts, $firstPart); - } - - // if the next item starts with a $ it must be the variable name - if (isset($parts[0]) && strpos($parts[0], '$') === 0) { - $variableName = array_shift($parts); - if ($type) { - array_shift($parts); - } - - Assert::notNull($variableName); - - $variableName = substr($variableName, 1); - } - - $description = $descriptionFactory->create(implode('', $parts), $context); - - return new static($variableName, $type, $description); - } - /** * Returns the variable's name. */ diff --git a/src/DocBlock/Tags/Version.php b/src/DocBlock/Tags/Version.php index 8ea96ed..951c8e5 100644 --- a/src/DocBlock/Tags/Version.php +++ b/src/DocBlock/Tags/Version.php @@ -23,7 +23,7 @@ use function preg_match; /** * Reflection class for a {@}version tag in a Docblock. */ -final class Version extends BaseTag implements Factory\StaticMethod +final class Version extends BaseTag { protected string $name = 'version'; diff --git a/src/Exception/CannotCreateTag.php b/src/Exception/CannotCreateTag.php new file mode 100644 index 0000000..a66884a --- /dev/null +++ b/src/Exception/CannotCreateTag.php @@ -0,0 +1,11 @@ +assertSame('string ...$myParameter Description', (string) $fixture); } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethod(): void - { - $typeResolver = new TypeResolver(); - $descriptionFactory = m::mock(DescriptionFactory::class); - $context = new Context(''); - - $description = new Description('My Description'); - $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); - - $fixture = Param::create('string $myParameter My Description', $typeResolver, $descriptionFactory, $context); - - $this->assertSame('string $myParameter My Description', (string) $fixture); - $this->assertSame('myParameter', $fixture->getVariableName()); - $this->assertInstanceOf(String_::class, $fixture->getType()); - $this->assertFalse($fixture->isVariadic()); - $this->assertFalse($fixture->isReference()); - $this->assertSame($description, $fixture->getDescription()); - } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethodWithVariadic(): void - { - $typeResolver = new TypeResolver(); - $descriptionFactory = m::mock(DescriptionFactory::class); - $context = new Context(''); - - $description = new Description('My Description'); - $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); - - $fixture = Param::create('string ...$myParameter My Description', $typeResolver, $descriptionFactory, $context); - - $this->assertSame('string ...$myParameter My Description', (string) $fixture); - $this->assertSame('myParameter', $fixture->getVariableName()); - $this->assertInstanceOf(String_::class, $fixture->getType()); - $this->assertTrue($fixture->isVariadic()); - $this->assertFalse($fixture->isReference()); - $this->assertSame($description, $fixture->getDescription()); - } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethodWithReference(): void - { - $typeResolver = new TypeResolver(); - $descriptionFactory = m::mock(DescriptionFactory::class); - $context = new Context(''); - - $description = new Description('My Description'); - $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); - - $fixture = Param::create('string &$myParameter My Description', $typeResolver, $descriptionFactory, $context); - - $this->assertSame('string &$myParameter My Description', (string) $fixture); - $this->assertSame('myParameter', $fixture->getVariableName()); - $this->assertInstanceOf(String_::class, $fixture->getType()); - $this->assertFalse($fixture->isVariadic()); - $this->assertTrue($fixture->isReference()); - $this->assertSame($description, $fixture->getDescription()); - } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethodWithVariadicReference(): void - { - $typeResolver = new TypeResolver(); - $descriptionFactory = m::mock(DescriptionFactory::class); - $context = new Context(''); - - $description = new Description('My Description'); - $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); - - $fixture = Param::create( - 'string &...$myParameter My Description', - $typeResolver, - $descriptionFactory, - $context - ); - - $this->assertSame('string &...$myParameter My Description', (string) $fixture); - $this->assertSame('myParameter', $fixture->getVariableName()); - $this->assertInstanceOf(String_::class, $fixture->getType()); - $this->assertTrue($fixture->isVariadic()); - $this->assertTrue($fixture->isReference()); - $this->assertSame($description, $fixture->getDescription()); - } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethodWithReferenceWithoutType(): void - { - $typeResolver = new TypeResolver(); - $fqsenResolver = new FqsenResolver(); - $tagFactory = new StandardTagFactory($fqsenResolver); - $descriptionFactory = new DescriptionFactory($tagFactory); - $context = new Context(''); - - $fixture = Param::create( - '&$myParameter My Description', - $typeResolver, - $descriptionFactory, - $context - ); - - $this->assertSame('&$myParameter My Description', (string) $fixture); - $this->assertSame('myParameter', $fixture->getVariableName()); - $this->assertNull($fixture->getType()); - $this->assertFalse($fixture->isVariadic()); - $this->assertTrue($fixture->isReference()); - $this->assertSame('My Description', $fixture->getDescription() . ''); - } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethodWithVariadicReferenceWithoutType(): void - { - $typeResolver = new TypeResolver(); - $fqsenResolver = new FqsenResolver(); - $tagFactory = new StandardTagFactory($fqsenResolver); - $descriptionFactory = new DescriptionFactory($tagFactory); - $context = new Context(''); - - $fixture = Param::create( - '&...$myParameter My Description', - $typeResolver, - $descriptionFactory, - $context - ); - - $this->assertSame('&...$myParameter My Description', (string) $fixture); - $this->assertSame('myParameter', $fixture->getVariableName()); - $this->assertNull($fixture->getType()); - $this->assertTrue($fixture->isVariadic()); - $this->assertTrue($fixture->isReference()); - $this->assertSame('My Description', $fixture->getDescription() . ''); - } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethodWithoutType(): void - { - $typeResolver = new TypeResolver(); - $fqsenResolver = new FqsenResolver(); - $tagFactory = new StandardTagFactory($fqsenResolver); - $descriptionFactory = new DescriptionFactory($tagFactory); - $context = new Context(''); - - $fixture = Param::create( - '$myParameter My Description', - $typeResolver, - $descriptionFactory, - $context - ); - - $this->assertSame('$myParameter My Description', (string) $fixture); - $this->assertSame('myParameter', $fixture->getVariableName()); - $this->assertNull($fixture->getType()); - $this->assertFalse($fixture->isVariadic()); - $this->assertFalse($fixture->isReference()); - $this->assertSame('My Description', $fixture->getDescription() . ''); - } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethodWithType(): void - { - $typeResolver = new TypeResolver(); - $fqsenResolver = new FqsenResolver(); - $tagFactory = new StandardTagFactory($fqsenResolver); - $descriptionFactory = new DescriptionFactory($tagFactory); - $context = new Context(''); - - $fixture = Param::create( - 'int My Description', - $typeResolver, - $descriptionFactory, - $context - ); - - $this->assertSame('int My Description', (string) $fixture); - $this->assertSame('', $fixture->getVariableName()); - $this->assertInstanceOf(Integer::class, $fixture->getType()); - $this->assertSame('My Description', $fixture->getDescription() . ''); - } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: - * @uses \phpDocumentor\Reflection\TypeResolver - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * - * @covers ::create - */ - public function testFactoryMethodFailsIfEmptyBodyIsGiven(): void - { - $this->expectException('InvalidArgumentException'); - $descriptionFactory = m::mock(DescriptionFactory::class); - Param::create('', new TypeResolver(), $descriptionFactory); - } - - /** - * @covers ::create - */ - public function testFactoryMethodFailsIfResolverIsNull(): void - { - $this->expectException('InvalidArgumentException'); - Param::create('body'); - } - - /** - * @uses \phpDocumentor\Reflection\TypeResolver - * - * @covers ::create - */ - public function testFactoryMethodFailsIfDescriptionFactoryIsNull(): void - { - $this->expectException('InvalidArgumentException'); - Param::create('body', new TypeResolver()); - } } diff --git a/tests/unit/DocBlock/Tags/PropertyReadTest.php b/tests/unit/DocBlock/Tags/PropertyReadTest.php index fba5cea..cb1d20c 100644 --- a/tests/unit/DocBlock/Tags/PropertyReadTest.php +++ b/tests/unit/DocBlock/Tags/PropertyReadTest.php @@ -15,12 +15,6 @@ namespace phpDocumentor\Reflection\DocBlock\Tags; use Mockery as m; use phpDocumentor\Reflection\DocBlock\Description; -use phpDocumentor\Reflection\DocBlock\DescriptionFactory; -use phpDocumentor\Reflection\DocBlock\StandardTagFactory; -use phpDocumentor\Reflection\FqsenResolver; -use phpDocumentor\Reflection\TypeResolver; -use phpDocumentor\Reflection\Types\Context; -use phpDocumentor\Reflection\Types\Integer; use phpDocumentor\Reflection\Types\String_; use PHPUnit\Framework\TestCase; @@ -141,126 +135,4 @@ class PropertyReadTest extends TestCase $this->assertSame('string $myProperty Description', (string) $fixture); } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\PropertyRead:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethod(): void - { - $typeResolver = new TypeResolver(); - $descriptionFactory = m::mock(DescriptionFactory::class); - $context = new Context(''); - - $description = new Description('My Description'); - $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); - - $fixture = PropertyRead::create( - 'string $myProperty My Description', - $typeResolver, - $descriptionFactory, - $context - ); - - $this->assertSame('string $myProperty My Description', (string) $fixture); - $this->assertSame('myProperty', $fixture->getVariableName()); - $this->assertInstanceOf(String_::class, $fixture->getType()); - $this->assertSame($description, $fixture->getDescription()); - } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethodWithoutType(): void - { - $typeResolver = new TypeResolver(); - $fqsenResolver = new FqsenResolver(); - $tagFactory = new StandardTagFactory($fqsenResolver); - $descriptionFactory = new DescriptionFactory($tagFactory); - $context = new Context(''); - - $fixture = PropertyRead::create( - '$myParameter My Description', - $typeResolver, - $descriptionFactory, - $context - ); - - $this->assertSame('$myParameter My Description', (string) $fixture); - $this->assertSame('myParameter', $fixture->getVariableName()); - $this->assertNull($fixture->getType()); - $this->assertSame('My Description', $fixture->getDescription() . ''); - } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethodWithType(): void - { - $typeResolver = new TypeResolver(); - $fqsenResolver = new FqsenResolver(); - $tagFactory = new StandardTagFactory($fqsenResolver); - $descriptionFactory = new DescriptionFactory($tagFactory); - $context = new Context(''); - - $fixture = PropertyRead::create( - 'int My Description', - $typeResolver, - $descriptionFactory, - $context - ); - - $this->assertSame('int My Description', (string) $fixture); - $this->assertSame('', $fixture->getVariableName()); - $this->assertInstanceOf(Integer::class, $fixture->getType()); - $this->assertSame('My Description', $fixture->getDescription() . ''); - } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\PropertyRead:: - * @uses \phpDocumentor\Reflection\TypeResolver - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * - * @covers ::create - */ - public function testFactoryMethodFailsIfEmptyBodyIsGiven(): void - { - $this->expectException('InvalidArgumentException'); - $descriptionFactory = m::mock(DescriptionFactory::class); - PropertyRead::create('', new TypeResolver(), $descriptionFactory); - } - - /** - * @covers ::create - */ - public function testFactoryMethodFailsIfResolverIsNull(): void - { - $this->expectException('InvalidArgumentException'); - PropertyRead::create('body'); - } - - /** - * @uses \phpDocumentor\Reflection\TypeResolver - * - * @covers ::create - */ - public function testFactoryMethodFailsIfDescriptionFactoryIsNull(): void - { - $this->expectException('InvalidArgumentException'); - PropertyRead::create('body', new TypeResolver()); - } } diff --git a/tests/unit/DocBlock/Tags/PropertyTest.php b/tests/unit/DocBlock/Tags/PropertyTest.php index ea0180c..99ee730 100644 --- a/tests/unit/DocBlock/Tags/PropertyTest.php +++ b/tests/unit/DocBlock/Tags/PropertyTest.php @@ -15,12 +15,6 @@ namespace phpDocumentor\Reflection\DocBlock\Tags; use Mockery as m; use phpDocumentor\Reflection\DocBlock\Description; -use phpDocumentor\Reflection\DocBlock\DescriptionFactory; -use phpDocumentor\Reflection\DocBlock\StandardTagFactory; -use phpDocumentor\Reflection\FqsenResolver; -use phpDocumentor\Reflection\TypeResolver; -use phpDocumentor\Reflection\Types\Context; -use phpDocumentor\Reflection\Types\Integer; use phpDocumentor\Reflection\Types\String_; use PHPUnit\Framework\TestCase; @@ -141,121 +135,4 @@ class PropertyTest extends TestCase $this->assertSame('string $myProperty Description', (string) $fixture); } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Property:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethod(): void - { - $typeResolver = new TypeResolver(); - $descriptionFactory = m::mock(DescriptionFactory::class); - $context = new Context(''); - - $description = new Description('My Description'); - $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); - - $fixture = Property::create('string $myProperty My Description', $typeResolver, $descriptionFactory, $context); - - $this->assertSame('string $myProperty My Description', (string) $fixture); - $this->assertSame('myProperty', $fixture->getVariableName()); - $this->assertInstanceOf(String_::class, $fixture->getType()); - $this->assertSame($description, $fixture->getDescription()); - } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethodWithoutType(): void - { - $typeResolver = new TypeResolver(); - $fqsenResolver = new FqsenResolver(); - $tagFactory = new StandardTagFactory($fqsenResolver); - $descriptionFactory = new DescriptionFactory($tagFactory); - $context = new Context(''); - - $fixture = Property::create( - '$myParameter My Description', - $typeResolver, - $descriptionFactory, - $context - ); - - $this->assertSame('$myParameter My Description', (string) $fixture); - $this->assertSame('myParameter', $fixture->getVariableName()); - $this->assertNull($fixture->getType()); - $this->assertSame('My Description', $fixture->getDescription() . ''); - } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethodWithType(): void - { - $typeResolver = new TypeResolver(); - $fqsenResolver = new FqsenResolver(); - $tagFactory = new StandardTagFactory($fqsenResolver); - $descriptionFactory = new DescriptionFactory($tagFactory); - $context = new Context(''); - - $fixture = Property::create( - 'int My Description', - $typeResolver, - $descriptionFactory, - $context - ); - - $this->assertSame('int My Description', (string) $fixture); - $this->assertSame('', $fixture->getVariableName()); - $this->assertInstanceOf(Integer::class, $fixture->getType()); - $this->assertSame('My Description', $fixture->getDescription() . ''); - } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Property:: - * @uses \phpDocumentor\Reflection\TypeResolver - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * - * @covers ::create - */ - public function testFactoryMethodFailsIfEmptyBodyIsGiven(): void - { - $this->expectException('InvalidArgumentException'); - $descriptionFactory = m::mock(DescriptionFactory::class); - Property::create('', new TypeResolver(), $descriptionFactory); - } - - /** - * @covers ::create - */ - public function testFactoryMethodFailsIfResolverIsNull(): void - { - $this->expectException('InvalidArgumentException'); - Property::create('body'); - } - - /** - * @uses \phpDocumentor\Reflection\TypeResolver - * - * @covers ::create - */ - public function testFactoryMethodFailsIfDescriptionFactoryIsNull(): void - { - $this->expectException('InvalidArgumentException'); - Property::create('body', new TypeResolver()); - } } diff --git a/tests/unit/DocBlock/Tags/PropertyWriteTest.php b/tests/unit/DocBlock/Tags/PropertyWriteTest.php index 47d9bdd..c627d98 100644 --- a/tests/unit/DocBlock/Tags/PropertyWriteTest.php +++ b/tests/unit/DocBlock/Tags/PropertyWriteTest.php @@ -15,12 +15,6 @@ namespace phpDocumentor\Reflection\DocBlock\Tags; use Mockery as m; use phpDocumentor\Reflection\DocBlock\Description; -use phpDocumentor\Reflection\DocBlock\DescriptionFactory; -use phpDocumentor\Reflection\DocBlock\StandardTagFactory; -use phpDocumentor\Reflection\FqsenResolver; -use phpDocumentor\Reflection\TypeResolver; -use phpDocumentor\Reflection\Types\Context; -use phpDocumentor\Reflection\Types\Integer; use phpDocumentor\Reflection\Types\String_; use PHPUnit\Framework\TestCase; @@ -141,126 +135,4 @@ class PropertyWriteTest extends TestCase $this->assertSame('string $myProperty Description', (string) $fixture); } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\PropertyWrite:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethod(): void - { - $typeResolver = new TypeResolver(); - $descriptionFactory = m::mock(DescriptionFactory::class); - $context = new Context(''); - - $description = new Description('My Description'); - $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); - - $fixture = PropertyWrite::create( - 'string $myProperty My Description', - $typeResolver, - $descriptionFactory, - $context - ); - - $this->assertSame('string $myProperty My Description', (string) $fixture); - $this->assertSame('myProperty', $fixture->getVariableName()); - $this->assertInstanceOf(String_::class, $fixture->getType()); - $this->assertSame($description, $fixture->getDescription()); - } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethodWithoutType(): void - { - $typeResolver = new TypeResolver(); - $fqsenResolver = new FqsenResolver(); - $tagFactory = new StandardTagFactory($fqsenResolver); - $descriptionFactory = new DescriptionFactory($tagFactory); - $context = new Context(''); - - $fixture = PropertyWrite::create( - '$myParameter My Description', - $typeResolver, - $descriptionFactory, - $context - ); - - $this->assertSame('$myParameter My Description', (string) $fixture); - $this->assertSame('myParameter', $fixture->getVariableName()); - $this->assertNull($fixture->getType()); - $this->assertSame('My Description', $fixture->getDescription() . ''); - } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethodWithType(): void - { - $typeResolver = new TypeResolver(); - $fqsenResolver = new FqsenResolver(); - $tagFactory = new StandardTagFactory($fqsenResolver); - $descriptionFactory = new DescriptionFactory($tagFactory); - $context = new Context(''); - - $fixture = PropertyWrite::create( - 'int My Description', - $typeResolver, - $descriptionFactory, - $context - ); - - $this->assertSame('int My Description', (string) $fixture); - $this->assertSame('', $fixture->getVariableName()); - $this->assertInstanceOf(Integer::class, $fixture->getType()); - $this->assertSame('My Description', $fixture->getDescription() . ''); - } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\PropertyWrite:: - * @uses \phpDocumentor\Reflection\TypeResolver - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * - * @covers ::create - */ - public function testFactoryMethodFailsIfEmptyBodyIsGiven(): void - { - $this->expectException('InvalidArgumentException'); - $descriptionFactory = m::mock(DescriptionFactory::class); - PropertyWrite::create('', new TypeResolver(), $descriptionFactory); - } - - /** - * @covers ::create - */ - public function testFactoryMethodFailsIfResolverIsNull(): void - { - $this->expectException('InvalidArgumentException'); - PropertyWrite::create('body'); - } - - /** - * @uses \phpDocumentor\Reflection\TypeResolver - * - * @covers ::create - */ - public function testFactoryMethodFailsIfDescriptionFactoryIsNull(): void - { - $this->expectException('InvalidArgumentException'); - PropertyWrite::create('body', new TypeResolver()); - } } diff --git a/tests/unit/DocBlock/Tags/ReturnTest.php b/tests/unit/DocBlock/Tags/ReturnTest.php index 5f7787f..4da4139 100644 --- a/tests/unit/DocBlock/Tags/ReturnTest.php +++ b/tests/unit/DocBlock/Tags/ReturnTest.php @@ -13,12 +13,8 @@ declare(strict_types=1); namespace phpDocumentor\Reflection\DocBlock\Tags; -use InvalidArgumentException; use Mockery as m; use phpDocumentor\Reflection\DocBlock\Description; -use phpDocumentor\Reflection\DocBlock\DescriptionFactory; -use phpDocumentor\Reflection\TypeResolver; -use phpDocumentor\Reflection\Types\Context; use phpDocumentor\Reflection\Types\String_; use PHPUnit\Framework\TestCase; @@ -140,152 +136,4 @@ class ReturnTest extends TestCase $this->assertSame('string', (string) $fixture); } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Return_:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\TypeResolver - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\String_ - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethod(): void - { - $descriptionFactory = m::mock(DescriptionFactory::class); - $resolver = new TypeResolver(); - $context = new Context(''); - - $type = new String_(); - $description = new Description('My Description'); - $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); - - $fixture = Return_::create('string My Description', $resolver, $descriptionFactory, $context); - - $this->assertSame('string My Description', (string) $fixture); - $this->assertEquals($type, $fixture->getType()); - $this->assertSame($description, $fixture->getDescription()); - } - - /** - * This test checks whether a braces in a Type are allowed. - * - * The advent of generics poses a few issues, one of them is that spaces can now be part of a type. In the past we - * could purely rely on spaces to split the individual parts of the body of a tag; but when there is a type in play - * we now need to check for braces. - * - * This test tests whether an error occurs demonstrating that the braces were taken into account; this test is still - * expected to produce an exception because the TypeResolver does not support generics. - * - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Return_:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\TypeResolver - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\String_ - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethodWithGenericWithSpace(): void - { - $descriptionFactory = m::mock(DescriptionFactory::class); - $resolver = new TypeResolver(); - $context = new Context(''); - - $description = new Description('My Description'); - $descriptionFactory->shouldReceive('create') - ->with('My Description', $context) - ->andReturn($description); - - $fixture = Return_::create('array My Description', $resolver, $descriptionFactory, $context); - - $this->assertSame('array My Description', (string) $fixture); - $this->assertEquals('array', $fixture->getType()); - $this->assertSame($description, $fixture->getDescription()); - } - - /** - * @see self::testFactoryMethodWithGenericWithSpace() - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Return_:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\TypeResolver - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\String_ - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethodWithGenericWithSpaceAndAddedEmojisToVerifyMultiByteBehaviour(): void - { - $this->markTestSkipped('A bug in the TypeResolver breaks this test'); - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('"\array😁" is not a valid Fqsen.'); - - $descriptionFactory = m::mock(DescriptionFactory::class); - $resolver = new TypeResolver(); - $context = new Context(''); - - $description = new Description('My Description'); - $descriptionFactory->shouldReceive('create') - ->with('My Description', $context) - ->andReturn($description); - - Return_::create('array😁 My Description', $resolver, $descriptionFactory, $context); - } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Return_:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\TypeResolver - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\String_ - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethodWithEmojisToVerifyMultiByteBehaviour(): void - { - $descriptionFactory = m::mock(DescriptionFactory::class); - $resolver = new TypeResolver(); - $context = new Context(''); - - $description = new Description('My Description'); - $descriptionFactory->shouldReceive('create') - ->with('My Description', $context) - ->andReturn($description); - - $fixture = Return_::create('\My😁Class My Description', $resolver, $descriptionFactory, $context); - - $this->assertSame('\My😁Class My Description', (string) $fixture); - $this->assertEquals('\My😁Class', $fixture->getType()); - $this->assertSame($description, $fixture->getDescription()); - } - - /** - * @covers ::create - */ - public function testFactoryMethodFailsIfBodyIsNotEmpty(): void - { - $this->expectException('InvalidArgumentException'); - $this->assertNull(Return_::create('')); - } - - /** - * @covers ::create - */ - public function testFactoryMethodFailsIfResolverIsNull(): void - { - $this->expectException('InvalidArgumentException'); - Return_::create('body'); - } - - /** - * @covers ::create - */ - public function testFactoryMethodFailsIfDescriptionFactoryIsNull(): void - { - $this->expectException('InvalidArgumentException'); - Return_::create('body', new TypeResolver()); - } } diff --git a/tests/unit/DocBlock/Tags/VarTest.php b/tests/unit/DocBlock/Tags/VarTest.php index 00af8ae..bb19105 100644 --- a/tests/unit/DocBlock/Tags/VarTest.php +++ b/tests/unit/DocBlock/Tags/VarTest.php @@ -15,12 +15,6 @@ namespace phpDocumentor\Reflection\DocBlock\Tags; use Mockery as m; use phpDocumentor\Reflection\DocBlock\Description; -use phpDocumentor\Reflection\DocBlock\DescriptionFactory; -use phpDocumentor\Reflection\DocBlock\StandardTagFactory; -use phpDocumentor\Reflection\FqsenResolver; -use phpDocumentor\Reflection\TypeResolver; -use phpDocumentor\Reflection\Types\Context; -use phpDocumentor\Reflection\Types\Integer; use phpDocumentor\Reflection\Types\String_; use PHPUnit\Framework\TestCase; @@ -179,150 +173,4 @@ class VarTest extends TestCase $this->assertSame('string $myVariable', (string) $fixture); } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Var_:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethod(): void - { - $typeResolver = new TypeResolver(); - $descriptionFactory = m::mock(DescriptionFactory::class); - $context = new Context(''); - - $description = new Description('My Description'); - $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); - - $fixture = Var_::create('string $myVariable My Description', $typeResolver, $descriptionFactory, $context); - - $this->assertSame('string $myVariable My Description', (string) $fixture); - $this->assertSame('myVariable', $fixture->getVariableName()); - $this->assertInstanceOf(String_::class, $fixture->getType()); - $this->assertSame($description, $fixture->getDescription()); - } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethodWithoutType(): void - { - $typeResolver = new TypeResolver(); - $fqsenResolver = new FqsenResolver(); - $tagFactory = new StandardTagFactory($fqsenResolver); - $descriptionFactory = new DescriptionFactory($tagFactory); - $context = new Context(''); - - $fixture = Var_::create( - '$myParameter My Description', - $typeResolver, - $descriptionFactory, - $context - ); - - $this->assertSame('$myParameter My Description', (string) $fixture); - $this->assertSame('myParameter', $fixture->getVariableName()); - $this->assertNull($fixture->getType()); - $this->assertSame('My Description', $fixture->getDescription() . ''); - } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethodWithType(): void - { - $typeResolver = new TypeResolver(); - $fqsenResolver = new FqsenResolver(); - $tagFactory = new StandardTagFactory($fqsenResolver); - $descriptionFactory = new DescriptionFactory($tagFactory); - $context = new Context(''); - - $fixture = Var_::create( - 'int My Description', - $typeResolver, - $descriptionFactory, - $context - ); - - $this->assertSame('int My Description', (string) $fixture); - $this->assertSame('', $fixture->getVariableName()); - $this->assertInstanceOf(Integer::class, $fixture->getType()); - $this->assertSame('My Description', $fixture->getDescription() . ''); - } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * @uses \phpDocumentor\Reflection\DocBlock\Description - * @uses \phpDocumentor\Reflection\Types\Context - * - * @covers ::create - */ - public function testFactoryMethodWithTypeWithoutComment(): void - { - $typeResolver = new TypeResolver(); - $fqsenResolver = new FqsenResolver(); - $tagFactory = new StandardTagFactory($fqsenResolver); - $descriptionFactory = new DescriptionFactory($tagFactory); - $context = new Context(''); - - $fixture = Var_::create( - 'int', - $typeResolver, - $descriptionFactory, - $context - ); - - $this->assertSame('int', (string) $fixture); - $this->assertSame('', $fixture->getVariableName()); - $this->assertInstanceOf(Integer::class, $fixture->getType()); - $this->assertSame('', $fixture->getDescription() . ''); - } - - /** - * @uses \phpDocumentor\Reflection\DocBlock\Tags\Var_:: - * @uses \phpDocumentor\Reflection\TypeResolver - * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory - * - * @covers ::create - */ - public function testFactoryMethodFailsIfEmptyBodyIsGiven(): void - { - $this->expectException('InvalidArgumentException'); - $descriptionFactory = m::mock(DescriptionFactory::class); - Var_::create('', new TypeResolver(), $descriptionFactory); - } - - /** - * @covers ::create - */ - public function testFactoryMethodFailsIfResolverIsNull(): void - { - $this->expectException('InvalidArgumentException'); - Var_::create('body'); - } - - /** - * @uses \phpDocumentor\Reflection\TypeResolver - * - * @covers ::create - */ - public function testFactoryMethodFailsIfDescriptionFactoryIsNull(): void - { - $this->expectException('InvalidArgumentException'); - Var_::create('body', new TypeResolver()); - } }