Add Extends tags

This commit is contained in:
AhJ
2024-07-24 12:10:17 +03:30
parent a46da81e77
commit f387e8faa9
3 changed files with 129 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
<?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 Doctrine\Deprecations\Deprecation;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\DocBlock\Description;
use phpDocumentor\Reflection\DocBlock\Tags\TagWithType;
/**
* Reflection class for a {@}extends tag in a Docblock.
*/
class Extends_ extends TagWithType
{
public function __construct(Type $type, ?Description $description = null)
{
$this->name = 'extends';
$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)
{
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;
}
}
@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
use Webmozart\Assert\Assert;
use phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\TypeResolver;
use phpDocumentor\Reflection\Types\Context;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use phpDocumentor\Reflection\DocBlock\Tags\Extends_;
use PHPStan\PhpDocParser\Ast\PhpDoc\ExtendsTagValueNode;
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
use phpDocumentor\Reflection\DocBlock\Tags\TemplateExtends;
/**
* @internal This class is not part of the BC promise of this library.
*/
class ExtendsFactory 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, ExtendsTagValueNode::class);
$description = $tagValue->getAttribute('description');
if (is_string($description) === false) {
$description = $tagValue->description;
}
$class = $node->name === '@extends' ? Extends_::class : TemplateExtends::class;
return new $class(
$this->typeResolver->createType($tagValue->type, $context),
$this->descriptionFactory->create($tagValue->description, $context)
);
}
public function supports(PhpDocTagNode $node, Context $context): bool
{
return $node->value instanceof ExtendsTagValueNode && ($node->name === '@extends' || $node->name === '@template-extends');
}
}
+29
View File
@@ -0,0 +1,29 @@
<?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;
/**
* Reflection class for a {@}template-extends tag in a Docblock.
*/
final class TemplateExtends extends Extends_
{
public function __construct(Type $type, ?Description $description = null)
{
parent::__construct($type, $description);
$this->name = 'template-extends';
}
}