Skip to content

Commit bd5b5a8

Browse files
authored
Merge pull request #373 from ahjdev/5.x
Add new tags
2 parents aa53f8d + 47fea84 commit bd5b5a8

19 files changed

+721
-90
lines changed

src/DocBlock/StandardTagFactory.php

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,47 @@
1313

1414
namespace phpDocumentor\Reflection\DocBlock;
1515

16+
use function trim;
17+
use function count;
18+
use function strpos;
19+
use function sprintf;
20+
use ReflectionMethod;
21+
use function get_class;
22+
use function is_object;
23+
use function preg_match;
24+
use ReflectionNamedType;
25+
use ReflectionParameter;
26+
use function array_merge;
27+
use function array_slice;
28+
use Webmozart\Assert\Assert;
1629
use InvalidArgumentException;
30+
use function array_key_exists;
31+
use function call_user_func_array;
32+
use phpDocumentor\Reflection\FqsenResolver;
33+
use phpDocumentor\Reflection\DocBlock\Tags\Uses;
34+
use phpDocumentor\Reflection\DocBlock\Tags\Var_;
35+
use phpDocumentor\Reflection\DocBlock\Tags\Mixin;
36+
use phpDocumentor\Reflection\DocBlock\Tags\Param;
37+
use phpDocumentor\Reflection\DocBlock\Tags\Since;
1738
use phpDocumentor\Reflection\DocBlock\Tags\Author;
1839
use phpDocumentor\Reflection\DocBlock\Tags\Covers;
19-
use phpDocumentor\Reflection\DocBlock\Tags\Deprecated;
20-
use phpDocumentor\Reflection\DocBlock\Tags\Factory\Factory;
21-
use phpDocumentor\Reflection\DocBlock\Tags\Generic;
22-
use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag;
23-
use phpDocumentor\Reflection\DocBlock\Tags\Link as LinkTag;
2440
use phpDocumentor\Reflection\DocBlock\Tags\Method;
25-
use phpDocumentor\Reflection\DocBlock\Tags\Param;
41+
use phpDocumentor\Reflection\DocBlock\Tags\Source;
42+
use phpDocumentor\Reflection\DocBlock\Tags\Throws;
43+
use phpDocumentor\Reflection\DocBlock\Tags\Generic;
44+
45+
use phpDocumentor\Reflection\DocBlock\Tags\Return_;
46+
use phpDocumentor\Reflection\DocBlock\Tags\Version;
2647
use phpDocumentor\Reflection\DocBlock\Tags\Property;
48+
use phpDocumentor\Reflection\DocBlock\Tags\Deprecated;
49+
use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag;
2750
use phpDocumentor\Reflection\DocBlock\Tags\PropertyRead;
2851
use phpDocumentor\Reflection\DocBlock\Tags\PropertyWrite;
29-
use phpDocumentor\Reflection\DocBlock\Tags\Return_;
3052
use phpDocumentor\Reflection\DocBlock\Tags\See as SeeTag;
31-
use phpDocumentor\Reflection\DocBlock\Tags\Since;
32-
use phpDocumentor\Reflection\DocBlock\Tags\Source;
33-
use phpDocumentor\Reflection\DocBlock\Tags\Throws;
34-
use phpDocumentor\Reflection\DocBlock\Tags\Uses;
35-
use phpDocumentor\Reflection\DocBlock\Tags\Var_;
36-
use phpDocumentor\Reflection\DocBlock\Tags\Version;
37-
use phpDocumentor\Reflection\FqsenResolver;
3853
use phpDocumentor\Reflection\Types\Context as TypeContext;
39-
use ReflectionMethod;
40-
use ReflectionNamedType;
41-
use ReflectionParameter;
42-
use Webmozart\Assert\Assert;
43-
44-
use function array_key_exists;
45-
use function array_merge;
46-
use function array_slice;
47-
use function call_user_func_array;
48-
use function count;
49-
use function get_class;
50-
use function is_object;
51-
use function preg_match;
52-
use function sprintf;
53-
use function strpos;
54-
use function trim;
54+
use phpDocumentor\Reflection\DocBlock\Tags\Factory\Factory;
55+
use phpDocumentor\Reflection\DocBlock\Tags\Link as LinkTag;
56+
use phpDocumentor\Reflection\DocBlock\Tags\TemplateCovariant;
5557

5658
/**
5759
* Creates a Tag object given the contents of a tag.
@@ -80,25 +82,27 @@ final class StandardTagFactory implements TagFactory
8082
* FQCN to a class that handles it as an array value.
8183
*/
8284
private array $tagHandlerMappings = [
83-
'author' => Author::class,
84-
'covers' => Covers::class,
85-
'deprecated' => Deprecated::class,
86-
// 'example' => '\phpDocumentor\Reflection\DocBlock\Tags\Example',
87-
'link' => LinkTag::class,
88-
'method' => Method::class,
89-
'param' => Param::class,
90-
'property-read' => PropertyRead::class,
91-
'property' => Property::class,
92-
'property-write' => PropertyWrite::class,
93-
'return' => Return_::class,
94-
'see' => SeeTag::class,
95-
'since' => Since::class,
96-
'source' => Source::class,
97-
'throw' => Throws::class,
98-
'throws' => Throws::class,
99-
'uses' => Uses::class,
100-
'var' => Var_::class,
101-
'version' => Version::class,
85+
'author' => Author::class,
86+
'covers' => Covers::class,
87+
'deprecated' => Deprecated::class,
88+
// 'example' => '\phpDocumentor\Reflection\DocBlock\Tags\Example',
89+
'link' => LinkTag::class,
90+
'mixin' => Mixin::class,
91+
'method' => Method::class,
92+
'param' => Param::class,
93+
'property-read' => PropertyRead::class,
94+
'property' => Property::class,
95+
'property-write' => PropertyWrite::class,
96+
'return' => Return_::class,
97+
'see' => SeeTag::class,
98+
'since' => Since::class,
99+
'source' => Source::class,
100+
'template-covariant' => TemplateCovariant::class,
101+
'throw' => Throws::class,
102+
'throws' => Throws::class,
103+
'uses' => Uses::class,
104+
'var' => Var_::class,
105+
'version' => Version::class,
102106
];
103107

104108
/**

src/DocBlock/Tags/Extends_.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link http://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Reflection\DocBlock\Tags;
15+
16+
use Doctrine\Deprecations\Deprecation;
17+
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\DocBlock\Description;
19+
use phpDocumentor\Reflection\DocBlock\Tags\TagWithType;
20+
21+
/**
22+
* Reflection class for a {@}extends tag in a Docblock.
23+
*/
24+
class Extends_ extends TagWithType
25+
{
26+
public function __construct(Type $type, ?Description $description = null)
27+
{
28+
$this->name = 'extends';
29+
$this->type = $type;
30+
$this->description = $description;
31+
}
32+
33+
/**
34+
* @deprecated Create using static factory is deprecated,
35+
* this method should not be called directly by library consumers
36+
*/
37+
public static function create(string $body)
38+
{
39+
Deprecation::trigger(
40+
'phpdocumentor/reflection-docblock',
41+
'https://github.com/phpDocumentor/ReflectionDocBlock/issues/361',
42+
'Create using static factory is deprecated, this method should not be called directly
43+
by library consumers',
44+
);
45+
return null;
46+
}
47+
}
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+
}
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\Tags\Extends_;
13+
use PHPStan\PhpDocParser\Ast\PhpDoc\ExtendsTagValueNode;
14+
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
15+
16+
/**
17+
* @internal This class is not part of the BC promise of this library.
18+
*/
19+
final class ExtendsFactory extends AbstractExtendsFactory
20+
{
21+
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
22+
{
23+
parent::__construct($typeResolver, $descriptionFactory);
24+
$this->tagName = '@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 Extends_(
38+
$this->typeResolver->createType($tagValue->type, $context),
39+
$this->descriptionFactory->create($description, $context)
40+
);
41+
}
42+
}
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\Tags\Implements_;
13+
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
14+
use PHPStan\PhpDocParser\Ast\PhpDoc\ImplementsTagValueNode;
15+
16+
/**
17+
* @internal This class is not part of the BC promise of this library.
18+
*/
19+
final class ImplementsFactory extends AbstractImplementsFactory
20+
{
21+
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
22+
{
23+
parent::__construct($typeResolver, $descriptionFactory);
24+
$this->tagName = '@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 Implements_(
38+
$this->typeResolver->createType($tagValue->type, $context),
39+
$this->descriptionFactory->create($description, $context)
40+
);
41+
}
42+
}
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+
}

0 commit comments

Comments
 (0)