mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-15 15:42:22 +00:00
Add @mixin support from PHPStan
This commit is contained in:
parent
6e9592e152
commit
da09614b2e
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;
|
||||
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\MixinTagValueNode;
|
||||
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
|
||||
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
|
||||
|
||||
final class AttributeAwareMixinTagValueNode extends MixinTagValueNode implements AttributeAwareNodeInterface
|
||||
{
|
||||
use AttributeTrait;
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\AttributeAwarePhpDoc\Ast\Type;
|
||||
|
||||
use PHPStan\PhpDocParser\Ast\Type\ConstTypeNode;
|
||||
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
|
||||
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
|
||||
|
||||
final class AttributeAwareConstTypeNode extends ConstTypeNode implements AttributeAwareNodeInterface
|
||||
{
|
||||
use AttributeTrait;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\PhpDoc;
|
||||
|
||||
use PHPStan\PhpDocParser\Ast\Node;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\MixinTagValueNode;
|
||||
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareMixinTagValueNode;
|
||||
use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
|
||||
|
||||
final class AttributeAwareMixinTagValueNodeFactory implements AttributeNodeAwareFactoryInterface
|
||||
{
|
||||
public function getOriginalNodeClass(): string
|
||||
{
|
||||
return MixinTagValueNode::class;
|
||||
}
|
||||
|
||||
public function isMatch(Node $node): bool
|
||||
{
|
||||
return is_a($node, MixinTagValueNode::class, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MixinTagValueNode $node
|
||||
*/
|
||||
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
|
||||
{
|
||||
return new AttributeAwareMixinTagValueNode($node->type, $node->description);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\Type;
|
||||
|
||||
use PHPStan\PhpDocParser\Ast\Node;
|
||||
use PHPStan\PhpDocParser\Ast\Type\ConstTypeNode;
|
||||
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareConstTypeNode;
|
||||
use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
|
||||
|
||||
final class AttributeAwareConstTypeNodeFactory implements AttributeNodeAwareFactoryInterface
|
||||
{
|
||||
public function getOriginalNodeClass(): string
|
||||
{
|
||||
return ConstTypeNode::class;
|
||||
}
|
||||
|
||||
public function isMatch(Node $node): bool
|
||||
{
|
||||
return is_a($node, ConstTypeNode::class, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConstTypeNode $node
|
||||
*/
|
||||
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
|
||||
{
|
||||
return new AttributeAwareConstTypeNode($node->constExpr);
|
||||
}
|
||||
}
|
|
@ -124,11 +124,13 @@ final class AttributeAwareClassFactoryFactory
|
|||
|
||||
$paramBuilder = new Param('docContent');
|
||||
$paramBuilder->setType('string');
|
||||
|
||||
$docContentParam = $paramBuilder->getNode();
|
||||
|
||||
$createClassMethod->addParam($nodeParam);
|
||||
$createClassMethod->addParam($docContentParam);
|
||||
$createClassMethod->makePublic();
|
||||
|
||||
$createClassMethod->setReturnType(new FullyQualified(AttributeAwareNodeInterface::class));
|
||||
|
||||
// add @param doc with more precise type
|
||||
|
|
Loading…
Reference in New Issue
Block a user