Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@

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;
Expand All @@ -27,12 +35,31 @@ public function isMatch(Node $node): bool
*/
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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/**
* @method int|bool|null|void main(...$args)
*/