fix method union annotation

This commit is contained in:
TomasVotruba 2020-02-25 21:38:33 +01:00
parent c50ef79cfb
commit 6fce4dcd37
2 changed files with 32 additions and 2 deletions

View File

@ -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;
}
}

View File

@ -0,0 +1,3 @@
/**
* @method int|bool|null|void main(...$args)
*/