Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions config/sets/symfony/composer-based.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Symfony\CodeQuality\Rector\AttributeGroup\SingleConditionSecurityAttributeToIsGrantedRector;
use Rector\Symfony\CodeQuality\Rector\Class_\SplitAndSecurityAttributeToIsGrantedRector;
use Rector\Symfony\Symfony42\Rector\New_\RootNodeTreeBuilderRector;
use Rector\Symfony\Symfony42\Rector\New_\StringToArrayArgumentProcessRector;
use Rector\Symfony\Symfony43\Rector\ClassMethod\EventDispatcherParentConstructRector;
use Rector\Symfony\Symfony43\Rector\MethodCall\MakeDispatchFirstArgumentEventRector;
use Rector\Symfony\Symfony44\Rector\ClassMethod\ConsoleExecuteReturnIntRector;
use Rector\Symfony\Symfony51\Rector\Class_\LogoutHandlerToLogoutEventSubscriberRector;
use Rector\Symfony\Symfony51\Rector\Class_\LogoutSuccessHandlerToLogoutEventSubscriberRector;
use Rector\Symfony\Symfony51\Rector\ClassMethod\CommandConstantReturnCodeRector;
use Rector\Symfony\Symfony52\Rector\MethodCall\DefinitionAliasSetPrivateToSetPublicRector;
use Rector\Symfony\Symfony52\Rector\MethodCall\ReflectionExtractorEnableMagicCallExtractorRector;
use Rector\Symfony\Symfony52\Rector\MethodCall\ValidatorBuilderEnableAnnotationMappingRector;
use Rector\Symfony\Symfony52\Rector\New_\PropertyAccessorCreationBooleanToFlagsRector;
use Rector\Symfony\Symfony52\Rector\StaticCall\BinaryFileResponseCreateToNewInstanceRector;
use Rector\Symfony\Symfony61\Rector\StaticPropertyFetch\ErrorNamesPropertyToConstantRector;
use Rector\Symfony\Symfony62\Rector\Class_\SecurityAttributeToIsGrantedAttributeRector;
use Rector\Symfony\Symfony62\Rector\ClassMethod\ClassMethod\ArgumentValueResolverToValueResolverRector;
use Rector\Symfony\Symfony63\Rector\Class_\ParamAndEnvAttributeRector;
use Rector\Symfony\Symfony63\Rector\Class_\SignalableCommandInterfaceReturnTypeRector;

/**
* Rules bound to the Symfony package version installed in the analysed project,
* as not every attribute, class and method exists in every Symfony version.
*
* Thanks to the composer package constraint, these rules can be registered once here, instead of being
* repeated in every Symfony version set to cover a direct upgrade from an older version.
*/
return static function (RectorConfig $rectorConfig): void {
// each of these rules declares the exact Symfony package and the version its target API was added in,
// @see ComposerPackageConstraintInterface
$rectorConfig->rules([
// symfony/config 4.2
RootNodeTreeBuilderRector::class,

// symfony/process 4.2
StringToArrayArgumentProcessRector::class,

// symfony/event-dispatcher 4.3
MakeDispatchFirstArgumentEventRector::class,
EventDispatcherParentConstructRector::class,

// symfony/console 4.4 and 5.1
ConsoleExecuteReturnIntRector::class,
CommandConstantReturnCodeRector::class,

// symfony/security-http 5.1
LogoutHandlerToLogoutEventSubscriberRector::class,
LogoutSuccessHandlerToLogoutEventSubscriberRector::class,

// symfony/* 5.2
DefinitionAliasSetPrivateToSetPublicRector::class,
ReflectionExtractorEnableMagicCallExtractorRector::class,
ValidatorBuilderEnableAnnotationMappingRector::class,
PropertyAccessorCreationBooleanToFlagsRector::class,
BinaryFileResponseCreateToNewInstanceRector::class,

// symfony/validator 6.1
ErrorNamesPropertyToConstantRector::class,

// attributes added in Symfony 6.2
SecurityAttributeToIsGrantedAttributeRector::class,
SingleConditionSecurityAttributeToIsGrantedRector::class,
SplitAndSecurityAttributeToIsGrantedRector::class,
ArgumentValueResolverToValueResolverRector::class,

// symfony/dependency-injection and symfony/console 6.3
ParamAndEnvAttributeRector::class,
SignalableCommandInterfaceReturnTypeRector::class,
]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Rector\Rector\AbstractRector;
use Rector\Symfony\CodeQuality\NodeAnalyzer\AttributePresenceDetector;
use Rector\Symfony\Enum\SensioAttribute;
use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface;
use Rector\VersionBonding\ValueObject\ComposerPackageConstraint;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand All @@ -22,13 +24,18 @@
*
* @see \Rector\Symfony\Tests\CodeQuality\Rector\AttributeGroup\SingleConditionSecurityAttributeToIsGrantedRector\SingleConditionSecurityAttributeToIsGrantedRectorTest
*/
final class SingleConditionSecurityAttributeToIsGrantedRector extends AbstractRector
final class SingleConditionSecurityAttributeToIsGrantedRector extends AbstractRector implements ComposerPackageConstraintInterface
{
public function __construct(
private readonly AttributePresenceDetector $attributePresenceDetector,
) {
}

public function provideComposerPackageConstraint(): ComposerPackageConstraint
{
return new ComposerPackageConstraint('symfony/security-http', '>=6.2');
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\Rector\AbstractRector;
use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface;
use Rector\VersionBonding\ValueObject\ComposerPackageConstraint;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand All @@ -22,8 +24,13 @@
/**
* @see \Rector\Symfony\Tests\CodeQuality\Rector\Class_\SplitAndSecurityAttributeToIsGrantedRector\SplitAndSecurityAttributeToIsGrantedRectorTest
*/
final class SplitAndSecurityAttributeToIsGrantedRector extends AbstractRector
final class SplitAndSecurityAttributeToIsGrantedRector extends AbstractRector implements ComposerPackageConstraintInterface
{
public function provideComposerPackageConstraint(): ComposerPackageConstraint
{
return new ComposerPackageConstraint('symfony/security-http', '>=6.2');
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
Expand Down
9 changes: 8 additions & 1 deletion rules/Symfony42/Rector/New_/RootNodeTreeBuilderRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Rector\PhpParser\Enum\NodeGroup;
use Rector\PhpParser\Node\BetterNodeFinder;
use Rector\Rector\AbstractRector;
use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface;
use Rector\VersionBonding\ValueObject\ComposerPackageConstraint;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand All @@ -23,13 +25,18 @@
*
* @see \Rector\Symfony\Tests\Symfony42\Rector\New_\RootNodeTreeBuilderRector\RootNodeTreeBuilderRectorTest
*/
final class RootNodeTreeBuilderRector extends AbstractRector
final class RootNodeTreeBuilderRector extends AbstractRector implements ComposerPackageConstraintInterface
{
public function __construct(
private readonly BetterNodeFinder $betterNodeFinder
) {
}

public function provideComposerPackageConstraint(): ComposerPackageConstraint
{
return new ComposerPackageConstraint('symfony/config', '>=4.2');
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use Rector\PhpParser\NodeTransformer;
use Rector\Rector\AbstractRector;
use Rector\Util\Reflection\PrivatesAccessor;
use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface;
use Rector\VersionBonding\ValueObject\ComposerPackageConstraint;
use Symfony\Component\Console\Input\StringInput;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand All @@ -27,7 +29,7 @@
*
* @see \Rector\Symfony\Tests\Symfony42\Rector\New_\StringToArrayArgumentProcessRector\StringToArrayArgumentProcessRectorTest
*/
final class StringToArrayArgumentProcessRector extends AbstractRector
final class StringToArrayArgumentProcessRector extends AbstractRector implements ComposerPackageConstraintInterface
{
/**
* @var string[]
Expand All @@ -44,6 +46,11 @@ public function __construct(
) {
}

public function provideComposerPackageConstraint(): ComposerPackageConstraint
{
return new ComposerPackageConstraint('symfony/process', '>=4.2');
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,26 @@
use Rector\PHPStan\ScopeFetcher;
use Rector\Rector\AbstractRector;
use Rector\ValueObject\MethodName;
use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface;
use Rector\VersionBonding\ValueObject\ComposerPackageConstraint;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

/**
* @see \Rector\Symfony\Tests\Symfony43\Rector\ClassMethod\EventDispatcherParentConstructRector\EventDispatcherParentConstructRectorTest
*/
final class EventDispatcherParentConstructRector extends AbstractRector
final class EventDispatcherParentConstructRector extends AbstractRector implements ComposerPackageConstraintInterface
{
public function __construct(
private readonly BetterNodeFinder $betterNodeFinder
) {
}

public function provideComposerPackageConstraint(): ComposerPackageConstraint
{
return new ComposerPackageConstraint('symfony/event-dispatcher', '>=4.3');
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Rector\NodeTypeResolver\TypeAnalyzer\StringTypeAnalyzer;
use Rector\PhpParser\Node\Value\ValueResolver;
use Rector\Rector\AbstractRector;
use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface;
use Rector\VersionBonding\ValueObject\ComposerPackageConstraint;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand All @@ -22,14 +24,19 @@
*
* @see \Rector\Symfony\Tests\Symfony43\Rector\MethodCall\MakeDispatchFirstArgumentEventRector\MakeDispatchFirstArgumentEventRectorTest
*/
final class MakeDispatchFirstArgumentEventRector extends AbstractRector
final class MakeDispatchFirstArgumentEventRector extends AbstractRector implements ComposerPackageConstraintInterface
{
public function __construct(
private readonly StringTypeAnalyzer $stringTypeAnalyzer,
private readonly ValueResolver $valueResolver
) {
}

public function provideComposerPackageConstraint(): ComposerPackageConstraint
{
return new ComposerPackageConstraint('symfony/event-dispatcher', '>=4.3');
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
use Rector\NodeAnalyzer\TerminatedNodeAnalyzer;
use Rector\PhpParser\Node\Value\ValueResolver;
use Rector\Rector\AbstractRector;
use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface;
use Rector\VersionBonding\ValueObject\ComposerPackageConstraint;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

/**
* @changelog https://github.com/symfony/symfony/pull/33775/files
* @see \Rector\Symfony\Tests\Symfony44\Rector\ClassMethod\ConsoleExecuteReturnIntRector\ConsoleExecuteReturnIntRectorTest
*/
final class ConsoleExecuteReturnIntRector extends AbstractRector
final class ConsoleExecuteReturnIntRector extends AbstractRector implements ComposerPackageConstraintInterface
{
private bool $hasChanged = false;

Expand All @@ -37,6 +39,11 @@ public function __construct(
) {
}

public function provideComposerPackageConstraint(): ComposerPackageConstraint
{
return new ComposerPackageConstraint('symfony/console', '>=4.4');
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Returns int from Command::execute() command', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Rector\Reflection\ReflectionResolver;
use Rector\Symfony\Enum\SymfonyClass;
use Rector\Symfony\ValueObject\ConstantMap\SymfonyCommandConstantMap;
use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface;
use Rector\VersionBonding\ValueObject\ComposerPackageConstraint;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand All @@ -23,14 +25,19 @@
*
* @see \Rector\Symfony\Tests\Symfony51\Rector\ClassMethod\CommandConstantReturnCodeRector\CommandConstantReturnCodeRectorTest
*/
final class CommandConstantReturnCodeRector extends AbstractRector
final class CommandConstantReturnCodeRector extends AbstractRector implements ComposerPackageConstraintInterface
{
public function __construct(
private readonly ReflectionResolver $reflectionResolver,
private readonly BetterNodeFinder $betterNodeFinder,
) {
}

public function provideComposerPackageConstraint(): ComposerPackageConstraint
{
return new ComposerPackageConstraint('symfony/console', '>=5.1');
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Rector\Symfony\NodeFactory\GetSubscribedEventsClassMethodFactory;
use Rector\Symfony\NodeFactory\OnLogoutClassMethodFactory;
use Rector\Symfony\ValueObject\EventReferenceToMethodName;
use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface;
use Rector\VersionBonding\ValueObject\ComposerPackageConstraint;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand All @@ -22,7 +24,7 @@
*
* @see \Rector\Symfony\Tests\Symfony51\Rector\Class_\LogoutHandlerToLogoutEventSubscriberRector\LogoutHandlerToLogoutEventSubscriberRectorTest
*/
final class LogoutHandlerToLogoutEventSubscriberRector extends AbstractRector
final class LogoutHandlerToLogoutEventSubscriberRector extends AbstractRector implements ComposerPackageConstraintInterface
{
private readonly ObjectType $logoutHandlerObjectType;

Expand All @@ -33,6 +35,11 @@ public function __construct(
$this->logoutHandlerObjectType = new ObjectType(SymfonyClass::LOGOUT_HANDLER_INTERFACE);
}

public function provideComposerPackageConstraint(): ComposerPackageConstraint
{
return new ComposerPackageConstraint('symfony/security-http', '>=5.1');
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Change logout handler to an event listener that listens to LogoutEvent', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Rector\Symfony\NodeFactory\GetSubscribedEventsClassMethodFactory;
use Rector\Symfony\NodeFactory\OnSuccessLogoutClassMethodFactory;
use Rector\Symfony\ValueObject\EventReferenceToMethodNameWithPriority;
use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface;
use Rector\VersionBonding\ValueObject\ComposerPackageConstraint;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand All @@ -23,7 +25,7 @@
*
* @see \Rector\Symfony\Tests\Symfony51\Rector\Class_\LogoutSuccessHandlerToLogoutEventSubscriberRector\LogoutSuccessHandlerToLogoutEventSubscriberRectorTest
*/
final class LogoutSuccessHandlerToLogoutEventSubscriberRector extends AbstractRector
final class LogoutSuccessHandlerToLogoutEventSubscriberRector extends AbstractRector implements ComposerPackageConstraintInterface
{
private readonly ObjectType $successHandlerObjectType;

Expand All @@ -35,6 +37,11 @@ public function __construct(
$this->successHandlerObjectType = new ObjectType(SymfonyClass::LOGOUT_SUCCESS_HANDLER);
}

public function provideComposerPackageConstraint(): ComposerPackageConstraint
{
return new ComposerPackageConstraint('symfony/security-http', '>=5.1');
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Change logout success handler to an event listener that listens to LogoutEvent', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
use PHPStan\Type\ObjectType;
use Rector\PhpParser\Node\Value\ValueResolver;
use Rector\Rector\AbstractRector;
use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface;
use Rector\VersionBonding\ValueObject\ComposerPackageConstraint;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

/**
* @changelog https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#dependencyinjection
* @see \Rector\Symfony\Tests\Symfony52\Rector\MethodCall\DefinitionAliasSetPrivateToSetPublicRector\DefinitionAliasSetPrivateToSetPublicRectorTest
*/
final class DefinitionAliasSetPrivateToSetPublicRector extends AbstractRector
final class DefinitionAliasSetPrivateToSetPublicRector extends AbstractRector implements ComposerPackageConstraintInterface
{
/**
* @var ObjectType[]
Expand All @@ -34,6 +36,11 @@ public function __construct(
];
}

public function provideComposerPackageConstraint(): ComposerPackageConstraint
{
return new ComposerPackageConstraint('symfony/dependency-injection', '>=5.2');
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
Expand Down
Loading
Loading