Skip to content

Commit f17d984

Browse files
committed
Seprate template-* tags
1 parent f93a6b7 commit f17d984

8 files changed

+164
-34
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
6+
7+
use phpDocumentor\Reflection\TypeResolver;
8+
use phpDocumentor\Reflection\Types\Context;
9+
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
10+
use PHPStan\PhpDocParser\Ast\PhpDoc\ExtendsTagValueNode;
11+
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
12+
13+
/**
14+
* @internal This class is not part of the BC promise of this library.
15+
*/
16+
abstract class AbstractExtendsFactory implements PHPStanFactory
17+
{
18+
private DescriptionFactory $descriptionFactory;
19+
private TypeResolver $typeResolver;
20+
protected string $tagName;
21+
22+
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
23+
{
24+
$this->descriptionFactory = $descriptionFactory;
25+
$this->typeResolver = $typeResolver;
26+
}
27+
28+
public function supports(PhpDocTagNode $node, Context $context): bool
29+
{
30+
return $node->value instanceof ExtendsTagValueNode && $node->name === $this->tagName;
31+
}
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
6+
7+
use phpDocumentor\Reflection\TypeResolver;
8+
use phpDocumentor\Reflection\Types\Context;
9+
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
10+
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
11+
use PHPStan\PhpDocParser\Ast\PhpDoc\ImplementsTagValueNode;
12+
13+
/**
14+
* @internal This class is not part of the BC promise of this library.
15+
*/
16+
abstract class AbstractImplementsFactory implements PHPStanFactory
17+
{
18+
private DescriptionFactory $descriptionFactory;
19+
private TypeResolver $typeResolver;
20+
protected string $tagName;
21+
22+
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
23+
{
24+
$this->descriptionFactory = $descriptionFactory;
25+
$this->typeResolver = $typeResolver;
26+
}
27+
28+
public function supports(PhpDocTagNode $node, Context $context): bool
29+
{
30+
return $node->value instanceof ImplementsTagValueNode && $node->name === $this->tagName;
31+
}
32+
}

src/DocBlock/Tags/Factory/ExtendsFactory.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,16 @@
1212
use phpDocumentor\Reflection\DocBlock\Tags\Extends_;
1313
use PHPStan\PhpDocParser\Ast\PhpDoc\ExtendsTagValueNode;
1414
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
15-
use phpDocumentor\Reflection\DocBlock\Tags\TemplateExtends;
1615

1716
/**
1817
* @internal This class is not part of the BC promise of this library.
1918
*/
20-
class ExtendsFactory implements PHPStanFactory
19+
final class ExtendsFactory extends AbstractExtendsFactory
2120
{
22-
private DescriptionFactory $descriptionFactory;
23-
private TypeResolver $typeResolver;
24-
2521
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
2622
{
27-
$this->descriptionFactory = $descriptionFactory;
28-
$this->typeResolver = $typeResolver;
23+
parent::__construct($typeResolver, $descriptionFactory);
24+
$this->tagName = '@extends';
2925
}
3026

3127
public function create(PhpDocTagNode $node, Context $context): Tag
@@ -38,16 +34,9 @@ public function create(PhpDocTagNode $node, Context $context): Tag
3834
$description = $tagValue->description;
3935
}
4036

41-
$class = $node->name === '@extends' ? Extends_::class : TemplateExtends::class;
42-
43-
return new $class(
37+
return new Extends_(
4438
$this->typeResolver->createType($tagValue->type, $context),
45-
$this->descriptionFactory->create($tagValue->description, $context)
39+
$this->descriptionFactory->create($description, $context)
4640
);
4741
}
48-
49-
public function supports(PhpDocTagNode $node, Context $context): bool
50-
{
51-
return $node->value instanceof ExtendsTagValueNode && ($node->name === '@extends' || $node->name === '@template-extends');
52-
}
5342
}

src/DocBlock/Tags/Factory/ImplementsFactory.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,16 @@
1212
use phpDocumentor\Reflection\DocBlock\Tags\Implements_;
1313
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
1414
use PHPStan\PhpDocParser\Ast\PhpDoc\ImplementsTagValueNode;
15-
use phpDocumentor\Reflection\DocBlock\Tags\TemplateImplements;
1615

1716
/**
1817
* @internal This class is not part of the BC promise of this library.
1918
*/
20-
class ImplementsFactory implements PHPStanFactory
19+
final class ImplementsFactory extends AbstractImplementsFactory
2120
{
22-
private DescriptionFactory $descriptionFactory;
23-
private TypeResolver $typeResolver;
24-
2521
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
2622
{
27-
$this->descriptionFactory = $descriptionFactory;
28-
$this->typeResolver = $typeResolver;
23+
parent::__construct($typeResolver, $descriptionFactory);
24+
$this->tagName = '@implements';
2925
}
3026

3127
public function create(PhpDocTagNode $node, Context $context): Tag
@@ -38,16 +34,9 @@ public function create(PhpDocTagNode $node, Context $context): Tag
3834
$description = $tagValue->description;
3935
}
4036

41-
$class = $node->name === '@implements' ? Implements_::class : TemplateImplements::class;
42-
43-
return new $class(
37+
return new Implements_(
4438
$this->typeResolver->createType($tagValue->type, $context),
45-
$this->descriptionFactory->create($tagValue->description, $context)
39+
$this->descriptionFactory->create($description, $context)
4640
);
4741
}
48-
49-
public function supports(PhpDocTagNode $node, Context $context): bool
50-
{
51-
return $node->value instanceof ImplementsTagValueNode && ($node->name === '@implements' || $node->name === '@template-implements');
52-
}
5342
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
6+
7+
use Webmozart\Assert\Assert;
8+
use phpDocumentor\Reflection\DocBlock\Tag;
9+
use phpDocumentor\Reflection\TypeResolver;
10+
use phpDocumentor\Reflection\Types\Context;
11+
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
12+
use PHPStan\PhpDocParser\Ast\PhpDoc\ExtendsTagValueNode;
13+
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
14+
use phpDocumentor\Reflection\DocBlock\Tags\TemplateExtends;
15+
16+
/**
17+
* @internal This class is not part of the BC promise of this library.
18+
*/
19+
final class TemplateExtendsFactory extends AbstractExtendsFactory
20+
{
21+
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
22+
{
23+
parent::__construct($typeResolver, $descriptionFactory);
24+
$this->tagName = '@template-extends';
25+
}
26+
27+
public function create(PhpDocTagNode $node, Context $context): Tag
28+
{
29+
$tagValue = $node->value;
30+
Assert::isInstanceOf($tagValue, ExtendsTagValueNode::class);
31+
32+
$description = $tagValue->getAttribute('description');
33+
if (is_string($description) === false) {
34+
$description = $tagValue->description;
35+
}
36+
37+
return new TemplateExtends(
38+
$this->typeResolver->createType($tagValue->type, $context),
39+
$this->descriptionFactory->create($description, $context)
40+
);
41+
}
42+
}

src/DocBlock/Tags/Factory/TemplateFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function create(PhpDocTagNode $node, Context $context): Tag
4141
$tagValue->name,
4242
$this->typeResolver->createType($tagValue->bound, $context),
4343
$this->typeResolver->createType($tagValue->default, $context),
44-
$this->descriptionFactory->create($tagValue->description, $context)
44+
$this->descriptionFactory->create($description, $context)
4545
);
4646
}
4747

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
6+
7+
use Webmozart\Assert\Assert;
8+
use phpDocumentor\Reflection\DocBlock\Tag;
9+
use phpDocumentor\Reflection\TypeResolver;
10+
use phpDocumentor\Reflection\Types\Context;
11+
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
12+
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
13+
use PHPStan\PhpDocParser\Ast\PhpDoc\ImplementsTagValueNode;
14+
use phpDocumentor\Reflection\DocBlock\Tags\TemplateImplements;
15+
16+
/**
17+
* @internal This class is not part of the BC promise of this library.
18+
*/
19+
final class TemplateImplementsFactory extends AbstractImplementsFactory
20+
{
21+
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
22+
{
23+
parent::__construct($typeResolver, $descriptionFactory);
24+
$this->tagName = '@template-implements';
25+
}
26+
27+
public function create(PhpDocTagNode $node, Context $context): Tag
28+
{
29+
$tagValue = $node->value;
30+
Assert::isInstanceOf($tagValue, ImplementsTagValueNode::class);
31+
32+
$description = $tagValue->getAttribute('description');
33+
if (is_string($description) === false) {
34+
$description = $tagValue->description;
35+
}
36+
37+
return new TemplateImplements(
38+
$this->typeResolver->createType($tagValue->type, $context),
39+
$this->descriptionFactory->create($description, $context)
40+
);
41+
}
42+
}

src/DocBlockFactory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyReadFactory;
3333
use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyWriteFactory;
3434
use phpDocumentor\Reflection\DocBlock\Tags\Factory\AbstractPHPStanFactory;
35+
use phpDocumentor\Reflection\DocBlock\Tags\Factory\TemplateExtendsFactory;
36+
use phpDocumentor\Reflection\DocBlock\Tags\Factory\TemplateImplementsFactory;
3537

3638
use function trim;
3739
use function count;
@@ -81,8 +83,10 @@ public static function createInstance(array $additionalTags = []): DocBlockFacto
8183
new PropertyWriteFactory($typeResolver, $descriptionFactory),
8284
new MethodFactory($typeResolver, $descriptionFactory),
8385
new ImplementsFactory($typeResolver, $descriptionFactory),
84-
new TemplateFactory($typeResolver, $descriptionFactory),
8586
new ExtendsFactory($typeResolver, $descriptionFactory),
87+
new TemplateFactory($typeResolver, $descriptionFactory),
88+
new TemplateImplementsFactory($typeResolver, $descriptionFactory),
89+
new TemplateExtendsFactory($typeResolver, $descriptionFactory),
8690
);
8791

8892
$tagFactory->addService($descriptionFactory);

0 commit comments

Comments
 (0)