mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 11:44:14 +01:00
add test case for as/of template tag
This commit is contained in:
parent
abb11dcdcf
commit
4132d9d885
@ -4,11 +4,36 @@ declare(strict_types=1);
|
||||
|
||||
namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
|
||||
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
|
||||
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
|
||||
|
||||
final class AttributeAwareTemplateTagValueNode extends TemplateTagValueNode implements AttributeAwareNodeInterface
|
||||
{
|
||||
use AttributeTrait;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $preposition;
|
||||
|
||||
public function __construct(string $name, ?TypeNode $bound, string $description, string $originalContent)
|
||||
{
|
||||
parent::__construct($name, $bound, $description);
|
||||
|
||||
$matches = Strings::match($originalContent, '#\s+(?<preposition>as|of)\s+#');
|
||||
$this->preposition = $matches['preposition'] ?? 'of';
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
// @see https://github.com/rectorphp/rector/issues/3438
|
||||
# 'as'/'of'
|
||||
$bound = $this->bound !== null ? ' ' . $this->preposition . ' ' . $this->bound : '';
|
||||
|
||||
$content = $this->name . $bound . ' ' . $this->description;
|
||||
return trim($content);
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,6 @@ final class AttributeAwareTemplateTagValueNodeFactory implements AttributeNodeAw
|
||||
*/
|
||||
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
|
||||
{
|
||||
return new AttributeAwareTemplateTagValueNode($node->name, $node->bound, $node->description);
|
||||
return new AttributeAwareTemplateTagValueNode($node->name, $node->bound, $node->description, $docContent);
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Class_\EntityTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Class_\TableTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\ColumnTagValueNode;
|
||||
@ -48,5 +49,6 @@ final class TagValueToPhpParserNodeMap
|
||||
|
||||
SensioTemplateTagValueNode::class => Class_::class,
|
||||
SensioMethodTagValueNode::class => ClassMethod::class,
|
||||
TemplateTagValueNode::class => Class_::class,
|
||||
];
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint\Fixture\Native\Template;
|
||||
|
||||
/** @template T as int */
|
||||
final class TemplateTagAsOf
|
||||
{
|
||||
|
||||
}
|
@ -6,6 +6,7 @@ namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\TagValueNodeReprint;
|
||||
|
||||
use Iterator;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Class_\EntityTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Class_\TableTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_\ColumnTagValueNode;
|
||||
@ -65,6 +66,8 @@ final class TagValueNodeReprintTest extends AbstractPhpDocInfoTest
|
||||
|
||||
SensioTemplateTagValueNode::class => __DIR__ . '/Fixture/SensioTemplate',
|
||||
SensioMethodTagValueNode::class => __DIR__ . '/Fixture/SensioMethod',
|
||||
|
||||
TemplateTagValueNode::class => __DIR__ . '/Fixture/Native/Template',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user