Skip to content

Commit

Permalink
[FEATURE] Provide migration for typoscript xhtmlDoctype config
Browse files Browse the repository at this point in the history
Resolves: #3616
  • Loading branch information
helsner authored and simonschaufi committed Dec 22, 2023
1 parent 9b3fdfe commit 3e2b822
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 0 deletions.
10 changes: 10 additions & 0 deletions config/v12/typoscript-124.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');
$rectorConfig->rule(\Ssch\TYPO3Rector\Rector\v12\v4\typoscript\MigrateXhtmlDoctypeRector::class);
};
50 changes: 50 additions & 0 deletions src/Rector/v12/v4/typoscript/MigrateXhtmlDoctypeRector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace Ssch\TYPO3Rector\Rector\v12\v4\typoscript;

use Helmich\TypoScriptParser\Parser\AST\Operator\Assignment;
use Helmich\TypoScriptParser\Parser\AST\Statement;
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.4/Deprecation-100461-TypoScriptOptionConfigxhtmlDoctype.html
* @see \Ssch\TYPO3Rector\Tests\Rector\v12\v4\typoscript\MigrateXhtmlDoctypeRector\MigrateXhtmlDoctypeRectorTest
*/
final class MigrateXhtmlDoctypeRector extends AbstractTypoScriptRector
{
public function enterNode(Statement $statement): void
{
if (! $statement instanceof Assignment) {
return;
}

if ($statement->object->absoluteName !== 'config.xhtmlDoctype') {
return;
}

$statement->object->relativeName = str_replace('xhtmlDoctype', 'doctype',$statement->object->relativeName);
$statement->object->absoluteName = str_replace('xhtmlDoctype', 'doctype',$statement->object->absoluteName);

$this->hasChanged = true;
}

/**
* @codeCoverageIgnore
*/
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Migrate typoscript xhtmlDoctype to doctype', [new CodeSample(
<<<'CODE_SAMPLE'
config.xhtmlDoctype = 1
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
config.doctype = 1
CODE_SAMPLE
)]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
config.xhtmlDoctype = 1

config {
xhtmlDoctype = 1
}
-----
config.doctype = 1

config {
doctype = 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Ssch\TYPO3Rector\Tests\Rector\v12\v4\typoscript\MigrateXhtmlDoctypeRector;

use Iterator;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class MigrateXhtmlDoctypeRectorTest 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.inc');
}

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\v4\typoscript\MigrateXhtmlDoctypeRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../../../../../../../config/config_test.php');
$rectorConfig->rule(MigrateXhtmlDoctypeRector::class);
};

0 comments on commit 3e2b822

Please sign in to comment.