diff --git a/config/sets/symfony/symfony5/symfony52.php b/config/sets/symfony/symfony5/symfony52.php index 3fd7ea046..8571b4c9d 100644 --- a/config/sets/symfony/symfony5/symfony52.php +++ b/config/sets/symfony/symfony5/symfony52.php @@ -2,171 +2,23 @@ declare(strict_types=1); -use PHPStan\Type\ObjectType; use Rector\Config\RectorConfig; -use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector; -use Rector\Renaming\Rector\MethodCall\RenameMethodRector; -use Rector\Renaming\Rector\PropertyFetch\RenamePropertyRector; -use Rector\Renaming\ValueObject\MethodCallRename; -use Rector\Renaming\ValueObject\RenameClassAndConstFetch; -use Rector\Renaming\ValueObject\RenameProperty; use Rector\Symfony\Set\SymfonySetList; -use Rector\Symfony\Symfony52\Rector\MethodCall\DefinitionAliasSetPrivateToSetPublicRector; -use Rector\Symfony\Symfony52\Rector\MethodCall\FormBuilderSetDataMapperRector; -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\New_\PropertyPathMapperToDataMapperRector; -use Rector\Symfony\Symfony52\Rector\StaticCall\BinaryFileResponseCreateToNewInstanceRector; -use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector; -use Rector\TypeDeclaration\ValueObject\AddParamTypeDeclaration; # https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md return static function (RectorConfig $rectorConfig): void { - $rectorConfig->sets([SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES]); + // $rectorConfig->sets([SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES]); + + $rectorConfig->import(__DIR__ . '/symfony52/symfony52-dependency-injection.php'); + $rectorConfig->import(__DIR__ . '/symfony52/symfony52-forms.php'); + $rectorConfig->import(__DIR__ . '/symfony52/symfony52-http-foundation.php'); + $rectorConfig->import(__DIR__ . '/symfony52/symfony52-mime.php'); + $rectorConfig->import(__DIR__ . '/symfony52/symfony52-notifier.php'); + $rectorConfig->import(__DIR__ . '/symfony52/symfony52-property-access.php'); + $rectorConfig->import(__DIR__ . '/symfony52/symfony52-property-info.php'); + $rectorConfig->import(__DIR__ . '/symfony52/symfony52-security-core.php'); + $rectorConfig->import(__DIR__ . '/symfony52/symfony52-security-http.php'); + $rectorConfig->import(__DIR__ . '/symfony52/symfony52-validator.php'); - $rectorConfig->rules([ - // https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#form - PropertyPathMapperToDataMapperRector::class, - - // https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#httpfoundation - BinaryFileResponseCreateToNewInstanceRector::class, - - // https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#propertyaccess - PropertyAccessorCreationBooleanToFlagsRector::class, - - // https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#propertyinfo - ReflectionExtractorEnableMagicCallExtractorRector::class, - - # https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#dependencyinjection - DefinitionAliasSetPrivateToSetPublicRector::class, - - # https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#form - FormBuilderSetDataMapperRector::class, - - # https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#validator - ValidatorBuilderEnableAnnotationMappingRector::class, - ]); - - # https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#security - $rectorConfig->ruleWithConfiguration(RenameClassConstFetchRector::class, [ - new RenameClassAndConstFetch( - 'Symfony\Component\Security\Http\Firewall\AccessListener', - 'PUBLIC_ACCESS', - 'Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter', - 'PUBLIC_ACCESS' - ), - ]); - - $rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [ - # https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#mime - new MethodCallRename('Symfony\Component\Mime\Address', 'fromString', 'create'), - - new MethodCallRename( - 'Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken', - 'setProviderKey', - 'setFirewallName' - ), - new MethodCallRename( - 'Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken', - 'getProviderKey', - 'getFirewallName' - ), - new MethodCallRename( - 'Symfony\Component\Security\Core\Authentication\Token\RememberMeToken', - 'setProviderKey', - 'setFirewallName' - ), - new MethodCallRename( - 'Symfony\Component\Security\Core\Authentication\Token\RememberMeToken', - 'getProviderKey', - 'getFirewallName' - ), - new MethodCallRename( - 'Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken', - 'setProviderKey', - 'setFirewallName' - ), - new MethodCallRename( - 'Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken', - 'getProviderKey', - 'getFirewallName' - ), - new MethodCallRename( - 'Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', - 'setProviderKey', - 'setFirewallName' - ), - new MethodCallRename( - 'Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', - 'getProviderKey', - 'getFirewallName' - ), - new MethodCallRename( - 'Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler', - 'setProviderKey', - 'setFirewallName' - ), - new MethodCallRename( - 'Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler', - 'getProviderKey', - 'getFirewallName' - ), - ]); - - # https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#notifier - $rectorConfig->ruleWithConfiguration(AddParamTypeDeclarationRector::class, [ - new AddParamTypeDeclaration( - 'Symfony\Component\Notifier\NotifierInterface', - 'send', - 1, - new ObjectType('Symfony\Component\Notifier\Recipient\RecipientInterface') - ), - new AddParamTypeDeclaration( - 'Symfony\Component\Notifier\Notifier', - 'getChannels', - 1, - new ObjectType('Symfony\Component\Notifier\Recipient\RecipientInterface') - ), - new AddParamTypeDeclaration( - 'Symfony\Component\Notifier\Channel\ChannelInterface', - 'notify', - 1, - new ObjectType('Symfony\Component\Notifier\Recipient\RecipientInterface') - ), - new AddParamTypeDeclaration( - 'Symfony\Component\Notifier\Channel\ChannelInterface', - 'supports', - 1, - new ObjectType('Symfony\Component\Notifier\Recipient\RecipientInterface') - ), - new AddParamTypeDeclaration( - 'Symfony\Component\Notifier\Notification\ChatNotificationInterface', - 'asChatMessage', - 0, - new ObjectType('Symfony\Component\Notifier\Recipient\RecipientInterface') - ), - new AddParamTypeDeclaration( - 'Symfony\Component\Notifier\Notification\EmailNotificationInterface', - 'asEmailMessage', - 0, - new ObjectType('Symfony\Component\Notifier\Recipient\EmailRecipientInterface') - ), - new AddParamTypeDeclaration( - 'Symfony\Component\Notifier\Notification\SmsNotificationInterface', - 'asSmsMessage', - 0, - new ObjectType('Symfony\Component\Notifier\Recipient\SmsRecipientInterface') - ), - ]); - - # https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#security - $rectorConfig->ruleWithConfiguration(RenamePropertyRector::class, [ - new RenameProperty( - 'Symfony\Component\Security\Http\RememberMe\AbstractRememberMeServices', - 'providerKey', - 'firewallName' - ), - ]); }; diff --git a/config/sets/symfony/symfony5/symfony52/symfony52-dependency-injection.php b/config/sets/symfony/symfony5/symfony52/symfony52-dependency-injection.php new file mode 100644 index 000000000..3cd62181a --- /dev/null +++ b/config/sets/symfony/symfony5/symfony52/symfony52-dependency-injection.php @@ -0,0 +1,13 @@ +rules([ + # https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#dependencyinjection + DefinitionAliasSetPrivateToSetPublicRector::class, + ]); +}; diff --git a/config/sets/symfony/symfony5/symfony52/symfony52-forms.php b/config/sets/symfony/symfony5/symfony52/symfony52-forms.php new file mode 100644 index 000000000..bd8549294 --- /dev/null +++ b/config/sets/symfony/symfony5/symfony52/symfony52-forms.php @@ -0,0 +1,12 @@ +rules([PropertyPathMapperToDataMapperRector::class, FormBuilderSetDataMapperRector::class]); +}; diff --git a/config/sets/symfony/symfony5/symfony52/symfony52-http-foundation.php b/config/sets/symfony/symfony5/symfony52/symfony52-http-foundation.php new file mode 100644 index 000000000..26029db43 --- /dev/null +++ b/config/sets/symfony/symfony5/symfony52/symfony52-http-foundation.php @@ -0,0 +1,13 @@ +rules([ + // https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#httpfoundation + BinaryFileResponseCreateToNewInstanceRector::class, + ]); +}; diff --git a/config/sets/symfony/symfony5/symfony52/symfony52-mime.php b/config/sets/symfony/symfony5/symfony52/symfony52-mime.php new file mode 100644 index 000000000..5cea71101 --- /dev/null +++ b/config/sets/symfony/symfony5/symfony52/symfony52-mime.php @@ -0,0 +1,16 @@ +ruleWithConfiguration(RenameMethodRector::class, [ + # https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#mime + new MethodCallRename('Symfony\Component\Mime\Address', 'fromString', 'create'), + ]); +}; diff --git a/config/sets/symfony/symfony5/symfony52/symfony52-notifier.php b/config/sets/symfony/symfony5/symfony52/symfony52-notifier.php new file mode 100644 index 000000000..cbba35ebb --- /dev/null +++ b/config/sets/symfony/symfony5/symfony52/symfony52-notifier.php @@ -0,0 +1,56 @@ +ruleWithConfiguration(AddParamTypeDeclarationRector::class, [ + new AddParamTypeDeclaration( + 'Symfony\Component\Notifier\NotifierInterface', + 'send', + 1, + new ObjectType('Symfony\Component\Notifier\Recipient\RecipientInterface') + ), + new AddParamTypeDeclaration( + 'Symfony\Component\Notifier\Notifier', + 'getChannels', + 1, + new ObjectType('Symfony\Component\Notifier\Recipient\RecipientInterface') + ), + new AddParamTypeDeclaration( + 'Symfony\Component\Notifier\Channel\ChannelInterface', + 'notify', + 1, + new ObjectType('Symfony\Component\Notifier\Recipient\RecipientInterface') + ), + new AddParamTypeDeclaration( + 'Symfony\Component\Notifier\Channel\ChannelInterface', + 'supports', + 1, + new ObjectType('Symfony\Component\Notifier\Recipient\RecipientInterface') + ), + new AddParamTypeDeclaration( + 'Symfony\Component\Notifier\Notification\ChatNotificationInterface', + 'asChatMessage', + 0, + new ObjectType('Symfony\Component\Notifier\Recipient\RecipientInterface') + ), + new AddParamTypeDeclaration( + 'Symfony\Component\Notifier\Notification\EmailNotificationInterface', + 'asEmailMessage', + 0, + new ObjectType('Symfony\Component\Notifier\Recipient\EmailRecipientInterface') + ), + new AddParamTypeDeclaration( + 'Symfony\Component\Notifier\Notification\SmsNotificationInterface', + 'asSmsMessage', + 0, + new ObjectType('Symfony\Component\Notifier\Recipient\SmsRecipientInterface') + ), + ]); +}; diff --git a/config/sets/symfony/symfony5/symfony52/symfony52-property-access.php b/config/sets/symfony/symfony5/symfony52/symfony52-property-access.php new file mode 100644 index 000000000..d4d50c694 --- /dev/null +++ b/config/sets/symfony/symfony5/symfony52/symfony52-property-access.php @@ -0,0 +1,13 @@ +rules([ + // https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#propertyaccess + PropertyAccessorCreationBooleanToFlagsRector::class, + ]); +}; diff --git a/config/sets/symfony/symfony5/symfony52/symfony52-property-info.php b/config/sets/symfony/symfony5/symfony52/symfony52-property-info.php new file mode 100644 index 000000000..11f3c5645 --- /dev/null +++ b/config/sets/symfony/symfony5/symfony52/symfony52-property-info.php @@ -0,0 +1,13 @@ +rules([ + // https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#propertyinfo + ReflectionExtractorEnableMagicCallExtractorRector::class, + ]); +}; diff --git a/config/sets/symfony/symfony5/symfony52/symfony52-security-core.php b/config/sets/symfony/symfony5/symfony52/symfony52-security-core.php new file mode 100644 index 000000000..82a2c9fa7 --- /dev/null +++ b/config/sets/symfony/symfony5/symfony52/symfony52-security-core.php @@ -0,0 +1,53 @@ +ruleWithConfiguration(RenameMethodRector::class, [ + new MethodCallRename( + 'Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken', + 'setProviderKey', + 'setFirewallName' + ), + new MethodCallRename( + 'Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken', + 'getProviderKey', + 'getFirewallName' + ), + new MethodCallRename( + 'Symfony\Component\Security\Core\Authentication\Token\RememberMeToken', + 'setProviderKey', + 'setFirewallName' + ), + new MethodCallRename( + 'Symfony\Component\Security\Core\Authentication\Token\RememberMeToken', + 'getProviderKey', + 'getFirewallName' + ), + new MethodCallRename( + 'Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken', + 'setProviderKey', + 'setFirewallName' + ), + new MethodCallRename( + 'Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken', + 'getProviderKey', + 'getFirewallName' + ), + new MethodCallRename( + 'Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', + 'setProviderKey', + 'setFirewallName' + ), + new MethodCallRename( + 'Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', + 'getProviderKey', + 'getFirewallName' + ), + ]); + +}; diff --git a/config/sets/symfony/symfony5/symfony52/symfony52-security-http.php b/config/sets/symfony/symfony5/symfony52/symfony52-security-http.php new file mode 100644 index 000000000..941013328 --- /dev/null +++ b/config/sets/symfony/symfony5/symfony52/symfony52-security-http.php @@ -0,0 +1,45 @@ +ruleWithConfiguration(RenameClassConstFetchRector::class, [ + new RenameClassAndConstFetch( + 'Symfony\Component\Security\Http\Firewall\AccessListener', + 'PUBLIC_ACCESS', + 'Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter', + 'PUBLIC_ACCESS' + ), + ]); + + # https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#security + $rectorConfig->ruleWithConfiguration(RenamePropertyRector::class, [ + new RenameProperty( + 'Symfony\Component\Security\Http\RememberMe\AbstractRememberMeServices', + 'providerKey', + 'firewallName' + ), + ]); + + $rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [ + new MethodCallRename( + 'Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler', + 'setProviderKey', + 'setFirewallName' + ), + new MethodCallRename( + 'Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler', + 'getProviderKey', + 'getFirewallName' + ), + ]); +}; diff --git a/config/sets/symfony/symfony5/symfony52/symfony52-validator.php b/config/sets/symfony/symfony5/symfony52/symfony52-validator.php new file mode 100644 index 000000000..88120808f --- /dev/null +++ b/config/sets/symfony/symfony5/symfony52/symfony52-validator.php @@ -0,0 +1,13 @@ +rules([ + # https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#validator + ValidatorBuilderEnableAnnotationMappingRector::class, + ]); +}; diff --git a/rules/Symfony52/Rector/New_/PropertyAccessorCreationBooleanToFlagsRector.php b/rules/Symfony52/Rector/New_/PropertyAccessorCreationBooleanToFlagsRector.php index 71451c89a..3e656cd3d 100644 --- a/rules/Symfony52/Rector/New_/PropertyAccessorCreationBooleanToFlagsRector.php +++ b/rules/Symfony52/Rector/New_/PropertyAccessorCreationBooleanToFlagsRector.php @@ -31,6 +31,8 @@ public function getRuleDefinition(): RuleDefinition return new RuleDefinition('Changes first argument of PropertyAccessor::__construct() to flags from boolean', [ new CodeSample( <<<'CODE_SAMPLE' +use Symfony\Component\PropertyAccess\PropertyAccessor; + class SomeClass { public function run() @@ -41,6 +43,8 @@ public function run() CODE_SAMPLE , <<<'CODE_SAMPLE' +use Symfony\Component\PropertyAccess\PropertyAccessor; + class SomeClass { public function run() diff --git a/src/Set/SetProvider/Symfony5SetProvider.php b/src/Set/SetProvider/Symfony5SetProvider.php index 20956163f..53085b808 100644 --- a/src/Set/SetProvider/Symfony5SetProvider.php +++ b/src/Set/SetProvider/Symfony5SetProvider.php @@ -127,10 +127,72 @@ public function provide(): array new ComposerTriggeredSet( SetGroup::SYMFONY, - 'symfony/*', + 'symfony/symfony', '5.2', __DIR__ . '/../../../config/sets/symfony/symfony5/symfony52.php' ), + + new ComposerTriggeredSet( + SetGroup::SYMFONY, + 'symfony/dependency-injection', + '5.2', + __DIR__ . '/../../../config/sets/symfony/symfony5/symfony52/symfony52-dependency-injection.php', + ), + new ComposerTriggeredSet( + SetGroup::SYMFONY, + 'symfony/forms', + '5.2', + __DIR__ . '/../../../config/sets/symfony/symfony5/symfony52/symfony52-forms.php', + ), + new ComposerTriggeredSet( + SetGroup::SYMFONY, + 'symfony/http-foundation', + '5.2', + __DIR__ . '/../../../config/sets/symfony/symfony5/symfony52/symfony52-http-foundation.php', + ), + new ComposerTriggeredSet( + SetGroup::SYMFONY, + 'symfony/mime', + '5.2', + __DIR__ . '/../../../config/sets/symfony/symfony5/symfony52/symfony52-mime.php', + ), + new ComposerTriggeredSet( + SetGroup::SYMFONY, + 'symfony/notifier', + '5.2', + __DIR__ . '/../../../config/sets/symfony/symfony5/symfony52/symfony52-notifier.php', + ), + new ComposerTriggeredSet( + SetGroup::SYMFONY, + 'symfony/property-access', + '5.2', + __DIR__ . '/../../../config/sets/symfony/symfony5/symfony52/symfony52-property-access.php', + ), + new ComposerTriggeredSet( + SetGroup::SYMFONY, + 'symfony/property-info', + '5.2', + __DIR__ . '/../../../config/sets/symfony/symfony5/symfony52/symfony52-property-info.php', + ), + new ComposerTriggeredSet( + SetGroup::SYMFONY, + 'symfony/security-core', + '5.2', + __DIR__ . '/../../../config/sets/symfony/symfony5/symfony52/symfony52-security-core.php', + ), + new ComposerTriggeredSet( + SetGroup::SYMFONY, + 'symfony/security-http', + '5.2', + __DIR__ . '/../../../config/sets/symfony/symfony5/symfony52/symfony52-security-http.php', + ), + new ComposerTriggeredSet( + SetGroup::SYMFONY, + 'symfony/validator', + '5.2', + __DIR__ . '/../../../config/sets/symfony/symfony5/symfony52/symfony52-validator.php', + ), + new ComposerTriggeredSet( SetGroup::SYMFONY, 'symfony/*',