mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 01:57:13 +00:00
Add property support
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
|
||||
|
||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Property;
|
||||
use phpDocumentor\Reflection\Types\Context;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
use function trim;
|
||||
|
||||
/**
|
||||
* @internal This class is not part of the BC promise of this library.
|
||||
*/
|
||||
final class PropertyFactory implements PHPStanFactory
|
||||
{
|
||||
private TypeFactory $typeFactory;
|
||||
private DescriptionFactory $descriptionFactory;
|
||||
|
||||
public function __construct(TypeFactory $typeFactory, DescriptionFactory $descriptionFactory)
|
||||
{
|
||||
$this->typeFactory = $typeFactory;
|
||||
$this->descriptionFactory = $descriptionFactory;
|
||||
}
|
||||
|
||||
public function create(PhpDocTagNode $node, ?Context $context): Tag
|
||||
{
|
||||
$tagValue = $node->value;
|
||||
Assert::isInstanceOf($tagValue, PropertyTagValueNode::class);
|
||||
|
||||
return new Property(
|
||||
trim($tagValue->propertyName, '$'),
|
||||
$this->typeFactory->createType($tagValue->type, $context),
|
||||
$this->descriptionFactory->create($tagValue->description, $context)
|
||||
);
|
||||
}
|
||||
|
||||
public function supports(PhpDocTagNode $node, ?Context $context): bool
|
||||
{
|
||||
return $node->value instanceof PropertyTagValueNode && $node->name === '@property';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
|
||||
|
||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\PropertyRead;
|
||||
use phpDocumentor\Reflection\Types\Context;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
use function trim;
|
||||
|
||||
/**
|
||||
* @internal This class is not part of the BC promise of this library.
|
||||
*/
|
||||
final class PropertyReadFactory implements PHPStanFactory
|
||||
{
|
||||
private TypeFactory $typeFactory;
|
||||
private DescriptionFactory $descriptionFactory;
|
||||
|
||||
public function __construct(TypeFactory $typeFactory, DescriptionFactory $descriptionFactory)
|
||||
{
|
||||
$this->typeFactory = $typeFactory;
|
||||
$this->descriptionFactory = $descriptionFactory;
|
||||
}
|
||||
|
||||
public function create(PhpDocTagNode $node, ?Context $context): Tag
|
||||
{
|
||||
$tagValue = $node->value;
|
||||
Assert::isInstanceOf($tagValue, PropertyTagValueNode::class);
|
||||
|
||||
return new PropertyRead(
|
||||
trim($tagValue->propertyName, '$'),
|
||||
$this->typeFactory->createType($tagValue->type, $context),
|
||||
$this->descriptionFactory->create($tagValue->description, $context)
|
||||
);
|
||||
}
|
||||
|
||||
public function supports(PhpDocTagNode $node, ?Context $context): bool
|
||||
{
|
||||
return $node->value instanceof PropertyTagValueNode && $node->name === '@property-read';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
|
||||
|
||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\PropertyWrite;
|
||||
use phpDocumentor\Reflection\Types\Context;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
use function trim;
|
||||
|
||||
/**
|
||||
* @internal This class is not part of the BC promise of this library.
|
||||
*/
|
||||
final class PropertyWriteFactory implements PHPStanFactory
|
||||
{
|
||||
private TypeFactory $typeFactory;
|
||||
private DescriptionFactory $descriptionFactory;
|
||||
|
||||
public function __construct(TypeFactory $typeFactory, DescriptionFactory $descriptionFactory)
|
||||
{
|
||||
$this->typeFactory = $typeFactory;
|
||||
$this->descriptionFactory = $descriptionFactory;
|
||||
}
|
||||
|
||||
public function create(PhpDocTagNode $node, ?Context $context): Tag
|
||||
{
|
||||
$tagValue = $node->value;
|
||||
Assert::isInstanceOf($tagValue, PropertyTagValueNode::class);
|
||||
|
||||
return new PropertyWrite(
|
||||
trim($tagValue->propertyName, '$'),
|
||||
$this->typeFactory->createType($tagValue->type, $context),
|
||||
$this->descriptionFactory->create($tagValue->description, $context)
|
||||
);
|
||||
}
|
||||
|
||||
public function supports(PhpDocTagNode $node, ?Context $context): bool
|
||||
{
|
||||
return $node->value instanceof PropertyTagValueNode && $node->name === '@property-write';
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,9 @@ use phpDocumentor\Reflection\DocBlock\TagFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\AbstractPHPStanFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\Factory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyReadFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyWriteFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ReturnFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\TypeFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\VarFactory;
|
||||
@@ -73,6 +76,9 @@ final class DocBlockFactory implements DocBlockFactoryInterface
|
||||
new ParamFactory($typeFactory, $descriptionFactory),
|
||||
new VarFactory($typeFactory, $descriptionFactory),
|
||||
new ReturnFactory($typeFactory, $descriptionFactory),
|
||||
new PropertyFactory($typeFactory, $descriptionFactory),
|
||||
new PropertyReadFactory($typeFactory, $descriptionFactory),
|
||||
new PropertyWriteFactory($typeFactory, $descriptionFactory),
|
||||
);
|
||||
|
||||
$tagFactory->addService($descriptionFactory);
|
||||
@@ -80,6 +86,9 @@ final class DocBlockFactory implements DocBlockFactoryInterface
|
||||
$tagFactory->registerTagHandler('param', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('var', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('return', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('property', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('property-read', $phpstanTagFactory);
|
||||
$tagFactory->registerTagHandler('property-write', $phpstanTagFactory);
|
||||
|
||||
$docBlockFactory = new self($descriptionFactory, $tagFactory);
|
||||
foreach ($additionalTags as $tagName => $tagHandler) {
|
||||
|
||||
Reference in New Issue
Block a user