mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-26 12:52:36 +00:00
[CakePHPToSymfony] Add CakePHPControllerRenderToSymfonyRector
This commit is contained in:
parent
70031e0b50
commit
37c342b654
|
@ -4,3 +4,4 @@ services:
|
|||
Rector\CakePHPToSymfony\Rector\Class_\CakePHPControllerHelperToSymfonyRector: null
|
||||
Rector\CakePHPToSymfony\Rector\Class_\CakePHPControllerComponentToSymfonyRector: null
|
||||
Rector\CakePHPToSymfony\Rector\ClassMethod\CakePHPControllerRedirectToSymfonyRector: null
|
||||
Rector\CakePHPToSymfony\Rector\ClassMethod\CakePHPControllerRenderToSymfonyRector: null
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# All 437 Rectors Overview
|
||||
# All 438 Rectors Overview
|
||||
|
||||
- [Projects](#projects)
|
||||
- [General](#general)
|
||||
|
@ -301,10 +301,6 @@ Migrate CakePHP 2.4 Controller action to Symfony 5
|
|||
+ public function index(): Response
|
||||
{
|
||||
$value = 5;
|
||||
- $this->set('name', $value);
|
||||
+ return $this->renderResponse('homepage/index.twig', [
|
||||
+ 'name' => $value
|
||||
+ ]);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -385,6 +381,25 @@ Migrate CakePHP 2.4 Controller redirect() to Symfony 5
|
|||
|
||||
<br>
|
||||
|
||||
### `CakePHPControllerRenderToSymfonyRector`
|
||||
|
||||
- class: `Rector\CakePHPToSymfony\Rector\ClassMethod\CakePHPControllerRenderToSymfonyRector`
|
||||
|
||||
Migrate CakePHP 2.4 Controller render() to Symfony 5
|
||||
|
||||
```diff
|
||||
class RedirectController extends \AppController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
- $this->render('custom_file');
|
||||
+ return $this->render('redirect/custom_file.twig');
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### `CakePHPControllerToSymfonyControllerRector`
|
||||
|
||||
- class: `Rector\CakePHPToSymfony\Rector\Class_\CakePHPControllerToSymfonyControllerRector`
|
||||
|
|
|
@ -5,19 +5,9 @@ declare(strict_types=1);
|
|||
namespace Rector\CakePHPToSymfony\Rector\ClassMethod;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\ArrayItem;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use Rector\CakePHPToSymfony\Rector\AbstractCakePHPRector;
|
||||
use Rector\CakePHPToSymfony\Rector\TemplatePathResolver;
|
||||
use Rector\CodeQuality\CompactConverter;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
||||
|
@ -32,22 +22,6 @@ use Rector\RectorDefinition\RectorDefinition;
|
|||
*/
|
||||
final class CakePHPControllerActionToSymfonyControllerActionRector extends AbstractCakePHPRector
|
||||
{
|
||||
/**
|
||||
* @var CompactConverter
|
||||
*/
|
||||
private $compactConverter;
|
||||
|
||||
/**
|
||||
* @var TemplatePathResolver
|
||||
*/
|
||||
private $templatePathResolver;
|
||||
|
||||
public function __construct(CompactConverter $compactConverter, TemplatePathResolver $templatePathResolver)
|
||||
{
|
||||
$this->compactConverter = $compactConverter;
|
||||
$this->templatePathResolver = $templatePathResolver;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('Migrate CakePHP 2.4 Controller action to Symfony 5', [
|
||||
|
@ -58,7 +32,6 @@ class HomepageController extends \AppController
|
|||
public function index()
|
||||
{
|
||||
$value = 5;
|
||||
$this->set('name', $value);
|
||||
}
|
||||
}
|
||||
PHP
|
||||
|
@ -71,9 +44,6 @@ class HomepageController extends \AppController
|
|||
public function index(): Response
|
||||
{
|
||||
$value = 5;
|
||||
return $this->renderResponse('homepage/index.twig', [
|
||||
'name' => $value
|
||||
]);
|
||||
}
|
||||
}
|
||||
PHP
|
||||
|
@ -103,88 +73,8 @@ PHP
|
|||
return null;
|
||||
}
|
||||
|
||||
$methodCall = $this->createThisRenderMethodCall($node);
|
||||
$return = new Return_($methodCall);
|
||||
$node->stmts[] = $return;
|
||||
|
||||
$node->returnType = new FullyQualified('Symfony\Component\HttpFoundation\Response');
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Arg[][]
|
||||
*/
|
||||
private function collectAndRemoveSetMethodCallArgs(array $stmts): array
|
||||
{
|
||||
$setMethodCallArgs = [];
|
||||
|
||||
$this->traverseNodesWithCallable($stmts, function (Node $node) use (&$setMethodCallArgs) {
|
||||
if (! $node instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $this->isName($node->name, 'set')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$setMethodCallArgs[] = $node->args;
|
||||
$this->removeNode($node);
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
return $setMethodCallArgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Arg[][] $setValues
|
||||
*/
|
||||
private function createArrayFromSetValues(array $setValues): Array_
|
||||
{
|
||||
$arrayItems = [];
|
||||
|
||||
foreach ($setValues as $setValue) {
|
||||
if (count($setValue) > 1) {
|
||||
$arrayItems[] = new ArrayItem($setValue[1]->value, $setValue[0]->value);
|
||||
} elseif ($this->isCompactFuncCall($setValue[0]->value)) {
|
||||
/** @var FuncCall $compactFuncCall */
|
||||
$compactFuncCall = $setValue[0]->value;
|
||||
|
||||
return $this->compactConverter->convertToArray($compactFuncCall);
|
||||
}
|
||||
}
|
||||
|
||||
return new Array_($arrayItems);
|
||||
}
|
||||
|
||||
private function isCompactFuncCall(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof FuncCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->isName($node, 'compact');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates "$this->render('...', [...])";
|
||||
*/
|
||||
private function createThisRenderMethodCall(ClassMethod $classMethod): MethodCall
|
||||
{
|
||||
$thisVariable = new Variable('this');
|
||||
$thisRenderMethodCall = new MethodCall($thisVariable, 'render');
|
||||
|
||||
$templateName = $this->templatePathResolver->resolveForClassMethod($classMethod);
|
||||
$thisRenderMethodCall->args[] = new Arg(new String_($templateName));
|
||||
|
||||
$setValues = $this->collectAndRemoveSetMethodCallArgs((array) $classMethod->stmts);
|
||||
|
||||
if ($setValues !== []) {
|
||||
$parametersArray = $this->createArrayFromSetValues($setValues);
|
||||
$thisRenderMethodCall->args[] = new Arg($parametersArray);
|
||||
}
|
||||
|
||||
return $thisRenderMethodCall;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,215 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\CakePHPToSymfony\Rector\ClassMethod;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\ArrayItem;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use Rector\CakePHPToSymfony\Rector\AbstractCakePHPRector;
|
||||
use Rector\CakePHPToSymfony\Rector\Template\TemplateMethodCallManipulator;
|
||||
use Rector\CakePHPToSymfony\Rector\TemplatePathResolver;
|
||||
use Rector\CodeQuality\CompactConverter;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
||||
/**
|
||||
* @see https://book.cakephp.org/2/en/controllers.html#rendering-a-specific-view
|
||||
* @see https://symfony.com/doc/current/controller.html#rendering-templates
|
||||
*
|
||||
* @see \Rector\CakePHPToSymfony\Tests\Rector\ClassMethod\CakePHPControllerRenderToSymfonyRector\CakePHPControllerRenderToSymfonyRectorTest
|
||||
*/
|
||||
final class CakePHPControllerRenderToSymfonyRector extends AbstractCakePHPRector
|
||||
{
|
||||
/**
|
||||
* @var TemplatePathResolver
|
||||
*/
|
||||
private $templatePathResolver;
|
||||
|
||||
/**
|
||||
* @var CompactConverter
|
||||
*/
|
||||
private $compactConverter;
|
||||
|
||||
/**
|
||||
* @var TemplateMethodCallManipulator
|
||||
*/
|
||||
private $templateMethodCallManipulator;
|
||||
|
||||
public function __construct(
|
||||
TemplatePathResolver $templatePathResolver,
|
||||
CompactConverter $compactConverter,
|
||||
TemplateMethodCallManipulator $templateMethodCallManipulator
|
||||
) {
|
||||
$this->templatePathResolver = $templatePathResolver;
|
||||
$this->compactConverter = $compactConverter;
|
||||
$this->templateMethodCallManipulator = $templateMethodCallManipulator;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('Migrate CakePHP 2.4 Controller render() to Symfony 5', [
|
||||
new CodeSample(
|
||||
<<<'PHP'
|
||||
class RedirectController extends \AppController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$this->render('custom_file');
|
||||
}
|
||||
}
|
||||
PHP
|
||||
,
|
||||
<<<'PHP'
|
||||
class RedirectController extends \AppController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return $this->render('redirect/custom_file.twig');
|
||||
}
|
||||
}
|
||||
PHP
|
||||
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [ClassMethod::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if (! $this->isInCakePHPController($node)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->hasRenderMethodCall($node)) {
|
||||
$this->templateMethodCallManipulator->refactorExistingRenderMethodCall($node);
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->completeImplicitRenderMethodCall($node);
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates "$this->render('...', [...])";
|
||||
*/
|
||||
private function createThisRenderMethodCall(ClassMethod $classMethod): MethodCall
|
||||
{
|
||||
$thisVariable = new Variable('this');
|
||||
$thisRenderMethodCall = new MethodCall($thisVariable, 'render');
|
||||
|
||||
$templateName = $this->templatePathResolver->resolveForClassMethod($classMethod);
|
||||
$thisRenderMethodCall->args[] = new Arg(new String_($templateName));
|
||||
|
||||
$setValues = $this->collectAndRemoveSetMethodCallArgs((array) $classMethod->stmts);
|
||||
|
||||
if ($setValues !== []) {
|
||||
$parametersArray = $this->createArrayFromSetValues($setValues);
|
||||
$thisRenderMethodCall->args[] = new Arg($parametersArray);
|
||||
}
|
||||
|
||||
return $thisRenderMethodCall;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Arg[][]
|
||||
*/
|
||||
private function collectAndRemoveSetMethodCallArgs(array $stmts): array
|
||||
{
|
||||
$setMethodCallArgs = [];
|
||||
|
||||
$this->traverseNodesWithCallable($stmts, function (Node $node) use (&$setMethodCallArgs) {
|
||||
if (! $node instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $this->isName($node->name, 'set')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$setMethodCallArgs[] = $node->args;
|
||||
$this->removeNode($node);
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
return $setMethodCallArgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Arg[][] $setValues
|
||||
*/
|
||||
private function createArrayFromSetValues(array $setValues): Array_
|
||||
{
|
||||
$arrayItems = [];
|
||||
|
||||
foreach ($setValues as $setValue) {
|
||||
if (count($setValue) > 1) {
|
||||
$arrayItems[] = new ArrayItem($setValue[1]->value, $setValue[0]->value);
|
||||
} elseif ($this->isCompactFuncCall($setValue[0]->value)) {
|
||||
/** @var FuncCall $compactFuncCall */
|
||||
$compactFuncCall = $setValue[0]->value;
|
||||
|
||||
return $this->compactConverter->convertToArray($compactFuncCall);
|
||||
}
|
||||
}
|
||||
|
||||
return new Array_($arrayItems);
|
||||
}
|
||||
|
||||
private function isCompactFuncCall(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof FuncCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->isName($node, 'compact');
|
||||
}
|
||||
|
||||
private function hasRenderMethodCall(ClassMethod $classMethod): bool
|
||||
{
|
||||
return (bool) $this->betterNodeFinder->findFirst($classMethod, function (Node $node) {
|
||||
return $this->isThisRenderMethodCall($node);
|
||||
});
|
||||
}
|
||||
|
||||
private function completeImplicitRenderMethodCall(ClassMethod $classMethod): void
|
||||
{
|
||||
$methodCall = $this->createThisRenderMethodCall($classMethod);
|
||||
$return = new Return_($methodCall);
|
||||
|
||||
$classMethod->stmts[] = $return;
|
||||
}
|
||||
|
||||
private function isThisRenderMethodCall(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof MethodCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->isName($node->var, 'this')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->isName($node->name, 'render');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\CakePHPToSymfony\Rector\Template;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use Rector\CakePHPToSymfony\Rector\TemplatePathResolver;
|
||||
use Rector\PhpParser\Node\Resolver\NameResolver;
|
||||
use Rector\PhpParser\Node\Value\ValueResolver;
|
||||
use Rector\PhpParser\NodeTraverser\CallableNodeTraverser;
|
||||
|
||||
final class TemplateMethodCallManipulator
|
||||
{
|
||||
/**
|
||||
* @var ValueResolver
|
||||
*/
|
||||
private $valueResolver;
|
||||
|
||||
/**
|
||||
* @var TemplatePathResolver
|
||||
*/
|
||||
private $templatePathResolver;
|
||||
|
||||
/**
|
||||
* @var CallableNodeTraverser
|
||||
*/
|
||||
private $callableNodeTraverser;
|
||||
|
||||
/**
|
||||
* @var NameResolver
|
||||
*/
|
||||
private $nameResolver;
|
||||
|
||||
public function __construct(
|
||||
ValueResolver $valueResolver,
|
||||
TemplatePathResolver $templatePathResolver,
|
||||
CallableNodeTraverser $callableNodeTraverser,
|
||||
NameResolver $nameResolver
|
||||
) {
|
||||
$this->valueResolver = $valueResolver;
|
||||
$this->templatePathResolver = $templatePathResolver;
|
||||
$this->callableNodeTraverser = $callableNodeTraverser;
|
||||
$this->nameResolver = $nameResolver;
|
||||
}
|
||||
|
||||
public function refactorExistingRenderMethodCall(ClassMethod $classMethod): void
|
||||
{
|
||||
$controllerNamePart = $this->templatePathResolver->resolveClassNameTemplatePart($classMethod);
|
||||
|
||||
$this->callableNodeTraverser->traverseNodesWithCallable($classMethod, function (Node $node) use (
|
||||
$controllerNamePart
|
||||
) {
|
||||
$renderMethodCall = $this->matchThisRenderMethodCallBareOrInReturn($node);
|
||||
if ($renderMethodCall === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->refactorRenderTemplateName($renderMethodCall, $controllerNamePart);
|
||||
});
|
||||
}
|
||||
|
||||
private function refactorRenderTemplateName(Node $node, string $controllerNamePart): ?Return_
|
||||
{
|
||||
/** @var MethodCall $node */
|
||||
$renderArgumentValue = $this->valueResolver->getValue($node->args[0]->value);
|
||||
|
||||
/** @var string|mixed $renderArgumentValue */
|
||||
if (! is_string($renderArgumentValue)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (Strings::contains($renderArgumentValue, '/')) {
|
||||
$templateName = $renderArgumentValue . '.twig';
|
||||
} else {
|
||||
// add explicit controller
|
||||
$templateName = $controllerNamePart . '/' . $renderArgumentValue . '.twig';
|
||||
}
|
||||
|
||||
$node->args[0]->value = new String_($templateName);
|
||||
|
||||
return new Return_($node);
|
||||
}
|
||||
|
||||
private function isThisRenderMethodCall(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof MethodCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->nameResolver->isName($node->var, 'this')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->nameResolver->isName($node->name, 'render');
|
||||
}
|
||||
|
||||
private function matchThisRenderMethodCallBareOrInReturn(Node $node): ?MethodCall
|
||||
{
|
||||
if ($node instanceof Return_) {
|
||||
$nodeExpr = $node->expr;
|
||||
if ($nodeExpr === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $this->isThisRenderMethodCall($nodeExpr)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var MethodCall $nodeExpr */
|
||||
return $nodeExpr;
|
||||
}
|
||||
|
||||
if ($node instanceof Expression) {
|
||||
if (! $this->isThisRenderMethodCall($node->expr)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $node->expr;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -60,6 +60,7 @@ final class TemplatePathResolver
|
|||
{
|
||||
$viewPropertyValue = $this->resolveViewPropertyValue($classMethod);
|
||||
if ($viewPropertyValue !== null) {
|
||||
$viewPropertyValue = Strings::lower($viewPropertyValue);
|
||||
return $viewPropertyValue . '.twig';
|
||||
}
|
||||
|
||||
|
@ -68,6 +69,17 @@ final class TemplatePathResolver
|
|||
return $classAndMethodValue . '.twig';
|
||||
}
|
||||
|
||||
public function resolveClassNameTemplatePart(ClassMethod $classMethod): string
|
||||
{
|
||||
/** @var string $className */
|
||||
$className = $classMethod->getAttribute(AttributeKey::CLASS_NAME);
|
||||
$shortClassName = $this->classNaming->getShortName($className);
|
||||
|
||||
$shortClassName = Strings::replace($shortClassName, '#Controller$#i');
|
||||
|
||||
return Strings::lower($shortClassName);
|
||||
}
|
||||
|
||||
private function resolveViewPropertyValue(ClassMethod $classMethod): ?string
|
||||
{
|
||||
$setViewProperty = null;
|
||||
|
@ -91,9 +103,10 @@ final class TemplatePathResolver
|
|||
if ($setViewProperty === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$setViewValue = $this->valueResolver->getValue($setViewProperty);
|
||||
if (is_string($setViewValue)) {
|
||||
return $setViewValue;
|
||||
return Strings::lower($setViewValue);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -101,13 +114,7 @@ final class TemplatePathResolver
|
|||
|
||||
private function resolveFromClassAndMethod(ClassMethod $classMethod): string
|
||||
{
|
||||
/** @var string $className */
|
||||
$className = $classMethod->getAttribute(AttributeKey::CLASS_NAME);
|
||||
$shortClassName = $this->classNaming->getShortName($className);
|
||||
|
||||
$shortClassName = Strings::replace($shortClassName, '#Controller$#i');
|
||||
$shortClassName = Strings::lower($shortClassName);
|
||||
|
||||
$shortClassName = $this->resolveClassNameTemplatePart($classMethod);
|
||||
$methodName = $classMethod->getAttribute(AttributeKey::METHOD_NAME);
|
||||
|
||||
return $shortClassName . '/' . $methodName;
|
||||
|
|
|
@ -7,7 +7,6 @@ class HomepageController extends \AppController
|
|||
public function index()
|
||||
{
|
||||
$value = 5;
|
||||
$this->set('name', $value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,7 +21,6 @@ class HomepageController extends \AppController
|
|||
public function index(): \Symfony\Component\HttpFoundation\Response
|
||||
{
|
||||
$value = 5;
|
||||
return $this->render('homepage/index.twig', ['name' => $value]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\CakePHPToSymfony\Tests\Rector\ClassMethod\CakePHPControllerRenderToSymfonyRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\CakePHPToSymfony\Rector\ClassMethod\CakePHPControllerRenderToSymfonyRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
|
||||
final class CakePHPControllerRenderToSymfonyRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideDataForTest()
|
||||
*/
|
||||
public function test(string $file): void
|
||||
{
|
||||
$this->doTestFile($file);
|
||||
}
|
||||
|
||||
public function provideDataForTest(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return CakePHPControllerRenderToSymfonyRector::class;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\CakePHPToSymfony\Tests\Rector\ClassMethod\CakePHPControllerActionToSymfonyControllerActionRector\Fixture;
|
||||
namespace Rector\CakePHPToSymfony\Tests\Rector\ClassMethod\CakePHPControllerRenderToSymfonyRector\Fixture;
|
||||
|
||||
class ChangedViewPropertyController extends \AppController
|
||||
{
|
||||
|
@ -14,13 +14,13 @@ class ChangedViewPropertyController extends \AppController
|
|||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\CakePHPToSymfony\Tests\Rector\ClassMethod\CakePHPControllerActionToSymfonyControllerActionRector\Fixture;
|
||||
namespace Rector\CakePHPToSymfony\Tests\Rector\ClassMethod\CakePHPControllerRenderToSymfonyRector\Fixture;
|
||||
|
||||
class ChangedViewPropertyController extends \AppController
|
||||
{
|
||||
public function index(): \Symfony\Component\HttpFoundation\Response
|
||||
public function index()
|
||||
{
|
||||
return $this->render('Controller/this_value.twig');
|
||||
return $this->render('controller/this_value.twig');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\CakePHPToSymfony\Tests\Rector\ClassMethod\CakePHPControllerActionToSymfonyControllerActionRector\Fixture;
|
||||
namespace Rector\CakePHPToSymfony\Tests\Rector\ClassMethod\CakePHPControllerRenderToSymfonyRector\Fixture;
|
||||
|
||||
class CompactTooController extends \AppController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$value = 5;
|
||||
$this->set(compact('clientId', 'states', 'invoiceTemplates'));
|
||||
}
|
||||
}
|
||||
|
@ -15,13 +14,12 @@ class CompactTooController extends \AppController
|
|||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\CakePHPToSymfony\Tests\Rector\ClassMethod\CakePHPControllerActionToSymfonyControllerActionRector\Fixture;
|
||||
namespace Rector\CakePHPToSymfony\Tests\Rector\ClassMethod\CakePHPControllerRenderToSymfonyRector\Fixture;
|
||||
|
||||
class CompactTooController extends \AppController
|
||||
{
|
||||
public function index(): \Symfony\Component\HttpFoundation\Response
|
||||
public function index()
|
||||
{
|
||||
$value = 5;
|
||||
return $this->render('compacttoo/index.twig', ['clientId' => $clientId, 'states' => $states, 'invoiceTemplates' => $invoiceTemplates]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\CakePHPToSymfony\Tests\Rector\ClassMethod\CakePHPControllerRenderToSymfonyRector\Fixture;
|
||||
|
||||
class RedirectController extends \AppController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$this->render('custom_file');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\CakePHPToSymfony\Tests\Rector\ClassMethod\CakePHPControllerRenderToSymfonyRector\Fixture;
|
||||
|
||||
class RedirectController extends \AppController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return $this->render('redirect/custom_file.twig');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\CakePHPToSymfony\Tests\Rector\ClassMethod\CakePHPControllerRenderToSymfonyRector\Fixture;
|
||||
|
||||
class SetController extends \AppController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$this->set('name', 5);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\CakePHPToSymfony\Tests\Rector\ClassMethod\CakePHPControllerRenderToSymfonyRector\Fixture;
|
||||
|
||||
class SetController extends \AppController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return $this->render('homepage/index.twig', ['name' => 5]);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -222,3 +222,4 @@ parameters:
|
|||
- '#Cannot cast \(array<string\>\)\|string\|true to string#'
|
||||
|
||||
- '#In method "Rector\\BetterPhpDocParser\\AnnotationReader\\NodeAnnotationReader\:\:createPropertyReflectionFromPropertyNode", caught "Throwable" must be rethrown\. Either catch a more specific exception or add a "throw" clause in the "catch" block to propagate the exception\. More info\: http\://bit\.ly/failloud#'
|
||||
- '#Method Rector\\CakePHPToSymfony\\Rector\\Template\\TemplateMethodCallManipulator\:\:matchThisRenderMethodCallBareOrInReturn\(\) should return PhpParser\\Node\\Expr\\MethodCall\|null but returns PhpParser\\Node\\Expr#'
|
||||
|
|
Loading…
Reference in New Issue
Block a user