Skip to content

Commit

Permalink
[FEATURE] Add RemoveAddLLrefForTCAdescrMethodCallRector
Browse files Browse the repository at this point in the history
  • Loading branch information
MohsinQK committed Jan 9, 2025
1 parent d3cc086 commit d684509
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/v12/typo3-120.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Ssch\TYPO3Rector\TYPO312\v0\MigrateFetchToFetchAssociativeRector;
use Ssch\TYPO3Rector\TYPO312\v0\MigrateQueryBuilderExecuteRector;
use Ssch\TYPO3Rector\TYPO312\v0\MoveAllowTableOnStandardPagesToTCAConfigurationRector;
use Ssch\TYPO3Rector\TYPO312\v0\RemoveAddLLrefForTCAdescrMethodCallRector;
use Ssch\TYPO3Rector\TYPO312\v0\RemoveMailerAdapterInterfaceRector;
use Ssch\TYPO3Rector\TYPO312\v0\RemoveRelativeToCurrentScriptArgumentsRector;
use Ssch\TYPO3Rector\TYPO312\v0\RemoveTSFEConvOutputCharsetCallsRector;
Expand Down Expand Up @@ -173,4 +174,5 @@
$rectorConfig->rule(MigrateBackendModuleRegistrationRector::class);
$rectorConfig->rule(MigrateContentObjectRendererGetTypoLinkUrlRector::class);
$rectorConfig->rule(ExtbaseActionsWithRedirectMustReturnResponseInterfaceRector::class);
$rectorConfig->rule(RemoveAddLLrefForTCAdescrMethodCallRector::class);
};
69 changes: 69 additions & 0 deletions rules/TYPO312/v0/RemoveAddLLrefForTCAdescrMethodCallRector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

namespace Ssch\TYPO3Rector\TYPO312\v0;

use PhpParser\Node;
use PhpParser\Node\Expr\StaticCall;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;

/**
* @changelog https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.0/Deprecation-97312-DeprecateCSH-relatedMethods.html
* @see \Ssch\TYPO3Rector\Tests\Rector\v12\v0\RemoveAddLLrefForTCAdescrMethodCallRector\RemoveAddLLrefForTCAdescrMethodCallRectorTest
*/
final class RemoveAddLLrefForTCAdescrMethodCallRector extends AbstractRector implements DocumentedRuleInterface
{
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'Remove ExtensionManagementUtility::addLLrefForTCAdescr() method call as it will be removed in TYPO3 v13',
[
new CodeSample(
<<<'CODE_SAMPLE'
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
ExtensionManagementUtility::addLLrefForTCAdescr('_MOD_web_info', 'EXT:info/Resources/Private/Language/locallang_csh_web_info.xlf');
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
CODE_SAMPLE
),

]);
}

/**
* @return array<class-string<Node>>
*/
public function getNodeTypes(): array
{
return [StaticCall::class];
}

/**
* @param StaticCall $node
*/
public function refactor(Node $node): ?Node
{
if (! $node instanceof StaticCall) {
return null;
}

if (! $this->nodeTypeResolver->isMethodStaticCallOrClassMethodObjectType(
$node,
ExtensionManagementUtility::class
)) {
return null;
}

if (! $this->isName($node->name, 'addLLrefForTCAdescr')) {
return null;
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;

defined('TYPO3') or die();

// This call should be removed
ExtensionManagementUtility::addLLrefForTCAdescr('_MOD_web_info', 'EXT:info/Resources/Private/Language/locallang_csh_web_info.xlf');

// This call should also be removed
ExtensionManagementUtility::addLLrefForTCAdescr('tt_content', 'EXT:frontend/Resources/Private/Language/locallang_csh_tt_content.xlf');

// This should remain unchanged
$someOtherCall = ExtensionManagementUtility::isLoaded('info');

?>
-----
<?php

use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;

defined('TYPO3') or die();

// This should remain unchanged
$someOtherCall = ExtensionManagementUtility::isLoaded('info');

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Ssch\TYPO3Rector\Tests\Rector\v12\v0\RemoveAddLLrefForTCAdescrMethodCallRector;

use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class RemoveAddLLrefForTCAdescrMethodCallRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

/**
* @return \Iterator<array<string>>
*/
public static function provideData(): \Iterator
{
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

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\TYPO312\v0\RemoveAddLLrefForTCAdescrMethodCallRector;

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

0 comments on commit d684509

Please sign in to comment.