mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 11:44:14 +01:00
Merge pull request #2934 from rectorphp/fix-union-method
fix @method union return type annotation
This commit is contained in:
commit
e36bc44a2c
@ -6,12 +6,20 @@ namespace Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactory\PhpDoc;
|
||||
|
||||
use PHPStan\PhpDocParser\Ast\Node;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\MethodTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
|
||||
use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareMethodTagValueNode;
|
||||
use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeAwareNodeFactoryAwareInterface;
|
||||
use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface;
|
||||
use Rector\BetterPhpDocParser\Attributes\Ast\AttributeAwareNodeFactory;
|
||||
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
|
||||
|
||||
final class AttributeAwareMethodTagValueNodeFactory implements AttributeNodeAwareFactoryInterface
|
||||
final class AttributeAwareMethodTagValueNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface
|
||||
{
|
||||
/**
|
||||
* @var AttributeAwareNodeFactory
|
||||
*/
|
||||
private $attributeAwareNodeFactory;
|
||||
|
||||
public function getOriginalNodeClass(): string
|
||||
{
|
||||
return MethodTagValueNode::class;
|
||||
@ -27,12 +35,31 @@ final class AttributeAwareMethodTagValueNodeFactory implements AttributeNodeAwar
|
||||
*/
|
||||
public function create(Node $node): AttributeAwareNodeInterface
|
||||
{
|
||||
$returnType = $this->createAttributeAwareReturnType($node);
|
||||
|
||||
return new AttributeAwareMethodTagValueNode(
|
||||
$node->isStatic,
|
||||
$node->returnType,
|
||||
$returnType,
|
||||
$node->methodName,
|
||||
$node->parameters,
|
||||
$node->description
|
||||
);
|
||||
}
|
||||
|
||||
public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void
|
||||
{
|
||||
$this->attributeAwareNodeFactory = $attributeAwareNodeFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TypeNode&AttributeAwareNodeInterface
|
||||
*/
|
||||
private function createAttributeAwareReturnType(MethodTagValueNode $methodTagValueNode)
|
||||
{
|
||||
if ($methodTagValueNode->returnType !== null) {
|
||||
return $this->attributeAwareNodeFactory->createFromNode($methodTagValueNode->returnType);
|
||||
}
|
||||
|
||||
return $methodTagValueNode->returnType;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,3 @@
|
||||
/**
|
||||
* @method int|bool|null|void main(...$args)
|
||||
*/
|
Loading…
x
Reference in New Issue
Block a user