Skip to content

Commit

Permalink
[TASK] Remove unused wordspace TSConfig modes
Browse files Browse the repository at this point in the history
Resolves: #3172
  • Loading branch information
helsner committed Oct 3, 2022
1 parent 6c3f90d commit 1724c03
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/v12/typoscript-120.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
77 changes: 77 additions & 0 deletions src/Rector/v12/v0/typoscript/RemoveTSConfigModesRector.php
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
)]);
}
}
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
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';
}
}
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);
};

0 comments on commit 1724c03

Please sign in to comment.