Skip to content

Commit 949aa3f

Browse files
committed
tidy up
1 parent 5ea0c40 commit 949aa3f

9 files changed

Lines changed: 27 additions & 26 deletions

File tree

rector.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
'*/Source/*',
2424
'*/Source*/*',
2525
'*/tests/*/Fixture*/Expected/*',
26-
StringClassNameToClassConstantRector::class => [__DIR__ . '/config', __DIR__ . '/src/Enum'],
26+
StringClassNameToClassConstantRector::class => [
27+
__DIR__ . '/config', __DIR__ . '/src/Enum',
28+
__DIR__ . '/rules/CodeQuality/Enum/',
29+
],
2730
UseClassKeywordForClassNameResolutionRector::class => [__DIR__ . '/config'],
2831

2932
RenameForeachValueVariableToMatchMethodCallReturnTypeRector::class => [
@@ -34,19 +37,8 @@
3437
// marked as skipped
3538
ReturnNeverTypeRector::class => ['*/tests/*'],
3639
])
37-
->withConfiguredRule(StringClassNameToClassConstantRector::class, [
38-
'Error',
39-
'Exception',
40-
'Symfony\*',
41-
'Twig_*',
42-
'Twig*',
43-
'Swift_*',
44-
'Doctrine\*',
45-
// loaded from project itself
46-
'Psr\Container\ContainerInterface',
47-
'Symfony\Component\Routing\RouterInterface',
48-
'Symfony\Component\DependencyInjection\Container',
49-
])
40+
// @todo cleanup rest and move to enum classes ass single place for class names
41+
->withConfiguredRule(StringClassNameToClassConstantRector::class, ['Symfony\*', 'Twig_*', 'Twig*'])
5042
->withPhpSets()
5143
->withPreparedSets(
5244
deadCode: true,

rules/CodeQuality/Rector/ClassMethod/RemoveUnusedRequestParamRector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Rector\Rector\AbstractRector;
1818
use Rector\Reflection\ReflectionResolver;
1919
use Rector\Symfony\TypeAnalyzer\ControllerAnalyzer;
20+
use Symplify\PHPStanRules\Enum\SymfonyClass;
2021
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
2122
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
2223

@@ -110,7 +111,7 @@ public function refactor(Node $node): ?Node
110111
continue;
111112
}
112113

113-
if (! $this->isObjectType($param->type, new ObjectType('Symfony\Component\HttpFoundation\Request'))) {
114+
if (! $this->isObjectType($param->type, new ObjectType(SymfonyClass::REQUEST))) {
114115
continue;
115116
}
116117

rules/CodeQuality/Rector/ClassMethod/ResponseReturnTypeControllerActionRector.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Rector\Symfony\CodeQuality\Enum\ResponseClass;
2626
use Rector\Symfony\Enum\SensioAttribute;
2727
use Rector\Symfony\Enum\SymfonyAnnotation;
28+
use Rector\Symfony\Enum\SymfonyClass;
2829
use Rector\Symfony\TypeAnalyzer\ControllerAnalyzer;
2930
use Rector\TypeDeclaration\NodeAnalyzer\ReturnAnalyzer;
3031
use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer;
@@ -125,7 +126,8 @@ public function refactor(Node $node): ?Node
125126

126127
$returnType = $this->returnTypeInferer->inferFunctionLike($node);
127128
$types = $returnType instanceof UnionType ? $returnType->getTypes() : [$returnType];
128-
$objectType = new ObjectType('Symfony\Component\HttpFoundation\Response');
129+
130+
$objectType = new ObjectType(SymfonyClass::RESPONSE);
129131

130132
foreach ($types as $type) {
131133
if ($type instanceof ObjectType && $objectType->isSuperTypeOf($type)->yes()) {

rules/Symfony30/Rector/ClassMethod/GetRequestRector.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Rector\PhpParser\Node\BetterNodeFinder;
1717
use Rector\Rector\AbstractRector;
1818
use Rector\Symfony\Bridge\NodeAnalyzer\ControllerMethodAnalyzer;
19+
use Rector\Symfony\Enum\SymfonyClass;
1920
use Rector\Symfony\TypeAnalyzer\ControllerAnalyzer;
2021
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
2122
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@@ -25,11 +26,6 @@
2526
*/
2627
final class GetRequestRector extends AbstractRector
2728
{
28-
/**
29-
* @var string
30-
*/
31-
private const REQUEST_CLASS = 'Symfony\Component\HttpFoundation\Request';
32-
3329
private ?string $requestVariableAndParamName = null;
3430

3531
public function __construct(
@@ -230,7 +226,7 @@ private function refactorClassMethod(ClassMethod $classMethod): null|ClassMethod
230226
return null;
231227
}
232228

233-
$fullyQualified = new FullyQualified(self::REQUEST_CLASS);
229+
$fullyQualified = new FullyQualified(SymfonyClass::REQUEST);
234230
$classMethod->params[] = new Param(new Variable(
235231
$this->getRequestVariableAndParamName()
236232
), null, $fullyQualified);

rules/Symfony51/Rector/ClassMethod/CommandConstantReturnCodeRector.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Rector\PhpParser\Node\BetterNodeFinder;
1414
use Rector\Rector\AbstractRector;
1515
use Rector\Reflection\ReflectionResolver;
16+
use Rector\Symfony\Enum\SymfonyClass;
1617
use Rector\Symfony\ValueObject\ConstantMap\SymfonyCommandConstantMap;
1718
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1819
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@@ -80,7 +81,7 @@ public function refactor(Node $node): ?Node
8081
return null;
8182
}
8283

83-
if (! $classReflection->is('Symfony\Component\Console\Command\Command')) {
84+
if (! $classReflection->is(SymfonyClass::COMMAND)) {
8485
return null;
8586
}
8687

@@ -121,7 +122,7 @@ private function convertNumberToConstant(Int_ $int): ?ClassConstFetch
121122
}
122123

123124
return $this->nodeFactory->createClassConstFetch(
124-
'Symfony\Component\Console\Command\Command',
125+
SymfonyClass::COMMAND,
125126
SymfonyCommandConstantMap::RETURN_TO_CONST[$int->value]
126127
);
127128
}

rules/Symfony61/Rector/Class_/MagicClosureTwigExtensionToNativeMethodsRector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Rector\NodeCollector\ValueObject\ArrayCallable;
1717
use Rector\PHPStan\ScopeFetcher;
1818
use Rector\Rector\AbstractRector;
19+
use Rector\Symfony\Enum\TwigClass;
1920
use Rector\ValueObject\PhpVersion;
2021
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
2122
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@@ -100,7 +101,7 @@ public function refactor(Node $node): ?Node
100101
{
101102
if (! $this->nodeTypeResolver->isObjectTypes($node, [
102103
new ObjectType('Twig_ExtensionInterface'),
103-
new ObjectType('Twig\Extension\ExtensionInterface'),
104+
new ObjectType(TwigClass::EXTENSION_INTERFACE),
104105
])) {
105106
return null;
106107
}

src/Bridge/Symfony/ContainerServiceProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Rector\Configuration\Option;
88
use Rector\Configuration\Parameter\SimpleParameterProvider;
99
use Rector\Exception\ShouldNotHappenException;
10+
use Rector\Symfony\Enum\SymfonyClass;
1011
use Symfony\Component\DependencyInjection\Container;
1112
use Webmozart\Assert\Assert;
1213

@@ -37,7 +38,7 @@ private function getSymfonyContainer(): object
3738
$container = require $symfonyContainerPhp;
3839

3940
// this allows older Symfony versions, e.g. 2.8 did not have the PSR yet
40-
Assert::isInstanceOf($container, 'Symfony\Component\DependencyInjection\Container');
41+
Assert::isInstanceOf($container, SymfonyClass::CONTAINER);
4142
$this->container = $container;
4243
}
4344

src/Enum/SymfonyClass.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,6 @@ final class SymfonyClass
226226
public const ROUTING_CONFIGURATOR = 'Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator';
227227

228228
public const KERNEL = 'Symfony\Component\HttpKernel\Kernel';
229+
230+
public const CONTAINER = 'Symfony\Component\DependencyInjection\Container';
229231
}

src/Enum/TwigClass.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ final class TwigClass
2020
* @var string
2121
*/
2222
public const AS_TWIG_FUNCTION_ATTRIBUTE = 'Twig\Attribute\AsTwigFunction';
23+
24+
/**
25+
* @var string
26+
*/
27+
public const EXTENSION_INTERFACE = 'Twig\Extension\ExtensionInterface';
2328
}

0 commit comments

Comments
 (0)