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 : '');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user