mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-08 04:10:51 +00:00
907c0dcefa
2d9fc68b65
Bump Rector deps (#38)
32 lines
1.3 KiB
PHP
32 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\NetteToSymfony\Routing;
|
|
|
|
use PhpParser\Node\Stmt\ClassMethod;
|
|
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
|
|
use Rector\BetterPhpDocParser\PhpDoc\SpacelessPhpDocTagNode;
|
|
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
|
final class ExplicitRouteAnnotationDecorator
|
|
{
|
|
/**
|
|
* @var string
|
|
*/
|
|
public const HAS_ROUTE_ANNOTATION = 'has_route_annotation';
|
|
/**
|
|
* @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory
|
|
*/
|
|
private $phpDocInfoFactory;
|
|
public function __construct(\Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory $phpDocInfoFactory)
|
|
{
|
|
$this->phpDocInfoFactory = $phpDocInfoFactory;
|
|
}
|
|
public function decorateClassMethodWithRouteAnnotation(\PhpParser\Node\Stmt\ClassMethod $classMethod, \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode) : void
|
|
{
|
|
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod);
|
|
$spacelessPhpDocTagNode = new \Rector\BetterPhpDocParser\PhpDoc\SpacelessPhpDocTagNode('@\\Symfony\\Component\\Routing\\Annotation\\Route', $doctrineAnnotationTagValueNode);
|
|
$phpDocInfo->addPhpDocTagNode($spacelessPhpDocTagNode);
|
|
$classMethod->setAttribute(self::HAS_ROUTE_ANNOTATION, \true);
|
|
}
|
|
}
|