mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 01:57:13 +00:00
Seprate template-* tags
This commit is contained in:
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
|
||||||
|
|
||||||
|
use phpDocumentor\Reflection\TypeResolver;
|
||||||
|
use phpDocumentor\Reflection\Types\Context;
|
||||||
|
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
||||||
|
use PHPStan\PhpDocParser\Ast\PhpDoc\ExtendsTagValueNode;
|
||||||
|
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal This class is not part of the BC promise of this library.
|
||||||
|
*/
|
||||||
|
abstract class AbstractExtendsFactory implements PHPStanFactory
|
||||||
|
{
|
||||||
|
private DescriptionFactory $descriptionFactory;
|
||||||
|
private TypeResolver $typeResolver;
|
||||||
|
protected string $tagName;
|
||||||
|
|
||||||
|
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
|
||||||
|
{
|
||||||
|
$this->descriptionFactory = $descriptionFactory;
|
||||||
|
$this->typeResolver = $typeResolver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function supports(PhpDocTagNode $node, Context $context): bool
|
||||||
|
{
|
||||||
|
return $node->value instanceof ExtendsTagValueNode && $node->name === $this->tagName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
|
||||||
|
|
||||||
|
use phpDocumentor\Reflection\TypeResolver;
|
||||||
|
use phpDocumentor\Reflection\Types\Context;
|
||||||
|
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
||||||
|
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||||
|
use PHPStan\PhpDocParser\Ast\PhpDoc\ImplementsTagValueNode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal This class is not part of the BC promise of this library.
|
||||||
|
*/
|
||||||
|
abstract class AbstractImplementsFactory implements PHPStanFactory
|
||||||
|
{
|
||||||
|
private DescriptionFactory $descriptionFactory;
|
||||||
|
private TypeResolver $typeResolver;
|
||||||
|
protected string $tagName;
|
||||||
|
|
||||||
|
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
|
||||||
|
{
|
||||||
|
$this->descriptionFactory = $descriptionFactory;
|
||||||
|
$this->typeResolver = $typeResolver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function supports(PhpDocTagNode $node, Context $context): bool
|
||||||
|
{
|
||||||
|
return $node->value instanceof ImplementsTagValueNode && $node->name === $this->tagName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,20 +12,16 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
|||||||
use phpDocumentor\Reflection\DocBlock\Tags\Extends_;
|
use phpDocumentor\Reflection\DocBlock\Tags\Extends_;
|
||||||
use PHPStan\PhpDocParser\Ast\PhpDoc\ExtendsTagValueNode;
|
use PHPStan\PhpDocParser\Ast\PhpDoc\ExtendsTagValueNode;
|
||||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||||
use phpDocumentor\Reflection\DocBlock\Tags\TemplateExtends;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal This class is not part of the BC promise of this library.
|
* @internal This class is not part of the BC promise of this library.
|
||||||
*/
|
*/
|
||||||
class ExtendsFactory implements PHPStanFactory
|
final class ExtendsFactory extends AbstractExtendsFactory
|
||||||
{
|
{
|
||||||
private DescriptionFactory $descriptionFactory;
|
|
||||||
private TypeResolver $typeResolver;
|
|
||||||
|
|
||||||
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
|
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
|
||||||
{
|
{
|
||||||
$this->descriptionFactory = $descriptionFactory;
|
parent::__construct($typeResolver, $descriptionFactory);
|
||||||
$this->typeResolver = $typeResolver;
|
$this->tagName = '@extends';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(PhpDocTagNode $node, Context $context): Tag
|
public function create(PhpDocTagNode $node, Context $context): Tag
|
||||||
@@ -38,16 +34,9 @@ class ExtendsFactory implements PHPStanFactory
|
|||||||
$description = $tagValue->description;
|
$description = $tagValue->description;
|
||||||
}
|
}
|
||||||
|
|
||||||
$class = $node->name === '@extends' ? Extends_::class : TemplateExtends::class;
|
return new Extends_(
|
||||||
|
|
||||||
return new $class(
|
|
||||||
$this->typeResolver->createType($tagValue->type, $context),
|
$this->typeResolver->createType($tagValue->type, $context),
|
||||||
$this->descriptionFactory->create($tagValue->description, $context)
|
$this->descriptionFactory->create($description, $context)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function supports(PhpDocTagNode $node, Context $context): bool
|
|
||||||
{
|
|
||||||
return $node->value instanceof ExtendsTagValueNode && ($node->name === '@extends' || $node->name === '@template-extends');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,20 +12,16 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
|||||||
use phpDocumentor\Reflection\DocBlock\Tags\Implements_;
|
use phpDocumentor\Reflection\DocBlock\Tags\Implements_;
|
||||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||||
use PHPStan\PhpDocParser\Ast\PhpDoc\ImplementsTagValueNode;
|
use PHPStan\PhpDocParser\Ast\PhpDoc\ImplementsTagValueNode;
|
||||||
use phpDocumentor\Reflection\DocBlock\Tags\TemplateImplements;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal This class is not part of the BC promise of this library.
|
* @internal This class is not part of the BC promise of this library.
|
||||||
*/
|
*/
|
||||||
class ImplementsFactory implements PHPStanFactory
|
final class ImplementsFactory extends AbstractImplementsFactory
|
||||||
{
|
{
|
||||||
private DescriptionFactory $descriptionFactory;
|
|
||||||
private TypeResolver $typeResolver;
|
|
||||||
|
|
||||||
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
|
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
|
||||||
{
|
{
|
||||||
$this->descriptionFactory = $descriptionFactory;
|
parent::__construct($typeResolver, $descriptionFactory);
|
||||||
$this->typeResolver = $typeResolver;
|
$this->tagName = '@implements';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(PhpDocTagNode $node, Context $context): Tag
|
public function create(PhpDocTagNode $node, Context $context): Tag
|
||||||
@@ -38,16 +34,9 @@ class ImplementsFactory implements PHPStanFactory
|
|||||||
$description = $tagValue->description;
|
$description = $tagValue->description;
|
||||||
}
|
}
|
||||||
|
|
||||||
$class = $node->name === '@implements' ? Implements_::class : TemplateImplements::class;
|
return new Implements_(
|
||||||
|
|
||||||
return new $class(
|
|
||||||
$this->typeResolver->createType($tagValue->type, $context),
|
$this->typeResolver->createType($tagValue->type, $context),
|
||||||
$this->descriptionFactory->create($tagValue->description, $context)
|
$this->descriptionFactory->create($description, $context)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function supports(PhpDocTagNode $node, Context $context): bool
|
|
||||||
{
|
|
||||||
return $node->value instanceof ImplementsTagValueNode && ($node->name === '@implements' || $node->name === '@template-implements');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?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 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.
|
||||||
|
*/
|
||||||
|
final class TemplateExtendsFactory extends AbstractExtendsFactory
|
||||||
|
{
|
||||||
|
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
|
||||||
|
{
|
||||||
|
parent::__construct($typeResolver, $descriptionFactory);
|
||||||
|
$this->tagName = '@template-extends';
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new TemplateExtends(
|
||||||
|
$this->typeResolver->createType($tagValue->type, $context),
|
||||||
|
$this->descriptionFactory->create($description, $context)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -41,7 +41,7 @@ final class TemplateFactory implements PHPStanFactory
|
|||||||
$tagValue->name,
|
$tagValue->name,
|
||||||
$this->typeResolver->createType($tagValue->bound, $context),
|
$this->typeResolver->createType($tagValue->bound, $context),
|
||||||
$this->typeResolver->createType($tagValue->default, $context),
|
$this->typeResolver->createType($tagValue->default, $context),
|
||||||
$this->descriptionFactory->create($tagValue->description, $context)
|
$this->descriptionFactory->create($description, $context)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?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\DescriptionFactory;
|
||||||
|
use PHPStan\PhpDocParser\Ast\PhpDoc\ImplementsTagValueNode;
|
||||||
|
use phpDocumentor\Reflection\DocBlock\Tags\TemplateImplements;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal This class is not part of the BC promise of this library.
|
||||||
|
*/
|
||||||
|
final class TemplateImplementsFactory extends AbstractImplementsFactory
|
||||||
|
{
|
||||||
|
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
|
||||||
|
{
|
||||||
|
parent::__construct($typeResolver, $descriptionFactory);
|
||||||
|
$this->tagName = '@template-implements';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(PhpDocTagNode $node, Context $context): Tag
|
||||||
|
{
|
||||||
|
$tagValue = $node->value;
|
||||||
|
Assert::isInstanceOf($tagValue, ImplementsTagValueNode::class);
|
||||||
|
|
||||||
|
$description = $tagValue->getAttribute('description');
|
||||||
|
if (is_string($description) === false) {
|
||||||
|
$description = $tagValue->description;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new TemplateImplements(
|
||||||
|
$this->typeResolver->createType($tagValue->type, $context),
|
||||||
|
$this->descriptionFactory->create($description, $context)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,6 +32,8 @@ use phpDocumentor\Reflection\DocBlock\Tags\Factory\ImplementsFactory;
|
|||||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyReadFactory;
|
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\AbstractPHPStanFactory;
|
use phpDocumentor\Reflection\DocBlock\Tags\Factory\AbstractPHPStanFactory;
|
||||||
|
use phpDocumentor\Reflection\DocBlock\Tags\Factory\TemplateExtendsFactory;
|
||||||
|
use phpDocumentor\Reflection\DocBlock\Tags\Factory\TemplateImplementsFactory;
|
||||||
|
|
||||||
use function trim;
|
use function trim;
|
||||||
use function count;
|
use function count;
|
||||||
@@ -81,8 +83,10 @@ final class DocBlockFactory implements DocBlockFactoryInterface
|
|||||||
new PropertyWriteFactory($typeResolver, $descriptionFactory),
|
new PropertyWriteFactory($typeResolver, $descriptionFactory),
|
||||||
new MethodFactory($typeResolver, $descriptionFactory),
|
new MethodFactory($typeResolver, $descriptionFactory),
|
||||||
new ImplementsFactory($typeResolver, $descriptionFactory),
|
new ImplementsFactory($typeResolver, $descriptionFactory),
|
||||||
new TemplateFactory($typeResolver, $descriptionFactory),
|
|
||||||
new ExtendsFactory($typeResolver, $descriptionFactory),
|
new ExtendsFactory($typeResolver, $descriptionFactory),
|
||||||
|
new TemplateFactory($typeResolver, $descriptionFactory),
|
||||||
|
new TemplateImplementsFactory($typeResolver, $descriptionFactory),
|
||||||
|
new TemplateExtendsFactory($typeResolver, $descriptionFactory),
|
||||||
);
|
);
|
||||||
|
|
||||||
$tagFactory->addService($descriptionFactory);
|
$tagFactory->addService($descriptionFactory);
|
||||||
|
|||||||
Reference in New Issue
Block a user