Merge pull request #2934 from rectorphp/fix-union-method

fix @method union return type annotation
This commit is contained in:
Tomas Votruba 2020-02-25 22:04:10 +01:00 committed by GitHub
commit e36bc44a2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)
*/