-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Remove unused wordspace TSConfig modes
Resolves: #3172
- Loading branch information
Showing
5 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/Rector/v12/v0/typoscript/RemoveTSConfigModesRector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ssch\TYPO3Rector\Rector\v12\v0\typoscript; | ||
|
||
use Helmich\TypoScriptParser\Parser\AST\Operator\Assignment; | ||
use Helmich\TypoScriptParser\Parser\AST\Statement; | ||
use Rector\Core\Provider\CurrentFileProvider; | ||
use Rector\Core\ValueObject\Application\File; | ||
use Ssch\TYPO3Rector\FileProcessor\TypoScript\Collector\RemoveTypoScriptStatementCollector; | ||
use Ssch\TYPO3Rector\FileProcessor\TypoScript\Rector\AbstractTypoScriptRector; | ||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
|
||
/** | ||
* @changelog https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.0/Breaking-98437-WorkspaceTSConfigSwapModeAndChangeStageModeRemoved.html | ||
* @see \Ssch\TYPO3Rector\Tests\Rector\v12\v0\typoscript\RemoveTSConfigModesRector\RemoveTSConfigModesRectorTest | ||
*/ | ||
final class RemoveTSConfigModesRector extends AbstractTypoScriptRector | ||
{ | ||
/** | ||
* @readonly | ||
*/ | ||
private RemoveTypoScriptStatementCollector $removeTypoScriptStatementCollector; | ||
|
||
/** | ||
* @readonly | ||
*/ | ||
private CurrentFileProvider $currentFileProvider; | ||
|
||
public function __construct( | ||
RemoveTypoScriptStatementCollector $removeTypoScriptStatementCollector, | ||
CurrentFileProvider $currentFileProvider | ||
) { | ||
$this->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 | ||
)]); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/Rector/v12/v0/typoscript/RemoveTSConfigModesRector/Fixture/fixture.typoscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
33 changes: 33 additions & 0 deletions
33
tests/Rector/v12/v0/typoscript/RemoveTSConfigModesRector/RemoveTSConfigModesRectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ssch\TYPO3Rector\Tests\Rector\v12\v0\typoscript\RemoveTSConfigModesRector; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class RemoveTSConfigModesRectorTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
/** | ||
* @return Iterator<array<string>> | ||
*/ | ||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture', '*.typoscript'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/Rector/v12/v0/typoscript/RemoveTSConfigModesRector/config/configured_rule.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Ssch\TYPO3Rector\Rector\v12\v0\typoscript\RemoveTSConfigModesRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->import(__DIR__ . '/../../../../../../../config/config_test.php'); | ||
$rectorConfig->rule(RemoveTSConfigModesRector::class); | ||
}; |