-
-
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: Add rule TemplateToFluidTemplateTypoScriptRector (#2966)
- Loading branch information
1 parent
8d62a8b
commit 8814f02
Showing
4 changed files
with
57 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
50 changes: 50 additions & 0 deletions
50
src/FileProcessor/TypoScript/Rector/TemplateToFluidTemplateTypoScriptRector.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\FileProcessor\TypoScript\Rector; | ||
|
||
use Helmich\TypoScriptParser\Parser\AST\Operator\ObjectCreation; | ||
use Helmich\TypoScriptParser\Parser\AST\Scalar; | ||
use Helmich\TypoScriptParser\Parser\AST\Statement; | ||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
|
||
/** | ||
* @changelog https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/11.0/Breaking-91562-CObjectTEMPLATERemoved.html | ||
* @see \Ssch\TYPO3Rector\Tests\FileProcessor\TypoScript\TypoScriptProcessorTest | ||
*/ | ||
final class TemplateToFluidTemplateTypoScriptRector extends AbstractTypoScriptRector | ||
{ | ||
public function enterNode(Statement $statement): void | ||
{ | ||
if (! $statement instanceof ObjectCreation) { | ||
return; | ||
} | ||
|
||
if (! $statement->value instanceof Scalar) { | ||
return; | ||
} | ||
|
||
if ('TEMPLATE' !== $statement->value->value) { | ||
return; | ||
} | ||
|
||
$statement->value->value = 'FLUIDTEMPLATE'; | ||
} | ||
|
||
public function getRuleDefinition(): RuleDefinition | ||
{ | ||
return new RuleDefinition('Convert TEMPLATE to FLUIDTEMPLATE', [ | ||
new CodeSample( | ||
<<<'CODE_SAMPLE' | ||
page.10 = TEMPLATE | ||
CODE_SAMPLE | ||
, | ||
<<<'CODE_SAMPLE' | ||
page.10 = FLUIDTEMPLATE | ||
CODE_SAMPLE | ||
), | ||
]); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
tests/FileProcessor/TypoScript/Fixture/TypoScript/template_to_fluidtemplate.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,3 @@ | ||
page.10 = TEMPLATE | ||
----- | ||
page.10 = FLUIDTEMPLATE |
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