Skip to content

Commit

Permalink
[TASK] Do not import TYPO3 namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
simonschaufi committed May 16, 2024
1 parent 9cc5740 commit d8a6588
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 30 deletions.
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
StringClassNameToClassConstantRector::class,
__DIR__ . '/src/Set',
UseClassKeywordForClassNameResolutionRector::class => [
__DIR__ . '/rules/TYPO311/v0/ForwardResponseInsteadOfForwardMethodRector.php', // Don't import TYPO3 namespace
__DIR__ . '/rules/TYPO310/v0/UseNativePhpHex2binMethodRector.php', // Don't import TYPO3 namespace
__DIR__ . '/rules/TYPO312/v0/MigrateFetchAllToFetchAllAssociativeRector.php', // Don't replace Doctrine Constants
__DIR__ . '/rules/TYPO312/v0/MigrateFetchToFetchAssociativeRector.php', // Don't replace Doctrine Constants
],
Expand Down
5 changes: 2 additions & 3 deletions rules/TYPO310/v0/UseNativePhpHex2binMethodRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use TYPO3\CMS\Extbase\Utility\TypeHandlingUtility;

/**
* @changelog https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/10.0/Deprecation-87613-DeprecateTYPO3CMSExtbaseUtilityTypeHandlingUtilityhex2bin.html
Expand Down Expand Up @@ -48,10 +47,10 @@ public function refactor(Node $node): ?Node
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'Turns ' . TypeHandlingUtility::class . '::hex2bin calls to native php hex2bin',
'Turns TYPO3\CMS\Extbase\Utility\TypeHandlingUtility::hex2bin calls to native php hex2bin',
[
new CodeSample(
TypeHandlingUtility::class . '::hex2bin("6578616d706c65206865782064617461");',
'TYPO3\CMS\Extbase\Utility\TypeHandlingUtility::hex2bin("6578616d706c65206865782064617461");',
'hex2bin("6578616d706c65206865782064617461");'
),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;

/**
* @changelog https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/11.0/Deprecation-92815-ActionControllerForward.html
Expand All @@ -40,7 +39,7 @@ public function __construct(ValueResolver $valueResolver)
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'Return TYPO3\CMS\Extbase\Http\ForwardResponse instead of ' . ActionController::class . '::forward()',
'Return TYPO3\CMS\Extbase\Http\ForwardResponse instead of TYPO3\CMS\Extbase\Mvc\Controller\ActionController::forward()',
[new CodeSample(
<<<'CODE_SAMPLE'
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
Expand Down
8 changes: 3 additions & 5 deletions rules/TYPO311/v3/MigrateHttpUtilityRedirectRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\HttpUtility;

/**
* @changelog https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/11.3/Deprecation-94316-DeprecatedHTTPHeaderManipulatingMethodsFromHttpUtility.html
Expand Down Expand Up @@ -77,7 +75,7 @@ public function refactor(Node $node): ?array

if (! $this->nodeTypeResolver->isMethodStaticCallOrClassMethodObjectType(
$staticCall,
new ObjectType(HttpUtility::class)
new ObjectType('TYPO3\CMS\Core\Utility\HttpUtility')
)) {
return null;
}
Expand All @@ -88,7 +86,7 @@ public function refactor(Node $node): ?array

$target = $staticCall->args[0];
$httpStatusCode = $staticCall->args[1] ?? $this->nodeFactory->createClassConstFetch(
HttpUtility::class,
'TYPO3\CMS\Core\Utility\HttpUtility',
'HTTP_STATUS_303'
);

Expand Down Expand Up @@ -116,7 +114,7 @@ public function refactor(Node $node): ?array
private function createResponseFactory(): StaticCall
{
return $this->nodeFactory->createStaticCall(
GeneralUtility::class,
'TYPO3\CMS\Core\Utility\GeneralUtility',
'makeInstance',
[$this->nodeFactory->createClassConstReference('Psr\\Http\\Message\\ResponseFactoryInterface')]
);
Expand Down
6 changes: 2 additions & 4 deletions rules/TYPO312/v0/UsePageDoktypeRegistryRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use TYPO3\CMS\Core\DataHandling\PageDoktypeRegistry;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* @changelog https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.0/Breaking-98487-GLOBALSPAGES_TYPESRemoved.html
Expand Down Expand Up @@ -68,8 +66,8 @@ public function refactor(Node $node)
}

return $this->nodeFactory->createMethodCall(
$this->nodeFactory->createStaticCall(GeneralUtility::class, 'makeInstance', [
$this->nodeFactory->createClassConstReference(PageDoktypeRegistry::class),
$this->nodeFactory->createStaticCall('TYPO3\CMS\Core\Utility\GeneralUtility', 'makeInstance', [
$this->nodeFactory->createClassConstReference('TYPO3\CMS\Core\DataHandling\PageDoktypeRegistry'),
]),
'add',
[$node->var->dim, $node->expr]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use TYPO3\CMS\Backend\Utility\BackendUtility;

/**
* @changelog https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.4/Deprecation-100459-BackendUtilitygetRecordToolTip.html
Expand All @@ -38,7 +37,6 @@ public function getRuleDefinition(): RuleDefinition
$link = '<a href="#" title="' . BackendUtility::getRecordIconAltText('tooltip') . '">my link</a>';
CODE_SAMPLE
),

]
);
}
Expand All @@ -59,7 +57,7 @@ public function refactor(Node $node): ?Node

$concatenationWithTitleAttribute = [
new String_('title="'),
$this->nodeFactory->createStaticCall(BackendUtility::class, 'getRecordIconAltText', $node->args),
$this->nodeFactory->createStaticCall('TYPO3\CMS\Backend\Utility\BackendUtility', 'getRecordIconAltText', $node->args),
new String_('"'),
];

Expand Down
3 changes: 1 addition & 2 deletions rules/TYPO313/v0/ChangeSignatureForLastInsertIdRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use TYPO3\CMS\Core\Database\Connection;

/**
* @changelog https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/13.0/Breaking-102875-ChangedConnectionMethodSignaturesAndBehaviour.html
Expand Down Expand Up @@ -59,7 +58,7 @@ public function refactor(Node $node): ?Node

if (! $this->nodeTypeResolver->isMethodStaticCallOrClassMethodObjectType(
$node,
new ObjectType(Connection::class)
new ObjectType('TYPO3\CMS\Core\Database\Connection')
)) {
return null;
}
Expand Down
6 changes: 2 additions & 4 deletions rules/TYPO313/v0/ChangeSignatureOfConnectionQuoteRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Ssch\TYPO3Rector\TYPO313\v0;

use Doctrine\DBAL\Connection;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Cast\String_;
Expand All @@ -13,7 +12,6 @@
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;

/**
* @changelog https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/13.0/Breaking-102875-ChangedConnectionMethodSignaturesAndBehaviour.html
Expand Down Expand Up @@ -56,10 +54,10 @@ public function refactor(Node $node): ?Node
{
if (! $this->nodeTypeResolver->isMethodStaticCallOrClassMethodObjectType(
$node,
new ObjectType(Connection::class)
new ObjectType('Doctrine\DBAL\Connection')
) && ! $this->nodeTypeResolver->isMethodStaticCallOrClassMethodObjectType(
$node,
new ObjectType(QueryBuilder::class)
new ObjectType('TYPO3\CMS\Core\Database\Query\QueryBuilder')
)) {
return null;
}
Expand Down
17 changes: 10 additions & 7 deletions rules/TYPO313/v0/EventListenerConfigurationToAttributeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Ssch\TYPO3Rector\Helper\ServiceDefinitionHelper;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use TYPO3\CMS\Core\Attribute\AsEventListener;

/**
* @changelog https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/13.0/Feature-101544-IntroducePHPAttributeToAutoconfigureEventListeners.html
Expand Down Expand Up @@ -50,8 +49,12 @@ final class EventListenerConfigurationToAttributeRector extends AbstractRector i

private string $eventListenerTagName = 'event.listener';

public function __construct(ReflectionProvider $reflectionProvider, ServiceDefinitionHelper $serviceDefinitionHelper, PhpAttributeGroupFactory $phpAttributeGroupFactory, PhpAttributeAnalyzer $phpAttributeAnalyzer)
{
public function __construct(
ReflectionProvider $reflectionProvider,
ServiceDefinitionHelper $serviceDefinitionHelper,
PhpAttributeGroupFactory $phpAttributeGroupFactory,
PhpAttributeAnalyzer $phpAttributeAnalyzer
) {
$this->reflectionProvider = $reflectionProvider;
$this->serviceDefinitionHelper = $serviceDefinitionHelper;
$this->phpAttributeGroupFactory = $phpAttributeGroupFactory;
Expand Down Expand Up @@ -105,11 +108,11 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
if (! $this->reflectionProvider->hasClass(AsEventListener::class)) {
if (! $this->reflectionProvider->hasClass('TYPO3\CMS\Core\Attribute\AsEventListener')) {
return null;
}

if ($this->phpAttributeAnalyzer->hasPhpAttribute($node, AsEventListener::class)) {
if ($this->phpAttributeAnalyzer->hasPhpAttribute($node, 'TYPO3\CMS\Core\Attribute\AsEventListener')) {
return null;
}

Expand Down Expand Up @@ -151,7 +154,7 @@ private function createAttributeGroupAsEventListener(
?string $method,
?string $event
): AttributeGroup {
$attributeGroup = $this->phpAttributeGroupFactory->createFromClass(AsEventListener::class);
$attributeGroup = $this->phpAttributeGroupFactory->createFromClass('TYPO3\CMS\Core\Attribute\AsEventListener');

$simpleOptions = array_filter([
'before' => $before,
Expand Down Expand Up @@ -180,7 +183,7 @@ private function replaceAsEventListenerAttribute(Class_ $class, AttributeGroup $
$replacedAsEventListenerAttribute = \false;
foreach ($class->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attribute) {
if ($this->nodeNameResolver->isName($attribute->name, AsEventListener::class)) {
if ($this->nodeNameResolver->isName($attribute->name, 'TYPO3\CMS\Core\Attribute\AsEventListener')) {
$hasAsEventListenerAttribute = \true;
$replacedAsEventListenerAttribute = $this->replaceArguments($attribute, $createAttributeGroup);
}
Expand Down

0 comments on commit d8a6588

Please sign in to comment.