diff --git a/config/set/cakephp-to-symfony/cakephp-24-to-symfony-50.yaml b/config/set/cakephp-to-symfony/cakephp-24-to-symfony-50.yaml index 8eca2cc679c..6eacc1a76c2 100644 --- a/config/set/cakephp-to-symfony/cakephp-24-to-symfony-50.yaml +++ b/config/set/cakephp-to-symfony/cakephp-24-to-symfony-50.yaml @@ -11,3 +11,4 @@ services: # .tpl templates to twig Rector\CakePHPToSymfony\Rector\Echo_\CakePHPTemplateLinkToTwigRector: null Rector\CakePHPToSymfony\Rector\Echo_\CakePHPTemplateTranslateToTwigRector: null + Rector\CakePHPToSymfony\Rector\Echo_\CakePHPTemplateHToTwigRector: null diff --git a/packages/CakePHPToSymfony/src/Rector/Echo_/CakePHPTemplateHToTwigRector.php b/packages/CakePHPToSymfony/src/Rector/Echo_/CakePHPTemplateHToTwigRector.php new file mode 100644 index 00000000000..207c351f0e2 --- /dev/null +++ b/packages/CakePHPToSymfony/src/Rector/Echo_/CakePHPTemplateHToTwigRector.php @@ -0,0 +1,45 @@ +', + '3>{{ value|escape }}' + ) + ]); + } + + /** + * @return string[] + */ + public function getNodeTypes(): array + { + return [\PhpParser\Node\Stmt\Echo_::class]; + } + + /** + * @param \PhpParser\Node\Stmt\Echo_ $node + */ + public function refactor(Node $node): ?Node + { + // change the node + + return $node; + } +} diff --git a/packages/CakePHPToSymfony/tests/Rector/Echo_/CakePHPTemplateHToTwigRector/CakePHPTemplateHToTwigRectorTest.php b/packages/CakePHPToSymfony/tests/Rector/Echo_/CakePHPTemplateHToTwigRector/CakePHPTemplateHToTwigRectorTest.php new file mode 100644 index 00000000000..2f731178693 --- /dev/null +++ b/packages/CakePHPToSymfony/tests/Rector/Echo_/CakePHPTemplateHToTwigRector/CakePHPTemplateHToTwigRectorTest.php @@ -0,0 +1,28 @@ +doTestFile($file); + } + + public function provideDataForTest(): \Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + protected function getRectorClass(): string + { + return \Rector\CakePHPToSymfony\Rector\Echo_\CakePHPTemplateHToTwigRector::class; + } +} diff --git a/packages/CakePHPToSymfony/tests/Rector/Echo_/CakePHPTemplateHToTwigRector/Fixture/fixture.php.inc b/packages/CakePHPToSymfony/tests/Rector/Echo_/CakePHPTemplateHToTwigRector/Fixture/fixture.php.inc new file mode 100644 index 00000000000..c48e9374387 --- /dev/null +++ b/packages/CakePHPToSymfony/tests/Rector/Echo_/CakePHPTemplateHToTwigRector/Fixture/fixture.php.inc @@ -0,0 +1,15 @@ + + +?> +----- +{{ value|escape }} + +?> diff --git a/utils/RectorGenerator/src/Command/CreateRectorCommand.php b/utils/RectorGenerator/src/Command/CreateRectorCommand.php index edc5f567602..c88307da6a8 100644 --- a/utils/RectorGenerator/src/Command/CreateRectorCommand.php +++ b/utils/RectorGenerator/src/Command/CreateRectorCommand.php @@ -96,6 +96,7 @@ final class CreateRectorCommand extends Command protected function configure(): void { $this->setName(CommandNaming::classToName(self::class)); + $this->setAliases(['c']); $this->setDescription('[Dev] Create a new Rector, in a proper location, with new tests'); } diff --git a/utils/RectorGenerator/src/Configuration/ConfigurationFactory.php b/utils/RectorGenerator/src/Configuration/ConfigurationFactory.php index fbac51f31d6..e2355167f35 100644 --- a/utils/RectorGenerator/src/Configuration/ConfigurationFactory.php +++ b/utils/RectorGenerator/src/Configuration/ConfigurationFactory.php @@ -48,8 +48,8 @@ final class ConfigurationFactory $category, $this->resolveFullyQualifiedNodeTypes($rectorRecipe['node_types']), $rectorRecipe['description'], - trim(ltrim($rectorRecipe['code_before'], 'normalizeCode($rectorRecipe['code_before']), + $this->normalizeCode($rectorRecipe['code_after']), array_filter((array) $rectorRecipe['source']), $this->resolveSetConfig($rectorRecipe['set']) ); @@ -134,4 +134,13 @@ final class ConfigurationFactory // in case of forgotten _ return Strings::endsWith($nodeClass, '\\' . $nodeType . '_'); } + + private function normalizeCode(string $code): string + { + if (Strings::startsWith($code, '