Skip to content

Commit f387e8f

Browse files
committed
Add Extends tags
1 parent a46da81 commit f387e8f

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed

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: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
use phpDocumentor\Reflection\DocBlock\Tags\TemplateExtends;
16+
17+
/**
18+
* @internal This class is not part of the BC promise of this library.
19+
*/
20+
class ExtendsFactory implements PHPStanFactory
21+
{
22+
private DescriptionFactory $descriptionFactory;
23+
private TypeResolver $typeResolver;
24+
25+
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
26+
{
27+
$this->descriptionFactory = $descriptionFactory;
28+
$this->typeResolver = $typeResolver;
29+
}
30+
31+
public function create(PhpDocTagNode $node, Context $context): Tag
32+
{
33+
$tagValue = $node->value;
34+
Assert::isInstanceOf($tagValue, ExtendsTagValueNode::class);
35+
36+
$description = $tagValue->getAttribute('description');
37+
if (is_string($description) === false) {
38+
$description = $tagValue->description;
39+
}
40+
41+
$class = $node->name === '@extends' ? Extends_::class : TemplateExtends::class;
42+
43+
return new $class(
44+
$this->typeResolver->createType($tagValue->type, $context),
45+
$this->descriptionFactory->create($tagValue->description, $context)
46+
);
47+
}
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+
}
53+
}

src/DocBlock/Tags/TemplateExtends.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 phpDocumentor\Reflection\Type;
17+
use phpDocumentor\Reflection\DocBlock\Description;
18+
19+
/**
20+
* Reflection class for a {@}template-extends tag in a Docblock.
21+
*/
22+
final class TemplateExtends extends Extends_
23+
{
24+
public function __construct(Type $type, ?Description $description = null)
25+
{
26+
parent::__construct($type, $description);
27+
$this->name = 'template-extends';
28+
}
29+
}

0 commit comments

Comments
 (0)