Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] Remove unused wordspace TSConfig modes #3187

Merged
merged 1 commit into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
};