-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Add RemoveAddLLrefForTCAdescrMethodCallRector
- Loading branch information
Showing
5 changed files
with
140 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
69 changes: 69 additions & 0 deletions
69
rules/TYPO312/v0/RemoveAddLLrefForTCAdescrMethodCallRector.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,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; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
tests/Rector/v12/v0/RemoveAddLLrefForTCAdescrMethodCallRector/Fixture/fixture.php.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,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'); | ||
|
||
?> |
31 changes: 31 additions & 0 deletions
31
...moveAddLLrefForTCAdescrMethodCallRector/RemoveAddLLrefForTCAdescrMethodCallRectorTest.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,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'; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/Rector/v12/v0/RemoveAddLLrefForTCAdescrMethodCallRector/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\TYPO312\v0\RemoveAddLLrefForTCAdescrMethodCallRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->import(__DIR__ . '/../../../../../../config/config_test.php'); | ||
$rectorConfig->rule(RemoveAddLLrefForTCAdescrMethodCallRector::class); | ||
}; |