From 468e73b99c49ac3be500b7654ef43cb1b695a855 Mon Sep 17 00:00:00 2001 From: Philipp Kitzberger Date: Tue, 6 Jun 2023 15:18:05 +0200 Subject: [PATCH 1/8] [FEATURE] Provide rule to migrate v:format.json.encode --- config/replace-vhs.php | 11 +++++ .../ReplaceFormatJsonEncodeFluidRector.php | 48 +++++++++++++++++++ src/Set/Extension/VhsSetList.php | 13 +++++ 3 files changed, 72 insertions(+) create mode 100644 config/replace-vhs.php create mode 100644 src/FileProcessor/Fluid/Rector/vhs/ReplaceFormatJsonEncodeFluidRector.php create mode 100644 src/Set/Extension/VhsSetList.php diff --git a/config/replace-vhs.php b/config/replace-vhs.php new file mode 100644 index 000000000..16d0b923b --- /dev/null +++ b/config/replace-vhs.php @@ -0,0 +1,11 @@ +import(__DIR__ . '/config.php'); + $rectorConfig->rule(ReplaceFormatJsonEncodeFluidRector::class); +}; diff --git a/src/FileProcessor/Fluid/Rector/vhs/ReplaceFormatJsonEncodeFluidRector.php b/src/FileProcessor/Fluid/Rector/vhs/ReplaceFormatJsonEncodeFluidRector.php new file mode 100644 index 000000000..da7931b5a --- /dev/null +++ b/src/FileProcessor/Fluid/Rector/vhs/ReplaceFormatJsonEncodeFluidRector.php @@ -0,0 +1,48 @@ +getFileContent(); + + $content = Strings::replace($content, self::PATTERN, self::REPLACEMENT); + + $file->changeFileContent($content); + } + + public function getRuleDefinition(): RuleDefinition + { + return new RuleDefinition('Use instead of ', [ + new CodeSample( + <<<'CODE_SAMPLE' +{someArray -> v:format.json.encode()} +CODE_SAMPLE + , + <<<'CODE_SAMPLE' +{someArray -> f:format.json()} +CODE_SAMPLE + ), + ]); + } +} diff --git a/src/Set/Extension/VhsSetList.php b/src/Set/Extension/VhsSetList.php new file mode 100644 index 000000000..2710af35d --- /dev/null +++ b/src/Set/Extension/VhsSetList.php @@ -0,0 +1,13 @@ + Date: Tue, 6 Jun 2023 15:34:25 +0200 Subject: [PATCH 2/8] [FEATURE] Provide rule to migrate v:l --- config/replace-vhs.php | 2 + .../Fluid/Rector/vhs/ReplaceLFluidRector.php | 52 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/FileProcessor/Fluid/Rector/vhs/ReplaceLFluidRector.php diff --git a/config/replace-vhs.php b/config/replace-vhs.php index 16d0b923b..bc54c60b6 100644 --- a/config/replace-vhs.php +++ b/config/replace-vhs.php @@ -4,8 +4,10 @@ use Rector\Config\RectorConfig; use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceFormatJsonEncodeFluidRector; +use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceLFluidRector; return static function (RectorConfig $rectorConfig): void { $rectorConfig->import(__DIR__ . '/config.php'); $rectorConfig->rule(ReplaceFormatJsonEncodeFluidRector::class); + $rectorConfig->rule(ReplaceLFluidRector::class); }; diff --git a/src/FileProcessor/Fluid/Rector/vhs/ReplaceLFluidRector.php b/src/FileProcessor/Fluid/Rector/vhs/ReplaceLFluidRector.php new file mode 100644 index 000000000..6d65ed03a --- /dev/null +++ b/src/FileProcessor/Fluid/Rector/vhs/ReplaceLFluidRector.php @@ -0,0 +1,52 @@ +getFileContent(); + + $content = Strings::replace($content, self::PATTERN, self::REPLACEMENT); + + $file->changeFileContent($content); + } + + public function getRuleDefinition(): RuleDefinition + { + return new RuleDefinition('Use instead of ', [ + new CodeSample( + <<<'CODE_SAMPLE' + + + +CODE_SAMPLE + , + <<<'CODE_SAMPLE' + + + +CODE_SAMPLE + ), + ]); + } +} From 3173f8b4481f6c84db93a3256a6cd6616c05b06b Mon Sep 17 00:00:00 2001 From: Philipp Kitzberger Date: Tue, 6 Jun 2023 15:46:37 +0200 Subject: [PATCH 3/8] [FEATURE] Provide rule to migrate v:variable.set --- config/replace-vhs.php | 2 + .../vhs/ReplaceVariableSetFluidRector.php | 50 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 src/FileProcessor/Fluid/Rector/vhs/ReplaceVariableSetFluidRector.php diff --git a/config/replace-vhs.php b/config/replace-vhs.php index bc54c60b6..053b566fb 100644 --- a/config/replace-vhs.php +++ b/config/replace-vhs.php @@ -5,9 +5,11 @@ use Rector\Config\RectorConfig; use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceFormatJsonEncodeFluidRector; use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceLFluidRector; +use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceVariableSetFluidRector; return static function (RectorConfig $rectorConfig): void { $rectorConfig->import(__DIR__ . '/config.php'); $rectorConfig->rule(ReplaceFormatJsonEncodeFluidRector::class); $rectorConfig->rule(ReplaceLFluidRector::class); + $rectorConfig->rule(ReplaceVariableSetFluidRector::class); }; diff --git a/src/FileProcessor/Fluid/Rector/vhs/ReplaceVariableSetFluidRector.php b/src/FileProcessor/Fluid/Rector/vhs/ReplaceVariableSetFluidRector.php new file mode 100644 index 000000000..9be4ee009 --- /dev/null +++ b/src/FileProcessor/Fluid/Rector/vhs/ReplaceVariableSetFluidRector.php @@ -0,0 +1,50 @@ +getFileContent(); + + $content = Strings::replace($content, self::PATTERN, self::REPLACEMENT); + + $file->changeFileContent($content); + } + + public function getRuleDefinition(): RuleDefinition + { + return new RuleDefinition('Use instead of ', [ + new CodeSample( + <<<'CODE_SAMPLE' + +{myvariable -> v:variable.set(name:'othervariable')} +CODE_SAMPLE + , + <<<'CODE_SAMPLE' + +{myvariable -> f:variable(name:'othervariable')} +CODE_SAMPLE + ), + ]); + } +} From 85bfe3d6e6d9d88d03ae8920c591e954301e37a2 Mon Sep 17 00:00:00 2001 From: Philipp Kitzberger Date: Tue, 6 Jun 2023 16:53:17 +0200 Subject: [PATCH 4/8] [FEATURE] Provide rules to migrate v:uri.image and v:media.image --- config/replace-vhs.php | 4 ++ .../vhs/ReplaceMediaImageFluidRector.php | 51 +++++++++++++++++ .../Rector/vhs/ReplaceUriImageFluidRector.php | 57 +++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 src/FileProcessor/Fluid/Rector/vhs/ReplaceMediaImageFluidRector.php create mode 100644 src/FileProcessor/Fluid/Rector/vhs/ReplaceUriImageFluidRector.php diff --git a/config/replace-vhs.php b/config/replace-vhs.php index 053b566fb..5c46cb655 100644 --- a/config/replace-vhs.php +++ b/config/replace-vhs.php @@ -5,11 +5,15 @@ use Rector\Config\RectorConfig; use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceFormatJsonEncodeFluidRector; use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceLFluidRector; +use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceMediaImageFluidRector; +use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceUriImageFluidRector; use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceVariableSetFluidRector; return static function (RectorConfig $rectorConfig): void { $rectorConfig->import(__DIR__ . '/config.php'); $rectorConfig->rule(ReplaceFormatJsonEncodeFluidRector::class); $rectorConfig->rule(ReplaceLFluidRector::class); + $rectorConfig->rule(ReplaceMediaImageFluidRector::class); + $rectorConfig->rule(ReplaceUriImageFluidRector::class); $rectorConfig->rule(ReplaceVariableSetFluidRector::class); }; diff --git a/src/FileProcessor/Fluid/Rector/vhs/ReplaceMediaImageFluidRector.php b/src/FileProcessor/Fluid/Rector/vhs/ReplaceMediaImageFluidRector.php new file mode 100644 index 000000000..9b8a91fc6 --- /dev/null +++ b/src/FileProcessor/Fluid/Rector/vhs/ReplaceMediaImageFluidRector.php @@ -0,0 +1,51 @@ +getFileContent(); + + // TODO 1: handle 'relative' attribute -> transform to inverted 'absolute' + // TODO 2: handle maxW attribute -> rename to maxWidth + // TODO 3: handle maxH attribute -> rename to maxHeight + $content = Strings::replace($content, self::PATTERN, self::REPLACEMENT); + + $file->changeFileContent($content); + } + + public function getRuleDefinition(): RuleDefinition + { + return new RuleDefinition('Use instead of ', [ + new CodeSample( + <<<'CODE_SAMPLE' + +CODE_SAMPLE + , + <<<'CODE_SAMPLE' + +CODE_SAMPLE + ), + ]); + } +} diff --git a/src/FileProcessor/Fluid/Rector/vhs/ReplaceUriImageFluidRector.php b/src/FileProcessor/Fluid/Rector/vhs/ReplaceUriImageFluidRector.php new file mode 100644 index 000000000..b68b378f3 --- /dev/null +++ b/src/FileProcessor/Fluid/Rector/vhs/ReplaceUriImageFluidRector.php @@ -0,0 +1,57 @@ +getFileContent(); + + // TODO 1: handle 'relative' attribute -> transform to inverted 'absolute' + // TODO 2: handle maxW attribute -> rename to maxWidth + // TODO 3: handle maxH attribute -> rename to maxHeight + $content = Strings::replace($content, self::PATTERN, self::REPLACEMENT); + + $file->changeFileContent($content); + } + + public function getRuleDefinition(): RuleDefinition + { + return new RuleDefinition('Use instead of ', [ + new CodeSample( + <<<'CODE_SAMPLE' +{v:uri.image(src:image.uid, treatIdAsReference: 1)} +{v:uri.image(src:image.uid, treatIdAsReference: 1, relative: 1)} +{v:uri.image(src:image.uid, treatIdAsReference: 1, relative: 0)} +{v:uri.image(src:image.uid, treatIdAsReference: 1, maxW: 250, maxH: 250)} +CODE_SAMPLE + , + <<<'CODE_SAMPLE' +{f:uri.image(src:image.uid, treatIdAsReference: 1)} +{f:uri.image(src:image.uid, treatIdAsReference: 1)} +{f:uri.image(src:image.uid, treatIdAsReference: 1, absolute: 1)} +{f:uri.image(src:image.uid, treatIdAsReference: 1, maxWidth: 250, maxHeight: 250)} +CODE_SAMPLE + ), + ]); + } +} From 553570e75960c60ba5b96d7ecbd1f3e86fd50811 Mon Sep 17 00:00:00 2001 From: Philipp Kitzberger Date: Tue, 6 Jun 2023 16:53:31 +0200 Subject: [PATCH 5/8] [FEATURE] Provide rules to migrate v:or --- config/replace-vhs.php | 2 + .../Fluid/Rector/vhs/ReplaceOrFluidRector.php | 50 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 src/FileProcessor/Fluid/Rector/vhs/ReplaceOrFluidRector.php diff --git a/config/replace-vhs.php b/config/replace-vhs.php index 5c46cb655..62cf604a8 100644 --- a/config/replace-vhs.php +++ b/config/replace-vhs.php @@ -6,6 +6,7 @@ use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceFormatJsonEncodeFluidRector; use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceLFluidRector; use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceMediaImageFluidRector; +use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceOrFluidRector; use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceUriImageFluidRector; use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceVariableSetFluidRector; @@ -14,6 +15,7 @@ $rectorConfig->rule(ReplaceFormatJsonEncodeFluidRector::class); $rectorConfig->rule(ReplaceLFluidRector::class); $rectorConfig->rule(ReplaceMediaImageFluidRector::class); + $rectorConfig->rule(ReplaceOrFluidRector::class); $rectorConfig->rule(ReplaceUriImageFluidRector::class); $rectorConfig->rule(ReplaceVariableSetFluidRector::class); }; diff --git a/src/FileProcessor/Fluid/Rector/vhs/ReplaceOrFluidRector.php b/src/FileProcessor/Fluid/Rector/vhs/ReplaceOrFluidRector.php new file mode 100644 index 000000000..2ced0ab4d --- /dev/null +++ b/src/FileProcessor/Fluid/Rector/vhs/ReplaceOrFluidRector.php @@ -0,0 +1,50 @@ +getFileContent(); + + $content = Strings::replace( + $content, + '#-> (v|vhs):or\(alternative:(\s?)([^),]+)\)#ims', + '?: $3' + ); + + $content = Strings::replace( + $content, + '#(v|vhs):or\(content:(\s?)([^),]+),(\s?)alternative:(\s?)([^),]+)\)#ims', + '$3 ?: $6' + ); + + $file->changeFileContent($content); + } + + public function getRuleDefinition(): RuleDefinition + { + return new RuleDefinition('Use instead of ', [ + new CodeSample( + <<<'CODE_SAMPLE' +{someVariable -> v:or(alternative: 'Fallback text')} +{v:or(content: someVariable, alternative: 'Fallback text')} +CODE_SAMPLE + , + <<<'CODE_SAMPLE' +{someVariable ?: 'Fallback text'} +{someVariable ?: 'Fallback text'} +CODE_SAMPLE + ), + ]); + } +} From df2eba0214bee98003531915e95b09ee5a9c01f6 Mon Sep 17 00:00:00 2001 From: Philipp Kitzberger Date: Wed, 14 Jun 2023 15:43:14 +0200 Subject: [PATCH 6/8] Added unit tests for vhs migrations --- .../vhs/ReplaceMediaImageFluidRector.php | 2 +- .../Fixture/fixture.html.inc | 5 +++ ...ReplaceFormatJsonEncodeFluidRectorTest.php | 32 +++++++++++++++++++ .../config/configured_rule.php | 11 +++++++ .../Fixture/fixture.html.inc | 7 ++++ .../ReplaceLFluidRectorTest.php | 32 +++++++++++++++++++ .../config/configured_rule.php | 11 +++++++ .../Fixture/fixture.html.inc | 3 ++ .../ReplaceMediaImageFluidRectorTest.php | 32 +++++++++++++++++++ .../config/configured_rule.php | 11 +++++++ .../Fixture/fixture.html.inc | 5 +++ .../ReplaceOrFluidRectorTest.php | 32 +++++++++++++++++++ .../config/configured_rule.php | 11 +++++++ .../Fixture/fixture.html.inc | 9 ++++++ .../ReplaceUriImageFluidRectorTest.php | 32 +++++++++++++++++++ .../config/configured_rule.php | 11 +++++++ .../Fixture/fixture.html.inc | 5 +++ .../ReplaceVariableSetFluidRectorTest.php | 32 +++++++++++++++++++ .../config/configured_rule.php | 11 +++++++ 19 files changed, 293 insertions(+), 1 deletion(-) create mode 100644 tests/FileProcessor/Fluid/Rector/vhs/ReplaceFormatJsonEncodeFluidRector/Fixture/fixture.html.inc create mode 100644 tests/FileProcessor/Fluid/Rector/vhs/ReplaceFormatJsonEncodeFluidRector/ReplaceFormatJsonEncodeFluidRectorTest.php create mode 100644 tests/FileProcessor/Fluid/Rector/vhs/ReplaceFormatJsonEncodeFluidRector/config/configured_rule.php create mode 100644 tests/FileProcessor/Fluid/Rector/vhs/ReplaceLFluidRector/Fixture/fixture.html.inc create mode 100644 tests/FileProcessor/Fluid/Rector/vhs/ReplaceLFluidRector/ReplaceLFluidRectorTest.php create mode 100644 tests/FileProcessor/Fluid/Rector/vhs/ReplaceLFluidRector/config/configured_rule.php create mode 100644 tests/FileProcessor/Fluid/Rector/vhs/ReplaceMediaImageFluidRector/Fixture/fixture.html.inc create mode 100644 tests/FileProcessor/Fluid/Rector/vhs/ReplaceMediaImageFluidRector/ReplaceMediaImageFluidRectorTest.php create mode 100644 tests/FileProcessor/Fluid/Rector/vhs/ReplaceMediaImageFluidRector/config/configured_rule.php create mode 100644 tests/FileProcessor/Fluid/Rector/vhs/ReplaceOrFluidRector/Fixture/fixture.html.inc create mode 100644 tests/FileProcessor/Fluid/Rector/vhs/ReplaceOrFluidRector/ReplaceOrFluidRectorTest.php create mode 100644 tests/FileProcessor/Fluid/Rector/vhs/ReplaceOrFluidRector/config/configured_rule.php create mode 100644 tests/FileProcessor/Fluid/Rector/vhs/ReplaceUriImageFluidRector/Fixture/fixture.html.inc create mode 100644 tests/FileProcessor/Fluid/Rector/vhs/ReplaceUriImageFluidRector/ReplaceUriImageFluidRectorTest.php create mode 100644 tests/FileProcessor/Fluid/Rector/vhs/ReplaceUriImageFluidRector/config/configured_rule.php create mode 100644 tests/FileProcessor/Fluid/Rector/vhs/ReplaceVariableSetFluidRector/Fixture/fixture.html.inc create mode 100644 tests/FileProcessor/Fluid/Rector/vhs/ReplaceVariableSetFluidRector/ReplaceVariableSetFluidRectorTest.php create mode 100644 tests/FileProcessor/Fluid/Rector/vhs/ReplaceVariableSetFluidRector/config/configured_rule.php diff --git a/src/FileProcessor/Fluid/Rector/vhs/ReplaceMediaImageFluidRector.php b/src/FileProcessor/Fluid/Rector/vhs/ReplaceMediaImageFluidRector.php index 9b8a91fc6..f0b0426b2 100644 --- a/src/FileProcessor/Fluid/Rector/vhs/ReplaceMediaImageFluidRector.php +++ b/src/FileProcessor/Fluid/Rector/vhs/ReplaceMediaImageFluidRector.php @@ -39,7 +39,7 @@ public function getRuleDefinition(): RuleDefinition return new RuleDefinition('Use instead of ', [ new CodeSample( <<<'CODE_SAMPLE' - + CODE_SAMPLE , <<<'CODE_SAMPLE' diff --git a/tests/FileProcessor/Fluid/Rector/vhs/ReplaceFormatJsonEncodeFluidRector/Fixture/fixture.html.inc b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceFormatJsonEncodeFluidRector/Fixture/fixture.html.inc new file mode 100644 index 000000000..3cb075467 --- /dev/null +++ b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceFormatJsonEncodeFluidRector/Fixture/fixture.html.inc @@ -0,0 +1,5 @@ +{someArray -> v:format.json.encode()} + +----- +{someArray -> f:format.json()} + diff --git a/tests/FileProcessor/Fluid/Rector/vhs/ReplaceFormatJsonEncodeFluidRector/ReplaceFormatJsonEncodeFluidRectorTest.php b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceFormatJsonEncodeFluidRector/ReplaceFormatJsonEncodeFluidRectorTest.php new file mode 100644 index 000000000..a5cff08fb --- /dev/null +++ b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceFormatJsonEncodeFluidRector/ReplaceFormatJsonEncodeFluidRectorTest.php @@ -0,0 +1,32 @@ +doTestFile($filePath); + } + + /** + * @return Iterator> + */ + public function provideData(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture', '*.html.inc'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/FileProcessor/Fluid/Rector/vhs/ReplaceFormatJsonEncodeFluidRector/config/configured_rule.php b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceFormatJsonEncodeFluidRector/config/configured_rule.php new file mode 100644 index 000000000..52b07cd77 --- /dev/null +++ b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceFormatJsonEncodeFluidRector/config/configured_rule.php @@ -0,0 +1,11 @@ +import(__DIR__ . '/../../../../../../../config/config_test.php'); + $rectorConfig->rule(ReplaceFormatJsonEncodeFluidRector::class); +}; diff --git a/tests/FileProcessor/Fluid/Rector/vhs/ReplaceLFluidRector/Fixture/fixture.html.inc b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceLFluidRector/Fixture/fixture.html.inc new file mode 100644 index 000000000..b95df0a84 --- /dev/null +++ b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceLFluidRector/Fixture/fixture.html.inc @@ -0,0 +1,7 @@ + + + +----- + + + diff --git a/tests/FileProcessor/Fluid/Rector/vhs/ReplaceLFluidRector/ReplaceLFluidRectorTest.php b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceLFluidRector/ReplaceLFluidRectorTest.php new file mode 100644 index 000000000..6420ab7d8 --- /dev/null +++ b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceLFluidRector/ReplaceLFluidRectorTest.php @@ -0,0 +1,32 @@ +doTestFile($filePath); + } + + /** + * @return Iterator> + */ + public function provideData(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture', '*.html.inc'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/FileProcessor/Fluid/Rector/vhs/ReplaceLFluidRector/config/configured_rule.php b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceLFluidRector/config/configured_rule.php new file mode 100644 index 000000000..d340c7df4 --- /dev/null +++ b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceLFluidRector/config/configured_rule.php @@ -0,0 +1,11 @@ +import(__DIR__ . '/../../../../../../../config/config_test.php'); + $rectorConfig->rule(ReplaceLFluidRector::class); +}; diff --git a/tests/FileProcessor/Fluid/Rector/vhs/ReplaceMediaImageFluidRector/Fixture/fixture.html.inc b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceMediaImageFluidRector/Fixture/fixture.html.inc new file mode 100644 index 000000000..91d745962 --- /dev/null +++ b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceMediaImageFluidRector/Fixture/fixture.html.inc @@ -0,0 +1,3 @@ + +----- + diff --git a/tests/FileProcessor/Fluid/Rector/vhs/ReplaceMediaImageFluidRector/ReplaceMediaImageFluidRectorTest.php b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceMediaImageFluidRector/ReplaceMediaImageFluidRectorTest.php new file mode 100644 index 000000000..15fbf7564 --- /dev/null +++ b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceMediaImageFluidRector/ReplaceMediaImageFluidRectorTest.php @@ -0,0 +1,32 @@ +doTestFile($filePath); + } + + /** + * @return Iterator> + */ + public function provideData(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture', '*.html.inc'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/FileProcessor/Fluid/Rector/vhs/ReplaceMediaImageFluidRector/config/configured_rule.php b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceMediaImageFluidRector/config/configured_rule.php new file mode 100644 index 000000000..2d1968fc8 --- /dev/null +++ b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceMediaImageFluidRector/config/configured_rule.php @@ -0,0 +1,11 @@ +import(__DIR__ . '/../../../../../../../config/config_test.php'); + $rectorConfig->rule(ReplaceMediaImageFluidRector::class); +}; diff --git a/tests/FileProcessor/Fluid/Rector/vhs/ReplaceOrFluidRector/Fixture/fixture.html.inc b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceOrFluidRector/Fixture/fixture.html.inc new file mode 100644 index 000000000..5d2a221d5 --- /dev/null +++ b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceOrFluidRector/Fixture/fixture.html.inc @@ -0,0 +1,5 @@ +{someVariable -> v:or(alternative:'Fallback text')} +{v:or(content: someVariable, alternative: 'Fallback text')} +----- +{someVariable ?: 'Fallback text'} +{someVariable ?: 'Fallback text'} diff --git a/tests/FileProcessor/Fluid/Rector/vhs/ReplaceOrFluidRector/ReplaceOrFluidRectorTest.php b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceOrFluidRector/ReplaceOrFluidRectorTest.php new file mode 100644 index 000000000..dcbd5437c --- /dev/null +++ b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceOrFluidRector/ReplaceOrFluidRectorTest.php @@ -0,0 +1,32 @@ +doTestFile($filePath); + } + + /** + * @return Iterator> + */ + public function provideData(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture', '*.html.inc'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/FileProcessor/Fluid/Rector/vhs/ReplaceOrFluidRector/config/configured_rule.php b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceOrFluidRector/config/configured_rule.php new file mode 100644 index 000000000..55b16885b --- /dev/null +++ b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceOrFluidRector/config/configured_rule.php @@ -0,0 +1,11 @@ +import(__DIR__ . '/../../../../../../../config/config_test.php'); + $rectorConfig->rule(ReplaceOrFluidRector::class); +}; diff --git a/tests/FileProcessor/Fluid/Rector/vhs/ReplaceUriImageFluidRector/Fixture/fixture.html.inc b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceUriImageFluidRector/Fixture/fixture.html.inc new file mode 100644 index 000000000..3897f6cf5 --- /dev/null +++ b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceUriImageFluidRector/Fixture/fixture.html.inc @@ -0,0 +1,9 @@ +{v:uri.image(src:image.uid, treatIdAsReference: 1)} +{v:uri.image(src:image.uid, treatIdAsReference: 1, relative: 1)} +{v:uri.image(src:image.uid, treatIdAsReference: 1, relative: 0)} +{v:uri.image(src:image.uid, treatIdAsReference: 1, maxW: 250, maxH: 250)} +----- +{f:uri.image(src:image.uid, treatIdAsReference: 1)} +{f:uri.image(src:image.uid, treatIdAsReference: 1)} +{f:uri.image(src:image.uid, treatIdAsReference: 1, absolute: 1)} +{f:uri.image(src:image.uid, treatIdAsReference: 1, maxWidth: 250, maxHeight: 250)} diff --git a/tests/FileProcessor/Fluid/Rector/vhs/ReplaceUriImageFluidRector/ReplaceUriImageFluidRectorTest.php b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceUriImageFluidRector/ReplaceUriImageFluidRectorTest.php new file mode 100644 index 000000000..364065408 --- /dev/null +++ b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceUriImageFluidRector/ReplaceUriImageFluidRectorTest.php @@ -0,0 +1,32 @@ +doTestFile($filePath); + } + + /** + * @return Iterator> + */ + public function provideData(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture', '*.html.inc'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/FileProcessor/Fluid/Rector/vhs/ReplaceUriImageFluidRector/config/configured_rule.php b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceUriImageFluidRector/config/configured_rule.php new file mode 100644 index 000000000..33778c3d3 --- /dev/null +++ b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceUriImageFluidRector/config/configured_rule.php @@ -0,0 +1,11 @@ +import(__DIR__ . '/../../../../../../../config/config_test.php'); + $rectorConfig->rule(ReplaceUriImageFluidRector::class); +}; diff --git a/tests/FileProcessor/Fluid/Rector/vhs/ReplaceVariableSetFluidRector/Fixture/fixture.html.inc b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceVariableSetFluidRector/Fixture/fixture.html.inc new file mode 100644 index 000000000..5278475e4 --- /dev/null +++ b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceVariableSetFluidRector/Fixture/fixture.html.inc @@ -0,0 +1,5 @@ + +{myvariable -> v:variable.set(name:'othervariable')} +----- + +{myvariable -> f:variable(name:'othervariable')} diff --git a/tests/FileProcessor/Fluid/Rector/vhs/ReplaceVariableSetFluidRector/ReplaceVariableSetFluidRectorTest.php b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceVariableSetFluidRector/ReplaceVariableSetFluidRectorTest.php new file mode 100644 index 000000000..388cdc76b --- /dev/null +++ b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceVariableSetFluidRector/ReplaceVariableSetFluidRectorTest.php @@ -0,0 +1,32 @@ +doTestFile($filePath); + } + + /** + * @return Iterator> + */ + public function provideData(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture', '*.html.inc'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/FileProcessor/Fluid/Rector/vhs/ReplaceVariableSetFluidRector/config/configured_rule.php b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceVariableSetFluidRector/config/configured_rule.php new file mode 100644 index 000000000..0f7899a25 --- /dev/null +++ b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceVariableSetFluidRector/config/configured_rule.php @@ -0,0 +1,11 @@ +import(__DIR__ . '/../../../../../../../config/config_test.php'); + $rectorConfig->rule(ReplaceVariableSetFluidRector::class); +}; From fb46b9d2b90241d61128b64401a6cbd3ad5932eb Mon Sep 17 00:00:00 2001 From: Philipp Kitzberger Date: Thu, 15 Jun 2023 10:21:29 +0200 Subject: [PATCH 7/8] Tweak replace v:varible.set * Only migrate the simple cases by the 'strict' pattern * Print warning about left over cases --- .../vhs/ReplaceVariableSetFluidRector.php | 30 +++++++++++++++++-- .../Fixture/fixture.html.inc | 6 ---- .../Fixture/fixture.html.inc | 14 +++++++-- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/FileProcessor/Fluid/Rector/vhs/ReplaceVariableSetFluidRector.php b/src/FileProcessor/Fluid/Rector/vhs/ReplaceVariableSetFluidRector.php index 9be4ee009..cc9248249 100644 --- a/src/FileProcessor/Fluid/Rector/vhs/ReplaceVariableSetFluidRector.php +++ b/src/FileProcessor/Fluid/Rector/vhs/ReplaceVariableSetFluidRector.php @@ -5,6 +5,7 @@ namespace Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs; use Nette\Utils\Strings; +use Rector\Core\Console\Output\RectorOutputStyle; use Rector\Core\ValueObject\Application\File; use Ssch\TYPO3Rector\Contract\FileProcessor\Fluid\Rector\FluidRectorInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -15,18 +16,41 @@ final class ReplaceVariableSetFluidRector implements FluidRectorInterface /** * @var string */ - private const PATTERN = '#(v|vhs):variable.set#imsU'; + private const PATTERN_STRICT = '#(v|vhs):(variable.set)([\s(]name[:=]["\'])([a-z]+)(["\'])#imsU'; /** * @var string */ - private const REPLACEMENT = 'f:variable'; + private const PATTERN_DOT = '#(v|vhs):(variable.set)([\s(]name[:=]["\'])([a-z\.]+)(["\'])#imsU'; + + /** + * @var string + */ + private const PATTERN_LEFTOVERS = '#(v|vhs):(variable.set)#imsU'; + + /** + * @readonly + */ + private RectorOutputStyle $rectorOutputStyle; + + public function __construct(RectorOutputStyle $rectorOutputStyle) + { + $this->rectorOutputStyle = $rectorOutputStyle; + } public function transform(File $file): void { $content = $file->getFileContent(); - $content = Strings::replace($content, self::PATTERN, self::REPLACEMENT); + $content = Strings::replace($content, self::PATTERN_STRICT, 'f:variable$3$4$5'); + + if (Strings::matchAll($content, self::PATTERN_DOT)) { + $this->rectorOutputStyle->warning('There\'s occurrences of v:variable.set that contain a dot in its name attribute and thus cannot be migrated to f:variable!'); + } + + if (Strings::matchAll($content, self::PATTERN_LEFTOVERS)) { + $this->rectorOutputStyle->warning('There\'s occurrences of v:variable.set that couldn\'t be migrated automatically. Migrate them manually!'); + } $file->changeFileContent($content); } diff --git a/tests/FileProcessor/Fluid/Rector/vhs/ReplaceUriImageFluidRector/Fixture/fixture.html.inc b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceUriImageFluidRector/Fixture/fixture.html.inc index 3897f6cf5..f4ff96fb3 100644 --- a/tests/FileProcessor/Fluid/Rector/vhs/ReplaceUriImageFluidRector/Fixture/fixture.html.inc +++ b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceUriImageFluidRector/Fixture/fixture.html.inc @@ -1,9 +1,3 @@ {v:uri.image(src:image.uid, treatIdAsReference: 1)} -{v:uri.image(src:image.uid, treatIdAsReference: 1, relative: 1)} -{v:uri.image(src:image.uid, treatIdAsReference: 1, relative: 0)} -{v:uri.image(src:image.uid, treatIdAsReference: 1, maxW: 250, maxH: 250)} ----- {f:uri.image(src:image.uid, treatIdAsReference: 1)} -{f:uri.image(src:image.uid, treatIdAsReference: 1)} -{f:uri.image(src:image.uid, treatIdAsReference: 1, absolute: 1)} -{f:uri.image(src:image.uid, treatIdAsReference: 1, maxWidth: 250, maxHeight: 250)} diff --git a/tests/FileProcessor/Fluid/Rector/vhs/ReplaceVariableSetFluidRector/Fixture/fixture.html.inc b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceVariableSetFluidRector/Fixture/fixture.html.inc index 5278475e4..1166ca331 100644 --- a/tests/FileProcessor/Fluid/Rector/vhs/ReplaceVariableSetFluidRector/Fixture/fixture.html.inc +++ b/tests/FileProcessor/Fluid/Rector/vhs/ReplaceVariableSetFluidRector/Fixture/fixture.html.inc @@ -1,5 +1,15 @@ - +Simple (and easily migratable) cases: {myvariable -> v:variable.set(name:'othervariable')} + + +More complex cases (and unmigratable) cases: + + ----- - +Simple (and easily migratable) cases: {myvariable -> f:variable(name:'othervariable')} + + +More complex cases (and unmigratable) cases: + + From dbcececf7bd81244320858e4be12f8371c5dabff Mon Sep 17 00:00:00 2001 From: Philipp Kitzberger Date: Mon, 17 Jul 2023 11:33:02 +0200 Subject: [PATCH 8/8] [FEATURE] Provide rule to migrate v:extension.path.relative --- config/replace-vhs.php | 2 + ...eplaceExtensionPathRelativeFluidRector.php | 67 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src/FileProcessor/Fluid/Rector/vhs/ReplaceExtensionPathRelativeFluidRector.php diff --git a/config/replace-vhs.php b/config/replace-vhs.php index 62cf604a8..773149410 100644 --- a/config/replace-vhs.php +++ b/config/replace-vhs.php @@ -3,6 +3,7 @@ declare(strict_types=1); use Rector\Config\RectorConfig; +use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceExtensionPathRelativeFluidRector; use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceFormatJsonEncodeFluidRector; use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceLFluidRector; use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceMediaImageFluidRector; @@ -12,6 +13,7 @@ return static function (RectorConfig $rectorConfig): void { $rectorConfig->import(__DIR__ . '/config.php'); + $rectorConfig->rule(ReplaceExtensionPathRelativeFluidRector::class); $rectorConfig->rule(ReplaceFormatJsonEncodeFluidRector::class); $rectorConfig->rule(ReplaceLFluidRector::class); $rectorConfig->rule(ReplaceMediaImageFluidRector::class); diff --git a/src/FileProcessor/Fluid/Rector/vhs/ReplaceExtensionPathRelativeFluidRector.php b/src/FileProcessor/Fluid/Rector/vhs/ReplaceExtensionPathRelativeFluidRector.php new file mode 100644 index 000000000..0a366140a --- /dev/null +++ b/src/FileProcessor/Fluid/Rector/vhs/ReplaceExtensionPathRelativeFluidRector.php @@ -0,0 +1,67 @@ +rectorOutputStyle = $rectorOutputStyle; + } + + public function transform(File $file): void + { + $content = $file->getFileContent(); + + $content = Strings::replace( + $content, + self::PATTERN_INLINE, + '{f:uri.resource(extensionName:\'\3\',path:\'\4.\5\')}' + ); + + if (Strings::matchAll($content, self::PATTERN_LEFTOVERS)) { + $this->rectorOutputStyle->warning('There\'s occurrences of v:extension.path.relative that couldn\'t be migrated automatically. Migrate them manually!'); + } + + $file->changeFileContent($content); + } + + public function getRuleDefinition(): RuleDefinition + { + return new RuleDefinition('Use instead of ', [ + new CodeSample( + <<<'CODE_SAMPLE' +{v:extension.path.relative(extensionName:'my_extension')}Resources/Public/Css/style.css +CODE_SAMPLE + , + <<<'CODE_SAMPLE' +{f:uri.resource(extensionName:'my_extension',path:'Css/style.css')} +CODE_SAMPLE + ), + ]); + } +}