mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 18:13:13 +00:00
Add Extends tags
This commit is contained in:
@@ -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');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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';
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user