Merge pull request #1044 from rectorphp/route-list-wrapper

Fix param wrapper conversion in RouterListToControllerAnnotationsRector
This commit is contained in:
Tomáš Votruba 2019-02-11 08:43:46 -08:00 committed by GitHub
commit 2ea051674d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 65 additions and 1 deletions

View File

@ -89,6 +89,8 @@ final class RouteInfoFactory
return null;
}
$routePath = $this->normalizeArgumentWrappers($routePath);
$targetNode = $expr->args[1]->value;
if ($targetNode instanceof ClassConstFetch) {
/** @var ClassConstFetch $controllerMethodNode */
@ -154,4 +156,9 @@ final class RouteInfoFactory
return null;
}
private function normalizeArgumentWrappers(string $routePath): string
{
return str_replace(['<', '>'], ['{', '}'], $routePath);
}
}

View File

@ -0,0 +1,56 @@
<?php
namespace Rector\NetteToSymfony\Tests\Rector\MethodCall\RouterListToControllerAnnotationsRetor\Fixture;
use Rector\NetteToSymfony\Tests\Rector\ClassMethod\RouterListToControllerAnnotationsRetor\Source\Route;
use Rector\NetteToSymfony\Tests\Rector\ClassMethod\RouterListToControllerAnnotationsRetor\Source\RouteList;
final class WithParameterRouterFactory
{
public function create(): RouteList
{
$routeList = new RouteList();
$routeList[] = new Route('some-path/<id>', WithParameterSomePresenter::class);
return $routeList;
}
}
final class WithParameterSomePresenter
{
public function run()
{
}
}
?>
-----
<?php
namespace Rector\NetteToSymfony\Tests\Rector\MethodCall\RouterListToControllerAnnotationsRetor\Fixture;
use Rector\NetteToSymfony\Tests\Rector\ClassMethod\RouterListToControllerAnnotationsRetor\Source\Route;
use Rector\NetteToSymfony\Tests\Rector\ClassMethod\RouterListToControllerAnnotationsRetor\Source\RouteList;
final class WithParameterRouterFactory
{
public function create(): RouteList
{
$routeList = new RouteList();
return $routeList;
}
}
final class WithParameterSomePresenter
{
/**
* @\Symfony\Component\Routing\Annotation\Route(path="some-path/{id}")
*/
public function run()
{
}
}
?>

View File

@ -7,7 +7,7 @@ use Rector\NetteToSymfony\Tests\Rector\ClassMethod\RouterListToControllerAnnotat
use Rector\NetteToSymfony\Tests\Rector\ClassMethod\RouterListToControllerAnnotationsRetor\Source\RouteList;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
final class RouterListToControllerAnnotationsRetorTest extends AbstractRectorTestCase
final class RouterListToControllerAnnotationsRectorTest extends AbstractRectorTestCase
{
public function test(): void
{
@ -17,6 +17,7 @@ final class RouterListToControllerAnnotationsRetorTest extends AbstractRectorTes
__DIR__ . '/Fixture/constant_reference_route_to_annotation.php.inc',
__DIR__ . '/Fixture/method_named_routes.php.inc',
__DIR__ . '/Fixture/general_method_named_routes.php.inc',
__DIR__ . '/Fixture/with_parameter.php.inc',
]);
}