Skip to content

Commit

Permalink
TASK: Add rule TemplateToFluidTemplateTypoScriptRector (#2966)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbelasichon authored May 10, 2022
1 parent 8d62a8b commit 8814f02
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/v11/typo3-110.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Rector\Transform\Rector\StaticCall\StaticCallToFuncCallRector;

use Rector\Transform\ValueObject\StaticCallToFuncCall;
use Ssch\TYPO3Rector\FileProcessor\TypoScript\Rector\TemplateToFluidTemplateTypoScriptRector;
use Ssch\TYPO3Rector\Rector\v11\v0\DateTimeAspectInsteadOfGlobalsExecTimeRector;
use Ssch\TYPO3Rector\Rector\v11\v0\ExtbaseControllerActionsMustReturnResponseInterfaceRector;
use Ssch\TYPO3Rector\Rector\v11\v0\ForwardResponseInsteadOfForwardMethodRector;
Expand Down Expand Up @@ -37,4 +38,5 @@
),
]);
$rectorConfig->rule(ReplaceInjectAnnotationWithMethodRector::class);
$rectorConfig->rule(TemplateToFluidTemplateTypoScriptRector::class);
};
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
),
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
page.10 = TEMPLATE
-----
page.10 = FLUIDTEMPLATE
2 changes: 2 additions & 0 deletions tests/FileProcessor/TypoScript/config/configured_rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Ssch\TYPO3Rector\FileProcessor\TypoScript\Rector\FileIncludeToImportStatementTypoScriptRector;
use Ssch\TYPO3Rector\FileProcessor\TypoScript\Rector\LibFluidContentToLibContentElementRector;
use Ssch\TYPO3Rector\FileProcessor\TypoScript\Rector\OldConditionToExpressionLanguageTypoScriptRector;
use Ssch\TYPO3Rector\FileProcessor\TypoScript\Rector\TemplateToFluidTemplateTypoScriptRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../../../../config/config_test.php');
Expand Down Expand Up @@ -51,4 +52,5 @@
$rectorConfig->rule(AdditionalHeadersToArrayTypoScriptRector::class);
$rectorConfig->rule(LibFluidContentToLibContentElementRector::class);
$rectorConfig->rule(LibFluidContentToContentElementTypoScriptPostRector::class);
$rectorConfig->rule(TemplateToFluidTemplateTypoScriptRector::class);
};

0 comments on commit 8814f02

Please sign in to comment.