Seprate template-* tags

This commit is contained in:
AhJ
2024-07-27 18:06:52 +03:30
parent f93a6b70aa
commit f17d98425c
8 changed files with 164 additions and 34 deletions
@@ -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;
}
}
+5 -16
View File
@@ -12,20 +12,16 @@ 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
final class ExtendsFactory extends AbstractExtendsFactory
{
private DescriptionFactory $descriptionFactory;
private TypeResolver $typeResolver;
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
{
$this->descriptionFactory = $descriptionFactory;
$this->typeResolver = $typeResolver;
parent::__construct($typeResolver, $descriptionFactory);
$this->tagName = '@extends';
}
public function create(PhpDocTagNode $node, Context $context): Tag
@@ -38,16 +34,9 @@ class ExtendsFactory implements PHPStanFactory
$description = $tagValue->description;
}
$class = $node->name === '@extends' ? Extends_::class : TemplateExtends::class;
return new $class(
return new Extends_(
$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\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.
*/
class ImplementsFactory implements PHPStanFactory
final class ImplementsFactory extends AbstractImplementsFactory
{
private DescriptionFactory $descriptionFactory;
private TypeResolver $typeResolver;
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
{
$this->descriptionFactory = $descriptionFactory;
$this->typeResolver = $typeResolver;
parent::__construct($typeResolver, $descriptionFactory);
$this->tagName = '@implements';
}
public function create(PhpDocTagNode $node, Context $context): Tag
@@ -38,16 +34,9 @@ class ImplementsFactory implements PHPStanFactory
$description = $tagValue->description;
}
$class = $node->name === '@implements' ? Implements_::class : TemplateImplements::class;
return new $class(
return new Implements_(
$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,
$this->typeResolver->createType($tagValue->bound, $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)
);
}
}