mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 10:07:12 +00:00
Add implements
This commit is contained in:
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
|
||||||
|
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
use phpDocumentor\Reflection\TypeResolver;
|
||||||
|
use phpDocumentor\Reflection\Types\Context;
|
||||||
|
use phpDocumentor\Reflection\DocBlock\Tag;
|
||||||
|
use phpDocumentor\Reflection\DocBlock\Tags\Implements_;
|
||||||
|
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||||
|
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
||||||
|
use PHPStan\PhpDocParser\Ast\PhpDoc\ImplementsTagValueNode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal This class is not part of the BC promise of this library.
|
||||||
|
*/
|
||||||
|
class ImplementsFactory 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, ImplementsTagValueNode::class);
|
||||||
|
|
||||||
|
return new Implements_(
|
||||||
|
$this->typeResolver->createType($tagValue->type, $context),
|
||||||
|
$this->descriptionFactory->create($tagValue->description, $context)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function supports(PhpDocTagNode $node, Context $context): bool
|
||||||
|
{
|
||||||
|
return $node->value instanceof ImplementsTagValueNode && $node->name === '@implements';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
use phpDocumentor\Reflection\Type;
|
||||||
|
use phpDocumentor\Reflection\DocBlock\Description;
|
||||||
|
use phpDocumentor\Reflection\DocBlock\Tags\TagWithType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reflection class for a {@}implements tag in a Docblock.
|
||||||
|
*/
|
||||||
|
final class Implements_ extends TagWithType
|
||||||
|
{
|
||||||
|
public function __construct(Type $type, ?Description $description = null)
|
||||||
|
{
|
||||||
|
$this->name = 'implements';
|
||||||
|
$this->type = $type;
|
||||||
|
$this->description = $description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function create(string $body)
|
||||||
|
{
|
||||||
|
trigger_error(
|
||||||
|
'Create using static factory is deprecated, this method should not be called directly
|
||||||
|
by library consumers',
|
||||||
|
E_USER_DEPRECATED
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __toString(): string
|
||||||
|
{
|
||||||
|
if ($this->description) {
|
||||||
|
$description = $this->description->render();
|
||||||
|
} else {
|
||||||
|
$description = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$type = $this->type;
|
||||||
|
|
||||||
|
return $type . ($description !== '' ? ' ' . $description : '');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,6 +28,7 @@ use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyReadFactory;
|
|||||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyWriteFactory;
|
use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyWriteFactory;
|
||||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ReturnFactory;
|
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ReturnFactory;
|
||||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\VarFactory;
|
use phpDocumentor\Reflection\DocBlock\Tags\Factory\VarFactory;
|
||||||
|
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ImplementsFactory;
|
||||||
use Webmozart\Assert\Assert;
|
use Webmozart\Assert\Assert;
|
||||||
|
|
||||||
use function array_shift;
|
use function array_shift;
|
||||||
@@ -76,7 +77,8 @@ final class DocBlockFactory implements DocBlockFactoryInterface
|
|||||||
new PropertyFactory($typeResolver, $descriptionFactory),
|
new PropertyFactory($typeResolver, $descriptionFactory),
|
||||||
new PropertyReadFactory($typeResolver, $descriptionFactory),
|
new PropertyReadFactory($typeResolver, $descriptionFactory),
|
||||||
new PropertyWriteFactory($typeResolver, $descriptionFactory),
|
new PropertyWriteFactory($typeResolver, $descriptionFactory),
|
||||||
new MethodFactory($typeResolver, $descriptionFactory)
|
new MethodFactory($typeResolver, $descriptionFactory),
|
||||||
|
new ImplementsFactory($typeResolver, $descriptionFactory)
|
||||||
);
|
);
|
||||||
|
|
||||||
$tagFactory->addService($descriptionFactory);
|
$tagFactory->addService($descriptionFactory);
|
||||||
@@ -88,6 +90,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
|
|||||||
$tagFactory->registerTagHandler('property-read', $phpstanTagFactory);
|
$tagFactory->registerTagHandler('property-read', $phpstanTagFactory);
|
||||||
$tagFactory->registerTagHandler('property-write', $phpstanTagFactory);
|
$tagFactory->registerTagHandler('property-write', $phpstanTagFactory);
|
||||||
$tagFactory->registerTagHandler('method', $phpstanTagFactory);
|
$tagFactory->registerTagHandler('method', $phpstanTagFactory);
|
||||||
|
$tagFactory->registerTagHandler('implements', $phpstanTagFactory);
|
||||||
|
|
||||||
$docBlockFactory = new self($descriptionFactory, $tagFactory);
|
$docBlockFactory = new self($descriptionFactory, $tagFactory);
|
||||||
foreach ($additionalTags as $tagName => $tagHandler) {
|
foreach ($additionalTags as $tagName => $tagHandler) {
|
||||||
|
|||||||
Reference in New Issue
Block a user