diff --git a/config/v12/typoscript-120.php b/config/v12/typoscript-120.php index 4da613c9d..4435e243c 100644 --- a/config/v12/typoscript-120.php +++ b/config/v12/typoscript-120.php @@ -18,4 +18,5 @@ $rectorConfig->rule(RemoveMetaCharSetRector::class); $rectorConfig->rule(\Ssch\TYPO3Rector\Rector\v12\v0\typoscript\RemoveConfigDoctypeSwitchRector::class); $rectorConfig->rule(\Ssch\TYPO3Rector\Rector\v12\v0\typoscript\UseConfigArrayForTSFEPropertiesRector::class); + $rectorConfig->rule(\Ssch\TYPO3Rector\Rector\v12\v0\typoscript\RemoveTSConfigModesRector::class); }; diff --git a/src/Rector/v12/v0/typoscript/RemoveTSConfigModesRector.php b/src/Rector/v12/v0/typoscript/RemoveTSConfigModesRector.php new file mode 100644 index 000000000..2a617c329 --- /dev/null +++ b/src/Rector/v12/v0/typoscript/RemoveTSConfigModesRector.php @@ -0,0 +1,77 @@ +removeTypoScriptStatementCollector = $removeTypoScriptStatementCollector; + $this->currentFileProvider = $currentFileProvider; + } + + public function enterNode(Statement $statement): void + { + if (! $statement instanceof Assignment) { + return; + } + + if ('options.workspaces.swapMode' !== $statement->object->absoluteName + && 'options.workspaces.changeStageMode' !== $statement->object->absoluteName) { + return; + } + + $file = $this->currentFileProvider->getFile(); + + if (! $file instanceof File) { + return; + } + + $this->removeTypoScriptStatementCollector->removeStatement($statement, $file); + $this->hasChanged = true; + } + + /** + * @codeCoverageIgnore + */ + public function getRuleDefinition(): RuleDefinition + { + return new RuleDefinition('Remove config.spamProtectEmailAddresses with option ascii', [new CodeSample( + <<<'CODE_SAMPLE' +options.workspaces.swapMode = any +options.workspaces.changeStageMode = any +CODE_SAMPLE + , + <<<'CODE_SAMPLE' +- +CODE_SAMPLE + )]); + } +} diff --git a/tests/Rector/v12/v0/typoscript/RemoveTSConfigModesRector/Fixture/fixture.typoscript b/tests/Rector/v12/v0/typoscript/RemoveTSConfigModesRector/Fixture/fixture.typoscript new file mode 100644 index 000000000..814fa7cf9 --- /dev/null +++ b/tests/Rector/v12/v0/typoscript/RemoveTSConfigModesRector/Fixture/fixture.typoscript @@ -0,0 +1,21 @@ +options.workspaces.swapMode = any +options.workspaces.swapMode = page +options.workspaces.changeStageMode = any +options.workspaces.changeStageMode = page + +options { + workspaces.swapMode = any + workspaces.swapMode = page + workspaces.changeStageMode = any + workspaces.changeStageMode = page + dummy = 1 +} + +config.foo = true +----- + +options { + dummy = 1 +} + +config.foo = true diff --git a/tests/Rector/v12/v0/typoscript/RemoveTSConfigModesRector/RemoveTSConfigModesRectorTest.php b/tests/Rector/v12/v0/typoscript/RemoveTSConfigModesRector/RemoveTSConfigModesRectorTest.php new file mode 100644 index 000000000..f5860214e --- /dev/null +++ b/tests/Rector/v12/v0/typoscript/RemoveTSConfigModesRector/RemoveTSConfigModesRectorTest.php @@ -0,0 +1,33 @@ +doTestFile($filePath); + } + + /** + * @return Iterator> + */ + public function provideData(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture', '*.typoscript'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Rector/v12/v0/typoscript/RemoveTSConfigModesRector/config/configured_rule.php b/tests/Rector/v12/v0/typoscript/RemoveTSConfigModesRector/config/configured_rule.php new file mode 100644 index 000000000..7e5ccf16b --- /dev/null +++ b/tests/Rector/v12/v0/typoscript/RemoveTSConfigModesRector/config/configured_rule.php @@ -0,0 +1,11 @@ +import(__DIR__ . '/../../../../../../../config/config_test.php'); + $rectorConfig->rule(RemoveTSConfigModesRector::class); +};