2021-04-06 17:33:09 +00:00
|
|
|
<?php
|
|
|
|
|
2021-05-09 20:15:43 +00:00
|
|
|
declare (strict_types=1);
|
2022-06-06 17:12:56 +00:00
|
|
|
namespace Rector\BetterPhpDocParser\PhpDocNodeVisitor;
|
2021-04-06 17:33:09 +00:00
|
|
|
|
2022-06-06 17:12:56 +00:00
|
|
|
use PHPStan\PhpDocParser\Ast\Node;
|
|
|
|
use PHPStan\PhpDocParser\Ast\Type\CallableTypeNode;
|
|
|
|
use Rector\BetterPhpDocParser\Attributes\AttributeMirrorer;
|
|
|
|
use Rector\BetterPhpDocParser\Contract\BasePhpDocNodeVisitorInterface;
|
|
|
|
use Rector\BetterPhpDocParser\ValueObject\Type\SpacingAwareCallableTypeNode;
|
2022-08-29 20:49:28 +00:00
|
|
|
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeVisitor\AbstractPhpDocNodeVisitor;
|
2022-06-07 08:22:29 +00:00
|
|
|
final class CallableTypePhpDocNodeVisitor extends AbstractPhpDocNodeVisitor implements BasePhpDocNodeVisitorInterface
|
2021-04-06 17:33:09 +00:00
|
|
|
{
|
|
|
|
/**
|
2023-06-11 23:01:39 +00:00
|
|
|
* @readonly
|
2021-05-10 23:39:21 +00:00
|
|
|
* @var \Rector\BetterPhpDocParser\Attributes\AttributeMirrorer
|
2021-04-06 17:33:09 +00:00
|
|
|
*/
|
|
|
|
private $attributeMirrorer;
|
2022-06-07 08:22:29 +00:00
|
|
|
public function __construct(AttributeMirrorer $attributeMirrorer)
|
2021-04-06 17:33:09 +00:00
|
|
|
{
|
|
|
|
$this->attributeMirrorer = $attributeMirrorer;
|
|
|
|
}
|
2022-06-07 08:22:29 +00:00
|
|
|
public function enterNode(Node $node) : ?Node
|
2021-04-06 17:33:09 +00:00
|
|
|
{
|
2022-06-07 08:22:29 +00:00
|
|
|
if (!$node instanceof CallableTypeNode) {
|
2021-04-06 17:33:09 +00:00
|
|
|
return null;
|
|
|
|
}
|
2022-06-07 08:22:29 +00:00
|
|
|
if ($node instanceof SpacingAwareCallableTypeNode) {
|
2021-04-06 17:33:09 +00:00
|
|
|
return null;
|
|
|
|
}
|
2022-06-07 08:22:29 +00:00
|
|
|
$spacingAwareCallableTypeNode = new SpacingAwareCallableTypeNode($node->identifier, $node->parameters, $node->returnType);
|
2021-04-06 17:33:09 +00:00
|
|
|
$this->attributeMirrorer->mirror($node, $spacingAwareCallableTypeNode);
|
|
|
|
return $spacingAwareCallableTypeNode;
|
|
|
|
}
|
|
|
|
}
|