mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-17 17:47:13 +00:00
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.
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of phpDocumentor.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
|
||||
|
||||
/**
|
||||
* @deprecated This contract is totally covered by Tag contract. Every class using StaticMethod also use Tag
|
||||
*/
|
||||
interface StaticMethod
|
||||
{
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public static function create(string $body);
|
||||
}
|
||||
@@ -25,7 +25,7 @@ use function preg_match;
|
||||
/**
|
||||
* Parses a tag definition for a DocBlock.
|
||||
*/
|
||||
final class Generic extends BaseTag implements Factory\StaticMethod
|
||||
final class Generic extends BaseTag
|
||||
{
|
||||
/**
|
||||
* Parses a tag and populates the member variables.
|
||||
|
||||
@@ -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 Implements_ 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
@@ -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[]
|
||||
*/
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpDocumentor\Reflection\Exception;
|
||||
|
||||
use LogicException;
|
||||
|
||||
final class CannotCreateTag extends LogicException
|
||||
{
|
||||
}
|
||||
@@ -7,9 +7,8 @@ namespace phpDocumentor\Reflection\Assets;
|
||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Formatter;
|
||||
use phpDocumentor\Reflection\FqsenResolver;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\StaticMethod;
|
||||
|
||||
final class CustomParam implements Tag, StaticMethod
|
||||
final class CustomParam implements Tag
|
||||
{
|
||||
public $myParam;
|
||||
public $fqsenResolver;
|
||||
|
||||
@@ -10,7 +10,7 @@ use phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter;
|
||||
use phpDocumentor\Reflection\FqsenResolver;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\StaticMethod;
|
||||
|
||||
final class CustomServiceClass implements Tag, StaticMethod
|
||||
final class CustomServiceClass implements Tag
|
||||
{
|
||||
public $formatter;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use phpDocumentor\Reflection\DocBlock\Tags\Formatter;
|
||||
use phpDocumentor\Reflection\FqsenResolver;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\StaticMethod;
|
||||
|
||||
final class CustomServiceInterface implements Tag, StaticMethod
|
||||
final class CustomServiceInterface implements Tag
|
||||
{
|
||||
public $formatter;
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ use phpDocumentor\Reflection\PseudoTypes\IntegerValue;
|
||||
use phpDocumentor\Reflection\PseudoTypes\StringValue;
|
||||
use phpDocumentor\Reflection\Types\Compound;
|
||||
use phpDocumentor\Reflection\Types\Context;
|
||||
use phpDocumentor\Reflection\Types\Integer;
|
||||
use phpDocumentor\Reflection\Types\Mixed_;
|
||||
use phpDocumentor\Reflection\Types\Object_;
|
||||
use phpDocumentor\Reflection\Types\String_;
|
||||
@@ -84,16 +83,6 @@ final class ParamFactoryTest extends TagFactoryTestCase
|
||||
false
|
||||
),
|
||||
],
|
||||
[
|
||||
'@param int My Description',
|
||||
new Param(
|
||||
null,
|
||||
new Integer(),
|
||||
false,
|
||||
new Description('My Description'),
|
||||
false
|
||||
),
|
||||
],
|
||||
[
|
||||
'@param \'GET\'|SomeClass $arg My Description',
|
||||
new Param(
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -159,273 +153,4 @@ class ParamTest extends TestCase
|
||||
|
||||
$this->assertSame('string ...$myParameter Description', (string) $fixture);
|
||||
}
|
||||
|
||||
/**
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Param::<public>
|
||||
* @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::<public>
|
||||
* @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::<public>
|
||||
* @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::<public>
|
||||
* @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::<public>
|
||||
* @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::<public>
|
||||
* @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::<public>
|
||||
* @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::<public>
|
||||
* @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::<public>
|
||||
* @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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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::<public>
|
||||
* @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::<public>
|
||||
* @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::<public>
|
||||
* @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::<public>
|
||||
* @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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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::<public>
|
||||
* @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::<public>
|
||||
* @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::<public>
|
||||
* @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::<public>
|
||||
* @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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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::<public>
|
||||
* @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::<public>
|
||||
* @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::<public>
|
||||
* @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::<public>
|
||||
* @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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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_::<public>
|
||||
* @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_::<public>
|
||||
* @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<string, string> My Description', $resolver, $descriptionFactory, $context);
|
||||
|
||||
$this->assertSame('array<string, string> My Description', (string) $fixture);
|
||||
$this->assertEquals('array<string, string>', $fixture->getType());
|
||||
$this->assertSame($description, $fixture->getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see self::testFactoryMethodWithGenericWithSpace()
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Return_::<public>
|
||||
* @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😁<string,😁 😁string>" 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😁<string,😁 😁string> My Description', $resolver, $descriptionFactory, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Return_::<public>
|
||||
* @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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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_::<public>
|
||||
* @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::<public>
|
||||
* @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::<public>
|
||||
* @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::<public>
|
||||
* @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_::<public>
|
||||
* @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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user