Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend Symfony 5.3, 5.4 and 6.0 sets #89

Merged
merged 2 commits into from
Dec 9, 2021
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
2 changes: 2 additions & 0 deletions config/sets/symfony/level/up-to-symfony-53.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
declare(strict_types=1);

use Rector\Symfony\Set\SymfonyLevelSetList;
use Rector\Symfony\Set\SymfonySetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(SymfonySetList::SYMFONY_53);
$containerConfigurator->import(SymfonyLevelSetList::UP_TO_SYMFONY_52);
};
2 changes: 2 additions & 0 deletions config/sets/symfony/level/up-to-symfony-60.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
declare(strict_types=1);

use Rector\Symfony\Set\SymfonyLevelSetList;
use Rector\Symfony\Set\SymfonySetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(SymfonySetList::SYMFONY_60);
$containerConfigurator->import(SymfonyLevelSetList::UP_TO_SYMFONY_54);
};
109 changes: 109 additions & 0 deletions config/sets/symfony/symfony53.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

declare(strict_types=1);

use PHPStan\Type\StringType;
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\RenameClassConstFetch;
use Rector\Symfony\Set\SymfonySetList;
use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddReturnTypeDeclaration;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

# https://github.com/symfony/symfony/blob/5.4/UPGRADE-5.3.md

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES);

$services = $containerConfigurator->services();
$services->set(RenameMethodRector::class)
->configure([
// @see https://github.com/symfony/symfony/pull/40536
new MethodCallRename(
'Symfony\Component\HttpFoundation\RequestStack',
'getMasterRequest',
'getMainRequest',
),
new MethodCallRename('Symfony\Component\Console\Helper\Helper', 'strlen', 'width',),
new MethodCallRename(
'Symfony\Component\Console\Helper\Helper',
'strlenWithoutDecoration',
'removeDecoration',
),
new MethodCallRename(
'\Symfony\Component\HttpKernel\Event\KernelEvent',
'isMasterRequest',
'isMainRequest',
),
new MethodCallRename(
'Symfony\Component\Security\Core\User\UserInterface',
'getUsername',
'getUserIdentifier',
),
new MethodCallRename(
'Symfony\Component\Security\Core\Authentication\Token\TokenInterface',
'getUsername',
'getUserIdentifier',
),
new MethodCallRename(
'Symfony\Component\Security\Core\User\UserProviderInterface',
'loadUserByUsername',
'loadUserByIdentifier',
),
new MethodCallRename(
'Symfony\Component\Security\Core\Exception\UsernameNotFoundException',
'getUsername',
'getUserIdentifier'
),
new MethodCallRename(
'Symfony\Component\Security\Core\Exception\UsernameNotFoundException',
'setUsername',
'setUserIdentifier'
),
new MethodCallRename(
'Symfony\Component\Security\Core\Authentication\RememberMe\PersistentTokenInterface',
'getUsername',
'getUserIdentifier'
),
]);

$services->set(RenameClassRector::class)
->configure([
'Symfony\Component\Security\Core\Exception\UsernameNotFoundException' => 'Symfony\Component\Security\Core\Exception\UserNotFoundException',
// @see https://github.com/symfony/symfony/pull/39802
'Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface' => 'Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface',
'Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder' => 'Symfony\Component\PasswordHasher\Hasher\MessageDigestPasswordHasher',
'Symfony\Component\Security\Core\Encoder\MigratingPasswordEncoder' => 'Symfony\Component\PasswordHasher\Hasher\MigratingPasswordHasher',
'Symfony\Component\Security\Core\Encoder\NativePasswordEncoder' => 'Symfony\Component\PasswordHasher\Hasher\NativePasswordHasher',
'Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface' => 'Symfony\Component\PasswordHasher\PasswordHasherInterface',
'Symfony\Component\Security\Core\Encoder\Pbkdf2PasswordEncoder' => 'Symfony\Component\PasswordHasher\Hasher\Pbkdf2PasswordHasher',
'Symfony\Component\Security\Core\Encoder\PlaintextPasswordEncoder' => 'Symfony\Component\PasswordHasher\Hasher\PlaintextPasswordHasher',
'Symfony\Component\Security\Core\Encoder\SelfSaltingEncoderInterface' => 'Symfony\Component\PasswordHasher\LegacyPasswordHasherInterface',
'Symfony\Component\Security\Core\Encoder\SodiumPasswordEncoder' => 'Symfony\Component\PasswordHasher\Hasher\SodiumPasswordHasher',
'Symfony\Component\Security\Core\Encoder\UserPasswordEncoder' => 'Symfony\Component\PasswordHasher\Hasher\UserPasswordHasher',
'Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface' => 'Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface',
]);

$services->set(AddReturnTypeDeclarationRector::class)
->configure([
new AddReturnTypeDeclaration(
'Symfony\Component\Mailer\Transport\AbstractTransportFactory',
'getEndpoint',
new StringType(),
),
]);

// rename constant
$services->set(RenameClassConstFetchRector::class)
->configure([
// @see https://github.com/symfony/symfony/pull/40536
new RenameClassConstFetch(
'Symfony\Component\HttpKernel\HttpKernelInterface',
'MASTER_REQUEST',
'MAIN_REQUEST'
),
]);
};
50 changes: 50 additions & 0 deletions config/sets/symfony/symfony54.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

use Rector\Php80\Rector\Class_\AnnotationToAttributeRector;
use Rector\Php80\ValueObject\AnnotationToAttribute;
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\RenameClassAndConstFetch;
use Rector\Renaming\ValueObject\RenameClassConstFetch;
use Rector\Symfony\Set\SymfonySetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

Expand All @@ -23,4 +29,48 @@
new AnnotationToAttribute('Symfony\Component\Validator\Constraints\AtLeastOneOf'),
new AnnotationToAttribute('Symfony\Component\Validator\Constraints\Sequentially'),
]);

$services = $containerConfigurator->services();
$services->set(RenameMethodRector::class)
->configure([
// @see https://github.com/symfony/symfony/pull/42582
new MethodCallRename(
'Symfony\Bundle\SecurityBundle\Security\FirewallConfig',
'getListeners',
'getAuthenticators'
),
]);

$services->set(RenameClassConstFetchRector::class)
->configure([
new RenameClassAndConstFetch(
'Symfony\Component\Security\Core\AuthenticationEvents',
'AUTHENTICATION_SUCCESS',
'Symfony\Component\Security\Core\Event\AuthenticationSuccessEvent',
'class'
),
new RenameClassAndConstFetch(
'Symfony\Component\Security\Core\AuthenticationEvents',
'AUTHENTICATION_FAILURE',
'Symfony\Component\Security\Core\Event\AuthenticationFailureEvent',
'class'
),
// @see https://github.com/symfony/symfony/pull/42510
new RenameClassConstFetch(
'Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter',
'IS_ANONYMOUS',
'PUBLIC_ACCESS'
),
new RenameClassConstFetch(
'Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter',
'IS_AUTHENTICATED_ANONYMOUSLY',
'PUBLIC_ACCESS'
),
]);

$services->set(RenameClassRector::class)
->configure([
// @see https://github.com/symfony/symfony/pull/42050
'Symfony\Component\Security\Http\Event\DeauthenticatedEvent' => 'Symfony\Component\Security\Http\Event\TokenDeauthenticatedEvent',
]);
};
5 changes: 5 additions & 0 deletions config/sets/symfony/symfony6/symfony-return-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,5 +575,10 @@
'normalize',
new UnionType([...$scalarTypes, new ObjectType('ArrayObject')])
),
new AddReturnTypeDeclaration(
'Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface',
'authenticate',
new ObjectType('Symfony\Component\Security\Http\Authenticator\Passport\Passport')
),
]);
};
19 changes: 19 additions & 0 deletions config/sets/symfony/symfony60.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use PhpParser\Node\Scalar\String_;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Symfony\Rector\FuncCall\ReplaceServiceArgumentRector;
use Rector\Symfony\Set\SymfonySetList;
use Rector\Symfony\ValueObject\ReplaceServiceArgument;
Expand All @@ -29,6 +32,12 @@
),
]);

$services->set(RenameClassRector::class)
->configure([
// @see https://github.com/symfony/symfony/pull/39484
'Symfony\Contracts\HttpClient\HttpClientInterface\RemoteJsonManifestVersionStrategy' => 'Symfony\Component\Asset\VersionStrategy\JsonManifestVersionStrategy',
]);

$services->set(AddParamTypeDeclarationRector::class)
->configure([
new AddParamTypeDeclaration(
Expand All @@ -44,4 +53,14 @@
new ObjectType('Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator'),
),
]);

$services->set(RenameMethodRector::class)
->configure([
// @see https://github.com/symfony/symfony/pull/40403
new MethodCallRename(
'Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface',
'loadUserByUsername',
'loadUserByIdentifier'
),
]);
};
10 changes: 10 additions & 0 deletions src/Set/SymfonySetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ final class SymfonySetList implements SetListInterface
*/
public const SYMFONY_52 = __DIR__ . '/../../config/sets/symfony/symfony52.php';

/**
* @var string
*/
public const SYMFONY_53 = __DIR__ . '/../../config/sets/symfony/symfony53.php';

/**
* @var string
*/
Expand All @@ -98,6 +103,11 @@ final class SymfonySetList implements SetListInterface
*/
public const SYMFONY_52_VALIDATOR_ATTRIBUTES = __DIR__ . '/../../config/sets/symfony/symfony52-validator-attributes.php';

/**
* @var string
*/
public const SYMFONY_60 = __DIR__ . '/../../config/sets/symfony/symfony60.php';

/**
* @var string
*/
Expand Down