-
-
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.
[FEATURE] Provide migration for typoscript xhtmlDoctype config
Resolves: #3616
- Loading branch information
1 parent
9b3fdfe
commit 3e2b822
Showing
5 changed files
with
114 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
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
50
src/Rector/v12/v4/typoscript/MigrateXhtmlDoctypeRector.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,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 | ||
)]); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/Rector/v12/v4/typoscript/MigrateXhtmlDoctypeRector/Fixture/fixture.typoscript.inc
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 @@ | ||
config.xhtmlDoctype = 1 | ||
|
||
config { | ||
xhtmlDoctype = 1 | ||
} | ||
----- | ||
config.doctype = 1 | ||
|
||
config { | ||
doctype = 1 | ||
} |
32 changes: 32 additions & 0 deletions
32
tests/Rector/v12/v4/typoscript/MigrateXhtmlDoctypeRector/MigrateXhtmlDoctypeRectorTest.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,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'; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/Rector/v12/v4/typoscript/MigrateXhtmlDoctypeRector/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\v4\typoscript\MigrateXhtmlDoctypeRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->import(__DIR__ . '/../../../../../../../config/config_test.php'); | ||
$rectorConfig->rule(MigrateXhtmlDoctypeRector::class); | ||
}; |