Skip to content

Commit

Permalink
Merge pull request #373 from ahjdev/5.x
Browse files Browse the repository at this point in the history
Add new tags
  • Loading branch information
jaapio authored Aug 14, 2024
2 parents aa53f8d + 47fea84 commit bd5b5a8
Show file tree
Hide file tree
Showing 19 changed files with 721 additions and 90 deletions.
102 changes: 53 additions & 49 deletions src/DocBlock/StandardTagFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,47 @@

namespace phpDocumentor\Reflection\DocBlock;

use function trim;
use function count;
use function strpos;
use function sprintf;
use ReflectionMethod;
use function get_class;
use function is_object;
use function preg_match;
use ReflectionNamedType;
use ReflectionParameter;
use function array_merge;
use function array_slice;
use Webmozart\Assert\Assert;
use InvalidArgumentException;
use function array_key_exists;
use function call_user_func_array;
use phpDocumentor\Reflection\FqsenResolver;
use phpDocumentor\Reflection\DocBlock\Tags\Uses;
use phpDocumentor\Reflection\DocBlock\Tags\Var_;
use phpDocumentor\Reflection\DocBlock\Tags\Mixin;
use phpDocumentor\Reflection\DocBlock\Tags\Param;
use phpDocumentor\Reflection\DocBlock\Tags\Since;
use phpDocumentor\Reflection\DocBlock\Tags\Author;
use phpDocumentor\Reflection\DocBlock\Tags\Covers;
use phpDocumentor\Reflection\DocBlock\Tags\Deprecated;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\Factory;
use phpDocumentor\Reflection\DocBlock\Tags\Generic;
use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag;
use phpDocumentor\Reflection\DocBlock\Tags\Link as LinkTag;
use phpDocumentor\Reflection\DocBlock\Tags\Method;
use phpDocumentor\Reflection\DocBlock\Tags\Param;
use phpDocumentor\Reflection\DocBlock\Tags\Source;
use phpDocumentor\Reflection\DocBlock\Tags\Throws;
use phpDocumentor\Reflection\DocBlock\Tags\Generic;

use phpDocumentor\Reflection\DocBlock\Tags\Return_;
use phpDocumentor\Reflection\DocBlock\Tags\Version;
use phpDocumentor\Reflection\DocBlock\Tags\Property;
use phpDocumentor\Reflection\DocBlock\Tags\Deprecated;
use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag;
use phpDocumentor\Reflection\DocBlock\Tags\PropertyRead;
use phpDocumentor\Reflection\DocBlock\Tags\PropertyWrite;
use phpDocumentor\Reflection\DocBlock\Tags\Return_;
use phpDocumentor\Reflection\DocBlock\Tags\See as SeeTag;
use phpDocumentor\Reflection\DocBlock\Tags\Since;
use phpDocumentor\Reflection\DocBlock\Tags\Source;
use phpDocumentor\Reflection\DocBlock\Tags\Throws;
use phpDocumentor\Reflection\DocBlock\Tags\Uses;
use phpDocumentor\Reflection\DocBlock\Tags\Var_;
use phpDocumentor\Reflection\DocBlock\Tags\Version;
use phpDocumentor\Reflection\FqsenResolver;
use phpDocumentor\Reflection\Types\Context as TypeContext;
use ReflectionMethod;
use ReflectionNamedType;
use ReflectionParameter;
use Webmozart\Assert\Assert;

use function array_key_exists;
use function array_merge;
use function array_slice;
use function call_user_func_array;
use function count;
use function get_class;
use function is_object;
use function preg_match;
use function sprintf;
use function strpos;
use function trim;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\Factory;
use phpDocumentor\Reflection\DocBlock\Tags\Link as LinkTag;
use phpDocumentor\Reflection\DocBlock\Tags\TemplateCovariant;

/**
* Creates a Tag object given the contents of a tag.
Expand Down Expand Up @@ -80,25 +82,27 @@ final class StandardTagFactory implements TagFactory
* FQCN to a class that handles it as an array value.
*/
private array $tagHandlerMappings = [
'author' => Author::class,
'covers' => Covers::class,
'deprecated' => Deprecated::class,
// 'example' => '\phpDocumentor\Reflection\DocBlock\Tags\Example',
'link' => LinkTag::class,
'method' => Method::class,
'param' => Param::class,
'property-read' => PropertyRead::class,
'property' => Property::class,
'property-write' => PropertyWrite::class,
'return' => Return_::class,
'see' => SeeTag::class,
'since' => Since::class,
'source' => Source::class,
'throw' => Throws::class,
'throws' => Throws::class,
'uses' => Uses::class,
'var' => Var_::class,
'version' => Version::class,
'author' => Author::class,
'covers' => Covers::class,
'deprecated' => Deprecated::class,
// 'example' => '\phpDocumentor\Reflection\DocBlock\Tags\Example',
'link' => LinkTag::class,
'mixin' => Mixin::class,
'method' => Method::class,
'param' => Param::class,
'property-read' => PropertyRead::class,
'property' => Property::class,
'property-write' => PropertyWrite::class,
'return' => Return_::class,
'see' => SeeTag::class,
'since' => Since::class,
'source' => Source::class,
'template-covariant' => TemplateCovariant::class,
'throw' => Throws::class,
'throws' => Throws::class,
'uses' => Uses::class,
'var' => Var_::class,
'version' => Version::class,
];

/**
Expand Down
47 changes: 47 additions & 0 deletions src/DocBlock/Tags/Extends_.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/

namespace phpDocumentor\Reflection\DocBlock\Tags;

use Doctrine\Deprecations\Deprecation;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\DocBlock\Description;
use phpDocumentor\Reflection\DocBlock\Tags\TagWithType;

/**
* Reflection class for a {@}extends tag in a Docblock.
*/
class Extends_ extends TagWithType
{
public function __construct(Type $type, ?Description $description = null)
{
$this->name = 'extends';
$this->type = $type;
$this->description = $description;
}

/**
* @deprecated Create using static factory is deprecated,
* this method should not be called directly by library consumers
*/
public static function create(string $body)
{
Deprecation::trigger(
'phpdocumentor/reflection-docblock',
'https://github.com/phpDocumentor/ReflectionDocBlock/issues/361',
'Create using static factory is deprecated, this method should not be called directly
by library consumers',
);
return null;
}
}
32 changes: 32 additions & 0 deletions src/DocBlock/Tags/Factory/AbstractExtendsFactory.php
Original file line number Diff line number Diff line change
@@ -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;

Check failure on line 18 in src/DocBlock/Tags/Factory/AbstractExtendsFactory.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.0)

Property phpDocumentor\Reflection\DocBlock\Tags\Factory\AbstractExtendsFactory::$descriptionFactory is never read, only written.
private TypeResolver $typeResolver;

Check failure on line 19 in src/DocBlock/Tags/Factory/AbstractExtendsFactory.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.0)

Property phpDocumentor\Reflection\DocBlock\Tags\Factory\AbstractExtendsFactory::$typeResolver is never read, only written.
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;
}
}
32 changes: 32 additions & 0 deletions src/DocBlock/Tags/Factory/AbstractImplementsFactory.php
Original file line number Diff line number Diff line change
@@ -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;

Check failure on line 18 in src/DocBlock/Tags/Factory/AbstractImplementsFactory.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.0)

Property phpDocumentor\Reflection\DocBlock\Tags\Factory\AbstractImplementsFactory::$descriptionFactory is never read, only written.
private TypeResolver $typeResolver;

Check failure on line 19 in src/DocBlock/Tags/Factory/AbstractImplementsFactory.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.0)

Property phpDocumentor\Reflection\DocBlock\Tags\Factory\AbstractImplementsFactory::$typeResolver is never read, only written.
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;
}
}
42 changes: 42 additions & 0 deletions src/DocBlock/Tags/Factory/ExtendsFactory.php
Original file line number Diff line number Diff line change
@@ -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\Tags\Extends_;
use PHPStan\PhpDocParser\Ast\PhpDoc\ExtendsTagValueNode;
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;

/**
* @internal This class is not part of the BC promise of this library.
*/
final class ExtendsFactory extends AbstractExtendsFactory
{
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
{
parent::__construct($typeResolver, $descriptionFactory);
$this->tagName = '@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 Extends_(
$this->typeResolver->createType($tagValue->type, $context),

Check failure on line 38 in src/DocBlock/Tags/Factory/ExtendsFactory.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.0)

Access to private property $typeResolver of parent class phpDocumentor\Reflection\DocBlock\Tags\Factory\AbstractExtendsFactory.
$this->descriptionFactory->create($description, $context)

Check failure on line 39 in src/DocBlock/Tags/Factory/ExtendsFactory.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.0)

Access to private property $descriptionFactory of parent class phpDocumentor\Reflection\DocBlock\Tags\Factory\AbstractExtendsFactory.
);
}
}
42 changes: 42 additions & 0 deletions src/DocBlock/Tags/Factory/ImplementsFactory.php
Original file line number Diff line number Diff line change
@@ -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\Tags\Implements_;
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
use PHPStan\PhpDocParser\Ast\PhpDoc\ImplementsTagValueNode;

/**
* @internal This class is not part of the BC promise of this library.
*/
final class ImplementsFactory extends AbstractImplementsFactory
{
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory)
{
parent::__construct($typeResolver, $descriptionFactory);
$this->tagName = '@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 Implements_(
$this->typeResolver->createType($tagValue->type, $context),

Check failure on line 38 in src/DocBlock/Tags/Factory/ImplementsFactory.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.0)

Access to private property $typeResolver of parent class phpDocumentor\Reflection\DocBlock\Tags\Factory\AbstractImplementsFactory.
$this->descriptionFactory->create($description, $context)

Check failure on line 39 in src/DocBlock/Tags/Factory/ImplementsFactory.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.0)

Access to private property $descriptionFactory of parent class phpDocumentor\Reflection\DocBlock\Tags\Factory\AbstractImplementsFactory.
);
}
}
42 changes: 42 additions & 0 deletions src/DocBlock/Tags/Factory/TemplateExtendsFactory.php
Original file line number Diff line number Diff line change
@@ -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),

Check failure on line 38 in src/DocBlock/Tags/Factory/TemplateExtendsFactory.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.0)

Access to private property $typeResolver of parent class phpDocumentor\Reflection\DocBlock\Tags\Factory\AbstractExtendsFactory.
$this->descriptionFactory->create($description, $context)

Check failure on line 39 in src/DocBlock/Tags/Factory/TemplateExtendsFactory.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.0)

Access to private property $descriptionFactory of parent class phpDocumentor\Reflection\DocBlock\Tags\Factory\AbstractExtendsFactory.
);
}
}
Loading

0 comments on commit bd5b5a8

Please sign in to comment.