mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-17 17:47:13 +00:00
Merge pull request #429 from phpDocumentor/prepare-6.x-build
Prepare 6.x build
This commit is contained in:
@@ -5,7 +5,7 @@ name: "Integrate"
|
||||
on: # yamllint disable-line rule:truthy
|
||||
push:
|
||||
branches:
|
||||
- "5.x"
|
||||
- "6.x"
|
||||
pull_request: null
|
||||
# Allow manually triggering the workflow.
|
||||
workflow_dispatch: null
|
||||
@@ -15,19 +15,19 @@ jobs:
|
||||
name: "Code Coverage"
|
||||
uses: "phpDocumentor/.github/.github/workflows/[email protected]"
|
||||
with:
|
||||
composer-root-version: "5.x-dev"
|
||||
composer-root-version: "6.x-dev"
|
||||
|
||||
coding-standards:
|
||||
name: "Coding Standards"
|
||||
uses: "phpDocumentor/.github/.github/workflows/[email protected]"
|
||||
with:
|
||||
composer-root-version: "5.x-dev"
|
||||
composer-root-version: "6.x-dev"
|
||||
|
||||
dependency-analysis:
|
||||
name: "Dependency analysis"
|
||||
uses: "phpDocumentor/.github/.github/workflows/[email protected]"
|
||||
with:
|
||||
composer-root-version: "5.x-dev"
|
||||
composer-root-version: "6.x-dev"
|
||||
|
||||
lint-root:
|
||||
name: "Lint root"
|
||||
@@ -40,19 +40,19 @@ jobs:
|
||||
uses: "phpDocumentor/.github/.github/workflows/[email protected]"
|
||||
with:
|
||||
php-extensions: "none, ctype, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter, fileinfo, pcntl, posix"
|
||||
composer-root-version: "5.x-dev"
|
||||
composer-root-version: "6.x-dev"
|
||||
|
||||
unit-tests:
|
||||
name: "Unit test"
|
||||
uses: "phpDocumentor/.github/.github/workflows/[email protected]"
|
||||
with:
|
||||
composer-root-version: "5.x-dev"
|
||||
composer-root-version: "6.x-dev"
|
||||
upcoming-releases: true
|
||||
|
||||
integration-tests:
|
||||
name: "Integration test"
|
||||
uses: "phpDocumentor/.github/.github/workflows/[email protected]"
|
||||
with:
|
||||
composer-root-version: "5.x-dev"
|
||||
composer-root-version: "6.x-dev"
|
||||
upcoming-releases: true
|
||||
test-suite: "integration"
|
||||
|
||||
+2
-2
@@ -15,11 +15,11 @@
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.4 || ^8.0",
|
||||
"phpdocumentor/type-resolver": "^1.7",
|
||||
"phpdocumentor/type-resolver": "^2.x-dev",
|
||||
"webmozart/assert": "^1.9.1 || ^2",
|
||||
"phpdocumentor/reflection-common": "^2.2",
|
||||
"ext-filter": "*",
|
||||
"phpstan/phpdoc-parser": "^1.7|^2.0",
|
||||
"phpstan/phpdoc-parser": "^2.0",
|
||||
"doctrine/deprecations": "^1.1"
|
||||
},
|
||||
"require-dev": {
|
||||
|
||||
Generated
+293
-221
File diff suppressed because it is too large
Load Diff
@@ -3,33 +3,5 @@ parameters:
|
||||
ignoreErrors:
|
||||
- '#Method phpDocumentor\\Reflection\\DocBlock\\StandardTagFactory::createTag\(\) should return phpDocumentor\\Reflection\\DocBlock\\Tag but returns mixed#'
|
||||
- '#Offset 2 on array\{string, 28, int\} on left side of \?\? always exists and is not nullable\.#'
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$constExprParser of class PHPStan\\\\PhpDocParser\\\\Parser\\\\TypeParser constructor expects PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser\\|null, PHPStan\\\\PhpDocParser\\\\ParserConfig given\\.$#"
|
||||
count: 1
|
||||
path: src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$parseDoctrineAnnotations of class PHPStan\\\\PhpDocParser\\\\Lexer\\\\Lexer constructor expects bool, PHPStan\\\\PhpDocParser\\\\ParserConfig given\\.$#"
|
||||
count: 1
|
||||
path: src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$typeParser of class PHPStan\\\\PhpDocParser\\\\Parser\\\\PhpDocParser constructor expects PHPStan\\\\PhpDocParser\\\\Parser\\\\TypeParser, PHPStan\\\\PhpDocParser\\\\ParserConfig given\\.$#"
|
||||
count: 1
|
||||
path: src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$unescapeStrings of class PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser constructor expects bool, PHPStan\\\\PhpDocParser\\\\ParserConfig given\\.$#"
|
||||
count: 1
|
||||
path: src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$constantExprParser of class PHPStan\\\\PhpDocParser\\\\Parser\\\\PhpDocParser constructor expects PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser, PHPStan\\\\PhpDocParser\\\\Parser\\\\TypeParser given\\.$#"
|
||||
count: 1
|
||||
path: src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$quoteAwareConstExprString of class PHPStan\\\\PhpDocParser\\\\Parser\\\\TypeParser constructor expects bool, PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser given\\.$#"
|
||||
count: 1
|
||||
path: src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php
|
||||
-
|
||||
message: "#^Parameter \\#3 \\$requireWhitespaceBeforeDescription of class PHPStan\\\\PhpDocParser\\\\Parser\\\\PhpDocParser constructor expects bool, PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser given\\.$#"
|
||||
count: 1
|
||||
path: src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php
|
||||
paths:
|
||||
- src
|
||||
|
||||
@@ -17,26 +17,34 @@ use InvalidArgumentException;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Author;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Covers;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Deprecated;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\AbstractPHPStanFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ExtendsFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\Factory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ImplementsFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\MethodFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyReadFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyWriteFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ReturnFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\TemplateExtendsFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\TemplateFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\TemplateImplementsFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ThrowsFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\VarFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Generic;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Link as LinkTag;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Method;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Mixin;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Param;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Property;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\PropertyRead;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\PropertyWrite;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Return_;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\See as SeeTag;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Since;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Source;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\TemplateCovariant;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Throws;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Uses;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Var_;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Version;
|
||||
use phpDocumentor\Reflection\FqsenResolver;
|
||||
use phpDocumentor\Reflection\TypeResolver;
|
||||
use phpDocumentor\Reflection\Types\Context as TypeContext;
|
||||
use ReflectionMethod;
|
||||
use ReflectionNamedType;
|
||||
@@ -77,7 +85,7 @@ final class StandardTagFactory implements TagFactory
|
||||
public const REGEX_TAGNAME = '[\w\-\_\\\\:]+';
|
||||
|
||||
/**
|
||||
* @var array<class-string<Tag>|Factory> An array with a tag as a key, and an
|
||||
* @var array<string, class-string<Tag>|Tag|Factory> An array with a tag as a key, and an
|
||||
* FQCN to a class that handles it as an array value.
|
||||
*/
|
||||
private array $tagHandlerMappings = [
|
||||
@@ -86,21 +94,13 @@ final class StandardTagFactory implements TagFactory
|
||||
'deprecated' => Deprecated::class,
|
||||
// 'example' => '\phpDocumentor\Reflection\DocBlock\Tags\Example',
|
||||
'link' => LinkTag::class,
|
||||
'mixin' => Mixin::class,
|
||||
'method' => Method::class,
|
||||
'param' => Param::class,
|
||||
'property-read' => PropertyRead::class,
|
||||
'property' => Property::class,
|
||||
'property-write' => PropertyWrite::class,
|
||||
'return' => Return_::class,
|
||||
'see' => SeeTag::class,
|
||||
'since' => Since::class,
|
||||
'source' => Source::class,
|
||||
'template-covariant' => TemplateCovariant::class,
|
||||
'throw' => Throws::class,
|
||||
'throws' => Throws::class,
|
||||
'uses' => Uses::class,
|
||||
'var' => Var_::class,
|
||||
'version' => Version::class,
|
||||
];
|
||||
|
||||
@@ -124,26 +124,60 @@ final class StandardTagFactory implements TagFactory
|
||||
*/
|
||||
private array $serviceLocator = [];
|
||||
|
||||
/**
|
||||
* Initialize this tag factory with the means to resolve an FQSEN and optionally a list of tag handlers.
|
||||
*
|
||||
* If no tag handlers are provided than the default list in the {@see self::$tagHandlerMappings} property
|
||||
* is used.
|
||||
*
|
||||
* @see self::registerTagHandler() to add a new tag handler to the existing default list.
|
||||
*
|
||||
* @param array<class-string<Tag>> $tagHandlers
|
||||
*/
|
||||
public function __construct(FqsenResolver $fqsenResolver, ?array $tagHandlers = null)
|
||||
private function __construct(FqsenResolver $fqsenResolver)
|
||||
{
|
||||
$this->fqsenResolver = $fqsenResolver;
|
||||
if ($tagHandlers !== null) {
|
||||
$this->tagHandlerMappings = $tagHandlers;
|
||||
}
|
||||
|
||||
$this->addService($fqsenResolver, FqsenResolver::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize this tag factory with the means to resolve an FQSEN.
|
||||
*
|
||||
* @see self::registerTagHandler() to add a new tag handler to the existing default list.
|
||||
*/
|
||||
public static function createInstance(FqsenResolver $fqsenResolver): self
|
||||
{
|
||||
$tagFactory = new self($fqsenResolver);
|
||||
$descriptionFactory = new DescriptionFactory($tagFactory);
|
||||
|
||||
$typeResolver = new TypeResolver($fqsenResolver);
|
||||
|
||||
$phpstanTagFactory = new AbstractPHPStanFactory(
|
||||
new ParamFactory($typeResolver, $descriptionFactory),
|
||||
new VarFactory($typeResolver, $descriptionFactory),
|
||||
new ReturnFactory($typeResolver, $descriptionFactory),
|
||||
new PropertyFactory($typeResolver, $descriptionFactory),
|
||||
new PropertyReadFactory($typeResolver, $descriptionFactory),
|
||||
new PropertyWriteFactory($typeResolver, $descriptionFactory),
|
||||
new MethodFactory($typeResolver, $descriptionFactory),
|
||||
new ImplementsFactory($typeResolver, $descriptionFactory),
|
||||
new ExtendsFactory($typeResolver, $descriptionFactory),
|
||||
new TemplateFactory($typeResolver, $descriptionFactory),
|
||||
new TemplateImplementsFactory($typeResolver, $descriptionFactory),
|
||||
new TemplateExtendsFactory($typeResolver, $descriptionFactory),
|
||||
new ThrowsFactory($typeResolver, $descriptionFactory),
|
||||
);
|
||||
|
||||
$tagFactory->addService($descriptionFactory);
|
||||
$tagFactory->addService($typeResolver);
|
||||
$tagFactory->registerTagHandler('param', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('var', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('return', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('property', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('property-read', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('property-write', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('method', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('extends', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('implements', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('template', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('template-extends', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('template-implements', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('throws', $phpstanTagFactory);
|
||||
|
||||
return $tagFactory;
|
||||
}
|
||||
|
||||
public function create(string $tagLine, ?TypeContext $context = null): Tag
|
||||
{
|
||||
if (!$context) {
|
||||
@@ -238,7 +272,7 @@ final class StandardTagFactory implements TagFactory
|
||||
/**
|
||||
* Determines the Fully Qualified Class Name of the Factory or Tag (containing a Factory Method `create`).
|
||||
*
|
||||
* @return class-string<Tag>|Factory
|
||||
* @return class-string<Tag>|Tag|Factory
|
||||
*/
|
||||
private function findHandlerClassName(string $tagName, TypeContext $context)
|
||||
{
|
||||
@@ -302,7 +336,7 @@ final class StandardTagFactory implements TagFactory
|
||||
* Retrieves a series of ReflectionParameter objects for the static 'create' method of the given
|
||||
* tag handler class name.
|
||||
*
|
||||
* @param class-string|Factory $handler
|
||||
* @param class-string<Tag>|Tag|Factory $handler
|
||||
*
|
||||
* @return ReflectionParameter[]
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
@@ -46,27 +45,14 @@ class AbstractPHPStanFactory implements Factory
|
||||
|
||||
public function __construct(PHPStanFactory ...$factories)
|
||||
{
|
||||
if (class_exists(ParserConfig::class)) {
|
||||
$config = new ParserConfig(['indexes' => true, 'lines' => true]);
|
||||
$this->lexer = new Lexer($config);
|
||||
$constParser = new ConstExprParser($config);
|
||||
$this->parser = new PhpDocParser(
|
||||
$config,
|
||||
new TypeParser($config, $constParser),
|
||||
$constParser
|
||||
);
|
||||
} else {
|
||||
$this->lexer = new Lexer(true);
|
||||
$constParser = new ConstExprParser(true, true, ['lines' => true, 'indexes' => true]);
|
||||
$this->parser = new PhpDocParser(
|
||||
new TypeParser($constParser, true, ['lines' => true, 'indexes' => true]),
|
||||
$constParser,
|
||||
true,
|
||||
true,
|
||||
['lines' => true, 'indexes' => true],
|
||||
true
|
||||
);
|
||||
}
|
||||
$config = new ParserConfig(['indexes' => true, 'lines' => true]);
|
||||
$this->lexer = new Lexer($config);
|
||||
$constParser = new ConstExprParser($config);
|
||||
$this->parser = new PhpDocParser(
|
||||
$config,
|
||||
new TypeParser($config, $constParser),
|
||||
$constParser
|
||||
);
|
||||
|
||||
$this->factories = $factories;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
|
||||
|
||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Mixin;
|
||||
use phpDocumentor\Reflection\TypeResolver;
|
||||
use phpDocumentor\Reflection\Types\Context;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\MixinTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
use function is_string;
|
||||
|
||||
/**
|
||||
* @internal This class is not part of the BC promise of this library.
|
||||
*/
|
||||
final class MixinFactory implements PHPStanFactory
|
||||
{
|
||||
private DescriptionFactory $descriptionFactory;
|
||||
private TypeResolver $typeResolver;
|
||||
|
||||
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
|
||||
{
|
||||
$this->descriptionFactory = $descriptionFactory;
|
||||
$this->typeResolver = $typeResolver;
|
||||
}
|
||||
|
||||
public function create(PhpDocTagNode $node, Context $context): Tag
|
||||
{
|
||||
$tagValue = $node->value;
|
||||
Assert::isInstanceOf($tagValue, MixinTagValueNode::class);
|
||||
|
||||
$description = $tagValue->getAttribute('description');
|
||||
if (is_string($description) === false) {
|
||||
$description = $tagValue->description;
|
||||
}
|
||||
|
||||
return new Mixin(
|
||||
$this->typeResolver->createType($tagValue->type, $context),
|
||||
$this->descriptionFactory->create($description, $context)
|
||||
);
|
||||
}
|
||||
|
||||
public function supports(PhpDocTagNode $node, Context $context): bool
|
||||
{
|
||||
return $node->value instanceof MixinTagValueNode;
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,11 @@ 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;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Param;
|
||||
use phpDocumentor\Reflection\Exception\ParserException;
|
||||
use phpDocumentor\Reflection\TypeResolver;
|
||||
use phpDocumentor\Reflection\Types\Context;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\InvalidTagValueNode;
|
||||
@@ -20,7 +20,6 @@ use PHPStan\PhpDocParser\Ast\Type\OffsetAccessTypeNode;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
use function is_string;
|
||||
use function sprintf;
|
||||
use function trim;
|
||||
|
||||
/**
|
||||
@@ -42,16 +41,9 @@ 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 InvalidTag::create($tagValue->value, 'param')->withError(
|
||||
ParserException::from($tagValue->exception)
|
||||
);
|
||||
|
||||
return Param::create($tagValue->value, $this->typeResolver, $this->descriptionFactory, $context);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
|
||||
|
||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Throws;
|
||||
use phpDocumentor\Reflection\TypeResolver;
|
||||
use phpDocumentor\Reflection\Types\Context;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\ThrowsTagValueNode;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
use function is_string;
|
||||
|
||||
/**
|
||||
* @internal This class is not part of the BC promise of this library.
|
||||
*/
|
||||
final class ThrowsFactory implements PHPStanFactory
|
||||
{
|
||||
private DescriptionFactory $descriptionFactory;
|
||||
private TypeResolver $typeResolver;
|
||||
|
||||
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
|
||||
{
|
||||
$this->descriptionFactory = $descriptionFactory;
|
||||
$this->typeResolver = $typeResolver;
|
||||
}
|
||||
|
||||
public function create(PhpDocTagNode $node, Context $context): Tag
|
||||
{
|
||||
$tagValue = $node->value;
|
||||
Assert::isInstanceOf($tagValue, ThrowsTagValueNode::class);
|
||||
|
||||
$description = $tagValue->getAttribute('description');
|
||||
if (is_string($description) === false) {
|
||||
$description = $tagValue->description;
|
||||
}
|
||||
|
||||
return new Throws(
|
||||
$this->typeResolver->createType($tagValue->type, $context),
|
||||
$this->descriptionFactory->create($description, $context)
|
||||
);
|
||||
}
|
||||
|
||||
public function supports(PhpDocTagNode $node, Context $context): bool
|
||||
{
|
||||
return $node->value instanceof ThrowsTagValueNode;
|
||||
}
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
|
||||
@@ -14,16 +14,12 @@ declare(strict_types=1);
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||
|
||||
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 {@}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)
|
||||
{
|
||||
@@ -31,21 +27,4 @@ final class Mixin extends TagWithType implements Factory\StaticMethod
|
||||
$this->type = $type;
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
public static function create(
|
||||
string $body,
|
||||
?TypeResolver $typeResolver = null,
|
||||
?DescriptionFactory $descriptionFactory = null,
|
||||
?TypeContext $context = null
|
||||
): self {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,27 +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 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 +44,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 +91,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;
|
||||
}
|
||||
|
||||
final public static function create(string $body): Tag
|
||||
{
|
||||
throw new CannotCreateTag('Typed tag cannot be created');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
|
||||
@@ -14,16 +14,12 @@ declare(strict_types=1);
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||
|
||||
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 {@}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)
|
||||
{
|
||||
@@ -31,21 +27,4 @@ final class TemplateCovariant extends TagWithType implements Factory\StaticMetho
|
||||
$this->type = $type;
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
public static function create(
|
||||
string $body,
|
||||
?TypeResolver $typeResolver = null,
|
||||
?DescriptionFactory $descriptionFactory = null,
|
||||
?TypeContext $context = null
|
||||
): self {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,16 +14,12 @@ declare(strict_types=1);
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||
|
||||
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 {@}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)
|
||||
{
|
||||
@@ -31,21 +27,4 @@ final class Throws extends TagWithType implements Factory\StaticMethod
|
||||
$this->type = $type;
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
public static function create(
|
||||
string $body,
|
||||
?TypeResolver $typeResolver = null,
|
||||
?DescriptionFactory $descriptionFactory = null,
|
||||
?TypeContext $context = null
|
||||
): self {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
+1
-45
@@ -19,20 +19,7 @@ use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\StandardTagFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
||||
use phpDocumentor\Reflection\DocBlock\TagFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\AbstractPHPStanFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ExtendsFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\Factory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ImplementsFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\MethodFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyReadFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyWriteFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ReturnFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\TemplateExtendsFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\TemplateFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\TemplateImplementsFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\VarFactory;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
use function array_shift;
|
||||
@@ -70,39 +57,8 @@ final class DocBlockFactory implements DocBlockFactoryInterface
|
||||
public static function createInstance(array $additionalTags = []): DocBlockFactoryInterface
|
||||
{
|
||||
$fqsenResolver = new FqsenResolver();
|
||||
$tagFactory = new StandardTagFactory($fqsenResolver);
|
||||
$tagFactory = StandardTagFactory::createInstance($fqsenResolver);
|
||||
$descriptionFactory = new DescriptionFactory($tagFactory);
|
||||
$typeResolver = new TypeResolver($fqsenResolver);
|
||||
|
||||
$phpstanTagFactory = new AbstractPHPStanFactory(
|
||||
new ParamFactory($typeResolver, $descriptionFactory),
|
||||
new VarFactory($typeResolver, $descriptionFactory),
|
||||
new ReturnFactory($typeResolver, $descriptionFactory),
|
||||
new PropertyFactory($typeResolver, $descriptionFactory),
|
||||
new PropertyReadFactory($typeResolver, $descriptionFactory),
|
||||
new PropertyWriteFactory($typeResolver, $descriptionFactory),
|
||||
new MethodFactory($typeResolver, $descriptionFactory),
|
||||
new ImplementsFactory($typeResolver, $descriptionFactory),
|
||||
new ExtendsFactory($typeResolver, $descriptionFactory),
|
||||
new TemplateFactory($typeResolver, $descriptionFactory),
|
||||
new TemplateImplementsFactory($typeResolver, $descriptionFactory),
|
||||
new TemplateExtendsFactory($typeResolver, $descriptionFactory),
|
||||
);
|
||||
|
||||
$tagFactory->addService($descriptionFactory);
|
||||
$tagFactory->addService($typeResolver);
|
||||
$tagFactory->registerTagHandler('param', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('var', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('return', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('property', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('property-read', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('property-write', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('method', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('extends', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('implements', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('template', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('template-extends', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('template-implements', $phpstanTagFactory);
|
||||
|
||||
$docBlockFactory = new self($descriptionFactory, $tagFactory);
|
||||
foreach ($additionalTags as $tagName => $tagHandler) {
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpDocumentor\Reflection\Exception;
|
||||
|
||||
use LogicException;
|
||||
|
||||
final class CannotCreateTag extends LogicException
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpDocumentor\Reflection\Exception;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
final class ParserException extends InvalidArgumentException implements ReflectionDocblockException
|
||||
{
|
||||
public static function from(\PHPStan\PhpDocParser\Parser\ParserException $exception): self
|
||||
{
|
||||
return new self(
|
||||
'Failed to parse docblock: ' . $exception->getMessage(),
|
||||
0,
|
||||
$exception
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpDocumentor\Reflection\Exception;
|
||||
|
||||
use Throwable;
|
||||
|
||||
interface ReflectionDocblockException extends Throwable
|
||||
{
|
||||
}
|
||||
@@ -26,6 +26,7 @@ use phpDocumentor\Reflection\DocBlock\Tags\Return_;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\See;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Since;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Template;
|
||||
use phpDocumentor\Reflection\Exception\ParserException;
|
||||
use phpDocumentor\Reflection\PseudoTypes\ConstExpression;
|
||||
use phpDocumentor\Reflection\Types\Array_;
|
||||
use phpDocumentor\Reflection\Types\Compound;
|
||||
@@ -242,18 +243,26 @@ DOC;
|
||||
$factory = DocBlockFactory::createInstance();
|
||||
$docblock = $factory->create($docComment);
|
||||
|
||||
self::assertEquals(
|
||||
[
|
||||
InvalidTag::create(
|
||||
'array\Foo> $test',
|
||||
'param',
|
||||
)->withError(
|
||||
new \InvalidArgumentException(
|
||||
'Could not find type in array\Foo> $test, please check for malformed notations')
|
||||
),
|
||||
],
|
||||
$docblock->getTags()
|
||||
);
|
||||
$tags = $docblock->getTags();
|
||||
|
||||
self::assertCount(1, $docblock->getTags());
|
||||
self::assertInstanceOf(InvalidTag::class, $tags[0]);
|
||||
self::assertCount(1, $docblock->getTags());
|
||||
self::assertSame('Failed to parse docblock: Unexpected token ">", expected variable at offset 16 on line 1', $tags[0]->getException()->getMessage());
|
||||
|
||||
|
||||
// self::assertEquals(
|
||||
// [
|
||||
// InvalidTag::create(
|
||||
// 'array\Foo> $test',
|
||||
// 'param',
|
||||
// )->withError(
|
||||
// new ParserException(
|
||||
// 'Could not find type in array\Foo> $test, please check for malformed notations', 'aa', 1)
|
||||
// ),
|
||||
// ],
|
||||
// $docblock->getTags()
|
||||
// );
|
||||
}
|
||||
|
||||
public function testConstantReferenceTypes(): void
|
||||
@@ -335,7 +344,7 @@ DOC;
|
||||
),
|
||||
new Param(
|
||||
'args',
|
||||
new Compound([new Array_(new Mixed_()), new String_()]),
|
||||
new Compound([new Array_(), new String_()]),
|
||||
false,
|
||||
new Description(
|
||||
'{' . "\n" .
|
||||
@@ -356,7 +365,7 @@ DOC;
|
||||
)
|
||||
),
|
||||
new Return_(
|
||||
new Compound([new Array_(new Mixed_()), new Object_(new Fqsen('\WP_Error'))]),
|
||||
new Compound([new Array_(), new Object_(new Fqsen('\WP_Error'))]),
|
||||
new Description('The result (also stored in `WP_Upgrader::$result`), or a WP_Error on failure.')
|
||||
),
|
||||
],
|
||||
@@ -407,7 +416,7 @@ identifier has already been registered.',
|
||||
new Since('6.5.0', new Description('')),
|
||||
new Param(
|
||||
'deps',
|
||||
new Array_(new Mixed_()),
|
||||
new Array_(),
|
||||
false,
|
||||
new Description("{
|
||||
Optional. List of dependencies.
|
||||
|
||||
@@ -16,7 +16,7 @@ use phpDocumentor\Reflection\Type;
|
||||
use phpDocumentor\Reflection\Types\Array_;
|
||||
use phpDocumentor\Reflection\Types\Callable_;
|
||||
use phpDocumentor\Reflection\Types\CallableParameter;
|
||||
use phpDocumentor\Reflection\Types\Collection;
|
||||
use phpDocumentor\Reflection\PseudoTypes\Generic;
|
||||
use phpDocumentor\Reflection\Types\Integer;
|
||||
use phpDocumentor\Reflection\Types\Nullable;
|
||||
use phpDocumentor\Reflection\Types\Object_;
|
||||
@@ -160,19 +160,19 @@ DOCBLOCK;
|
||||
],
|
||||
[
|
||||
'Collection<int, string>',
|
||||
new Collection(new Fqsen('\\Collection'), new String_(), new Integer()),
|
||||
new Generic(new Fqsen('\\Collection'), [new Integer(), new String_()]),
|
||||
],
|
||||
[
|
||||
'Collection<TKey, Tvalue>',
|
||||
new Collection(new Fqsen('\\Collection'), new Object_(new Fqsen('\\Tvalue')), new Object_(new Fqsen('\\TKey'))),
|
||||
new Generic(new Fqsen('\\Collection'), [new Object_(new Fqsen('\\TKey')), new Object_(new Fqsen('\\Tvalue'))]),
|
||||
],
|
||||
[
|
||||
'Collection<Tvalue>',
|
||||
new Collection(new Fqsen('\\Collection'), new Object_(new Fqsen('\\Tvalue'))),
|
||||
new Generic(new Fqsen('\\Collection'), [new Object_(new Fqsen('\\Tvalue'))]),
|
||||
],
|
||||
[
|
||||
'callable(int $foo, string $bar): void',
|
||||
new Callable_([new CallableParameter(new Integer(), 'foo'), new CallableParameter(new String_(), 'bar')], new Void_()),
|
||||
new Callable_('callable', [new CallableParameter(new Integer(), 'foo'), new CallableParameter(new String_(), 'bar')], new Void_()),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -20,11 +20,10 @@ use phpDocumentor\Reflection\Assets\CustomServiceClass;
|
||||
use phpDocumentor\Reflection\Assets\CustomServiceInterface;
|
||||
use phpDocumentor\Reflection\Assets\CustomTagFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Author;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Deprecated;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Formatter;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Generic;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Return_;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\See;
|
||||
use phpDocumentor\Reflection\Fqsen;
|
||||
use phpDocumentor\Reflection\FqsenResolver;
|
||||
@@ -69,7 +68,7 @@ class StandardTagFactoryTest extends TestCase
|
||||
->with($expectedDescriptionText, $context)
|
||||
->andReturn($expectedDescription);
|
||||
|
||||
$tagFactory = new StandardTagFactory(m::mock(FqsenResolver::class));
|
||||
$tagFactory = StandardTagFactory::createInstance(m::mock(FqsenResolver::class));
|
||||
$tagFactory->addService($descriptionFactory, DescriptionFactory::class);
|
||||
|
||||
$tag = $tagFactory->create('@' . $expectedTagName . ' This is a description', $context);
|
||||
@@ -94,7 +93,7 @@ class StandardTagFactoryTest extends TestCase
|
||||
$expectedDescriptionText = ' foo Bar 123 ';
|
||||
$context = new Context('');
|
||||
|
||||
$tagFactory = new StandardTagFactory(new FqsenResolver());
|
||||
$tagFactory = StandardTagFactory::createInstance(new FqsenResolver());
|
||||
$tagFactory->addService(new DescriptionFactory($tagFactory), DescriptionFactory::class);
|
||||
|
||||
$tag = $tagFactory->create('@' . $expectedTagName . $expectedDescriptionText, $context);
|
||||
@@ -114,7 +113,7 @@ class StandardTagFactoryTest extends TestCase
|
||||
public function testCreatingASpecificTag(): void
|
||||
{
|
||||
$context = new Context('');
|
||||
$tagFactory = new StandardTagFactory(m::mock(FqsenResolver::class));
|
||||
$tagFactory = StandardTagFactory::createInstance(m::mock(FqsenResolver::class));
|
||||
|
||||
$tag = $tagFactory->create('@author Mike van Riel <[email protected]>', $context);
|
||||
|
||||
@@ -143,7 +142,7 @@ class StandardTagFactoryTest extends TestCase
|
||||
$descriptionFactory = m::mock(DescriptionFactory::class);
|
||||
$descriptionFactory->shouldIgnoreMissing();
|
||||
|
||||
$tagFactory = new StandardTagFactory($resolver);
|
||||
$tagFactory = StandardTagFactory::createInstance($resolver);
|
||||
$tagFactory->addService($descriptionFactory, DescriptionFactory::class);
|
||||
|
||||
$tag = $tagFactory->create('@see Tag');
|
||||
@@ -163,7 +162,8 @@ class StandardTagFactoryTest extends TestCase
|
||||
public function testPassingYourOwnSetOfTagHandlers(): void
|
||||
{
|
||||
$context = new Context('');
|
||||
$tagFactory = new StandardTagFactory(m::mock(FqsenResolver::class), ['user' => Author::class]);
|
||||
$tagFactory = StandardTagFactory::createInstance(m::mock(FqsenResolver::class));
|
||||
$tagFactory->registerTagHandler('user', Author::class);
|
||||
|
||||
$tag = $tagFactory->create('@user Mike van Riel <[email protected]>', $context);
|
||||
|
||||
@@ -181,16 +181,11 @@ class StandardTagFactoryTest extends TestCase
|
||||
*/
|
||||
public function testPassingYourOwnSetOfTagHandlersWithGermanChars(): void
|
||||
{
|
||||
$typeResolver = new TypeResolver();
|
||||
$fqsenResolver = new FqsenResolver();
|
||||
$tagFactory = new StandardTagFactory($fqsenResolver);
|
||||
$descriptionFactory = new DescriptionFactory($tagFactory);
|
||||
$tagFactory = StandardTagFactory::createInstance($fqsenResolver);
|
||||
$context = new Context('');
|
||||
|
||||
$tagFactory = new StandardTagFactory(
|
||||
$fqsenResolver,
|
||||
['my-täg' => Author::class]
|
||||
);
|
||||
$tagFactory->registerTagHandler('my-täg', Author::class);
|
||||
|
||||
$tag = $tagFactory->create('@my-täg foo bar ', $context);
|
||||
|
||||
@@ -209,17 +204,11 @@ class StandardTagFactoryTest extends TestCase
|
||||
*/
|
||||
public function testPassingYourOwnSetOfTagHandlersWithoutComment(): void
|
||||
{
|
||||
$typeResolver = new TypeResolver();
|
||||
$fqsenResolver = new FqsenResolver();
|
||||
$tagFactory = new StandardTagFactory($fqsenResolver);
|
||||
$descriptionFactory = new DescriptionFactory($tagFactory);
|
||||
$tagFactory = StandardTagFactory::createInstance($fqsenResolver);
|
||||
$context = new Context('');
|
||||
|
||||
$tagFactory = new StandardTagFactory(
|
||||
$fqsenResolver,
|
||||
['my-täg' => Author::class]
|
||||
);
|
||||
|
||||
$tagFactory->registerTagHandler('my-täg', Author::class);
|
||||
$tag = $tagFactory->create('@my-täg', $context);
|
||||
|
||||
$this->assertInstanceOf(Author::class, $tag);
|
||||
@@ -233,7 +222,7 @@ class StandardTagFactoryTest extends TestCase
|
||||
$customFactory = new CustomTagFactory();
|
||||
$injectedClass = new CustomServiceClass();
|
||||
|
||||
$tagFactory = new StandardTagFactory($fqsenResolver);
|
||||
$tagFactory = StandardTagFactory::createInstance($fqsenResolver);
|
||||
$tagFactory->addService($injectedClass);
|
||||
$tagFactory->registerTagHandler('param', $customFactory);
|
||||
$tag = $tagFactory->create('@param foo');
|
||||
@@ -259,11 +248,11 @@ class StandardTagFactoryTest extends TestCase
|
||||
|
||||
$typeResolver = new TypeResolver();
|
||||
$fqsenResolver = new FqsenResolver();
|
||||
$tagFactory = new StandardTagFactory($fqsenResolver);
|
||||
$tagFactory = StandardTagFactory::createInstance($fqsenResolver);
|
||||
$descriptionFactory = new DescriptionFactory($tagFactory);
|
||||
$context = new Context('');
|
||||
|
||||
$tagFactory = new StandardTagFactory(
|
||||
$tagFactory = StandardTagFactory::createInstance(
|
||||
$fqsenResolver,
|
||||
['my-täg' => Author::class]
|
||||
);
|
||||
@@ -283,7 +272,7 @@ class StandardTagFactoryTest extends TestCase
|
||||
$this->expectExceptionMessage(
|
||||
'The tag "@user[myuser" does not seem to be wellformed, please check it for errors'
|
||||
);
|
||||
$tagFactory = new StandardTagFactory(m::mock(FqsenResolver::class));
|
||||
$tagFactory = StandardTagFactory::createInstance(m::mock(FqsenResolver::class));
|
||||
$tagFactory->create('@user[myuser');
|
||||
}
|
||||
|
||||
@@ -296,7 +285,7 @@ class StandardTagFactoryTest extends TestCase
|
||||
public function testAddParameterToServiceLocator(): void
|
||||
{
|
||||
$resolver = m::mock(FqsenResolver::class);
|
||||
$tagFactory = new StandardTagFactory($resolver);
|
||||
$tagFactory = StandardTagFactory::createInstance($resolver);
|
||||
$tagFactory->registerTagHandler('spy', CustomParam::class);
|
||||
|
||||
$tagFactory->addParameter('myParam', 'myValue');
|
||||
@@ -316,7 +305,7 @@ class StandardTagFactoryTest extends TestCase
|
||||
$service = new PassthroughFormatter();
|
||||
|
||||
$resolver = m::mock(FqsenResolver::class);
|
||||
$tagFactory = new StandardTagFactory($resolver);
|
||||
$tagFactory = StandardTagFactory::createInstance($resolver);
|
||||
$tagFactory->addService($service);
|
||||
$tagFactory->registerTagHandler('spy', CustomServiceClass::class);
|
||||
|
||||
@@ -336,7 +325,7 @@ class StandardTagFactoryTest extends TestCase
|
||||
$service = new PassthroughFormatter();
|
||||
|
||||
$resolver = m::mock(FqsenResolver::class);
|
||||
$tagFactory = new StandardTagFactory($resolver);
|
||||
$tagFactory = StandardTagFactory::createInstance($resolver);
|
||||
$tagFactory->addService($service, $interfaceName);
|
||||
$tagFactory->registerTagHandler('spy', CustomServiceInterface::class);
|
||||
|
||||
@@ -356,7 +345,7 @@ class StandardTagFactoryTest extends TestCase
|
||||
public function testRegisteringAHandlerForANewTag(): void
|
||||
{
|
||||
$resolver = m::mock(FqsenResolver::class);
|
||||
$tagFactory = new StandardTagFactory($resolver);
|
||||
$tagFactory = StandardTagFactory::createInstance($resolver);
|
||||
|
||||
$tagFactory->registerTagHandler('my-tag', Author::class);
|
||||
|
||||
@@ -375,7 +364,7 @@ class StandardTagFactoryTest extends TestCase
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$resolver = m::mock(FqsenResolver::class);
|
||||
$tagFactory = new StandardTagFactory($resolver);
|
||||
$tagFactory = StandardTagFactory::createInstance($resolver);
|
||||
// phpcs:ignore SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName
|
||||
$tagFactory->registerTagHandler(\Name\Spaced\Tag::class, Author::class);
|
||||
}
|
||||
@@ -390,7 +379,7 @@ class StandardTagFactoryTest extends TestCase
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$resolver = m::mock(FqsenResolver::class);
|
||||
$tagFactory = new StandardTagFactory($resolver);
|
||||
$tagFactory = StandardTagFactory::createInstance($resolver);
|
||||
$tagFactory->registerTagHandler('my-tag', '');
|
||||
}
|
||||
|
||||
@@ -404,7 +393,7 @@ class StandardTagFactoryTest extends TestCase
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$resolver = m::mock(FqsenResolver::class);
|
||||
$tagFactory = new StandardTagFactory($resolver);
|
||||
$tagFactory = StandardTagFactory::createInstance($resolver);
|
||||
$tagFactory->registerTagHandler('my-tag', 'IDoNotExist');
|
||||
}
|
||||
|
||||
@@ -418,7 +407,7 @@ class StandardTagFactoryTest extends TestCase
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$resolver = m::mock(FqsenResolver::class);
|
||||
$tagFactory = new StandardTagFactory($resolver);
|
||||
$tagFactory = StandardTagFactory::createInstance($resolver);
|
||||
$tagFactory->registerTagHandler('my-tag', 'stdClass');
|
||||
}
|
||||
|
||||
@@ -439,28 +428,19 @@ class StandardTagFactoryTest extends TestCase
|
||||
$descriptionFactory
|
||||
->shouldReceive('create')
|
||||
->once()
|
||||
->with('', $context)
|
||||
->with('mixed test', $context)
|
||||
->andReturn(new Description(''));
|
||||
|
||||
$typeResolver = new TypeResolver();
|
||||
|
||||
$tagFactory = new StandardTagFactory(m::mock(FqsenResolver::class));
|
||||
$tagFactory = StandardTagFactory::createInstance(m::mock(FqsenResolver::class));
|
||||
$tagFactory->addService($descriptionFactory, DescriptionFactory::class);
|
||||
$tagFactory->addService($typeResolver, TypeResolver::class);
|
||||
|
||||
$tag = $tagFactory->create('@return mixed', $context);
|
||||
$tag = $tagFactory->create('@deprecated mixed test', $context);
|
||||
|
||||
$this->assertInstanceOf(Return_::class, $tag);
|
||||
$this->assertSame('return', $tag->getName());
|
||||
}
|
||||
|
||||
public function testInvalidTagIsReturnedOnFailure(): void
|
||||
{
|
||||
$tagFactory = new StandardTagFactory(m::mock(FqsenResolver::class));
|
||||
|
||||
$tag = $tagFactory->create('@see $name some invalid tag');
|
||||
|
||||
$this->assertInstanceOf(InvalidTag::class, $tag);
|
||||
$this->assertInstanceOf(Deprecated::class, $tag);
|
||||
$this->assertSame('deprecated', $tag->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -469,7 +449,7 @@ class StandardTagFactoryTest extends TestCase
|
||||
public function testValidFormattedTags(string $input, string $tagName, string $render): void
|
||||
{
|
||||
$fqsenResolver = m::mock(FqsenResolver::class);
|
||||
$tagFactory = new StandardTagFactory($fqsenResolver);
|
||||
$tagFactory = StandardTagFactory::createInstance($fqsenResolver);
|
||||
$tagFactory->registerTagHandler('tag', Generic::class);
|
||||
$tag = $tagFactory->create($input);
|
||||
|
||||
@@ -540,7 +520,7 @@ class StandardTagFactoryTest extends TestCase
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$fqsenResolver = m::mock(FqsenResolver::class);
|
||||
$tagFactory = new StandardTagFactory($fqsenResolver);
|
||||
$tagFactory = StandardTagFactory::createInstance($fqsenResolver);
|
||||
$tagFactory->registerTagHandler('tag', Generic::class);
|
||||
$tagFactory->create($input);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ 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\DocBlock\TagFactory;
|
||||
use phpDocumentor\Reflection\Fqsen;
|
||||
use phpDocumentor\Reflection\FqsenResolver;
|
||||
use phpDocumentor\Reflection\Types\Context;
|
||||
@@ -188,8 +188,7 @@ class CoversTest extends TestCase
|
||||
public function testFactoryMethodWithSpaceBeforeClass(): void
|
||||
{
|
||||
$fqsenResolver = new FqsenResolver();
|
||||
$tagFactory = new StandardTagFactory($fqsenResolver);
|
||||
$descriptionFactory = new DescriptionFactory($tagFactory);
|
||||
$descriptionFactory = new DescriptionFactory($this->createMock(TagFactory::class));
|
||||
$context = new Context('');
|
||||
|
||||
$fixture = Covers::create(
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -16,8 +16,7 @@ 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\DocBlock\TagFactory;
|
||||
use phpDocumentor\Reflection\Types\Context;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@@ -177,9 +176,7 @@ class LinkTest extends TestCase
|
||||
*/
|
||||
public function testFactoryMethodWithoutSpaceBeforeUrl(): void
|
||||
{
|
||||
$fqsenResolver = new FqsenResolver();
|
||||
$tagFactory = new StandardTagFactory($fqsenResolver);
|
||||
$descriptionFactory = new DescriptionFactory($tagFactory);
|
||||
$descriptionFactory = new DescriptionFactory($this->createMock(TagFactory::class));
|
||||
$context = new Context('');
|
||||
|
||||
$fixture = Link::create(
|
||||
@@ -204,9 +201,7 @@ class LinkTest extends TestCase
|
||||
*/
|
||||
public function testFactoryMethodWithSpaceBeforeUrl(): void
|
||||
{
|
||||
$fqsenResolver = new FqsenResolver();
|
||||
$tagFactory = new StandardTagFactory($fqsenResolver);
|
||||
$descriptionFactory = new DescriptionFactory($tagFactory);
|
||||
$descriptionFactory = new DescriptionFactory($this->createMock(TagFactory::class));
|
||||
$context = new Context('');
|
||||
|
||||
$fixture = Link::create(
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ 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\DocBlock\TagFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen as FqsenRef;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen as TagsFqsen;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Url as UrlRef;
|
||||
@@ -266,8 +266,7 @@ class SeeTest extends TestCase
|
||||
public function testFactoryMethodWithoutUrl(): void
|
||||
{
|
||||
$fqsenResolver = new FqsenResolver();
|
||||
$tagFactory = new StandardTagFactory($fqsenResolver);
|
||||
$descriptionFactory = new DescriptionFactory($tagFactory);
|
||||
$descriptionFactory = new DescriptionFactory($this->createMock(TagFactory::class));
|
||||
$context = new Context('');
|
||||
|
||||
$fixture = See::create(
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -146,152 +142,4 @@ class ThrowsTest extends TestCase
|
||||
|
||||
$this->assertSame('string', (string) $fixture);
|
||||
}
|
||||
|
||||
/**
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Throws::<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 = Throws::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\Throws::<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 = Throws::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\Throws::<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);
|
||||
|
||||
Throws::create('array😁<string,😁 😁string> My Description', $resolver, $descriptionFactory, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Throws::<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 = Throws::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(Throws::create(''));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::create
|
||||
*/
|
||||
public function testFactoryMethodFailsIfResolverIsNull(): void
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
Throws::create('body');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::create
|
||||
*/
|
||||
public function testFactoryMethodFailsIfDescriptionFactoryIsNull(): void
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
Throws::create('body', new TypeResolver());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ 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\DocBlock\TagFactory;
|
||||
use phpDocumentor\Reflection\Fqsen;
|
||||
use phpDocumentor\Reflection\FqsenResolver;
|
||||
use phpDocumentor\Reflection\Types\Context;
|
||||
@@ -190,8 +190,7 @@ class UsesTest extends TestCase
|
||||
public function testFactoryMethodWithoutSpaceBeforeClass(): void
|
||||
{
|
||||
$fqsenResolver = new FqsenResolver();
|
||||
$tagFactory = new StandardTagFactory($fqsenResolver);
|
||||
$descriptionFactory = new DescriptionFactory($tagFactory);
|
||||
$descriptionFactory = new DescriptionFactory($this->createMock(TagFactory::class));
|
||||
$context = new Context('');
|
||||
|
||||
$fixture = Uses::create(
|
||||
@@ -220,8 +219,7 @@ class UsesTest extends TestCase
|
||||
public function testFactoryMethodWithSpaceBeforeClass(): void
|
||||
{
|
||||
$fqsenResolver = new FqsenResolver();
|
||||
$tagFactory = new StandardTagFactory($fqsenResolver);
|
||||
$descriptionFactory = new DescriptionFactory($tagFactory);
|
||||
$descriptionFactory = new DescriptionFactory($this->createMock(TagFactory::class));
|
||||
$context = new Context('');
|
||||
|
||||
$fixture = Uses::create(
|
||||
|
||||
@@ -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