[Symfony] Add Symfony 5.1 set (#5331)

Co-authored-by: rector-bot <tomas@getrector.org>
This commit is contained in:
Tomas Votruba 2021-01-27 15:09:08 +01:00 committed by GitHub
parent 57d7899184
commit fced0ca087
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 1086 additions and 244 deletions

View File

@ -13,13 +13,14 @@ use Rector\CakePHP\Rector\MethodCall\ModalToGetSetRector;
use Rector\CakePHP\Rector\MethodCall\RenameMethodCallBasedOnParameterRector;
use Rector\CakePHP\ValueObject\ModalToGetSet;
use Rector\CakePHP\ValueObject\RenameMethodCallBasedOnParameter;
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstantRector;
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\Rector\PropertyFetch\RenamePropertyRector;
use Rector\Renaming\Rector\StaticCall\RenameStaticMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\RenameClassConstant;
use Rector\Renaming\ValueObject\RenameClassAndConstFetch;
use Rector\Renaming\ValueObject\RenameClassConstFetch;
use Rector\Renaming\ValueObject\RenameProperty;
use Rector\Renaming\ValueObject\RenameStaticMethod;
use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector;
@ -42,15 +43,35 @@ return static function (ContainerConfigurator $containerConfigurator): void {
],
]]);
$services->set(RenameClassConstantRector::class)
$services->set(RenameClassConstFetchRector::class)
->call('configure', [[
RenameClassConstantRector::CLASS_CONSTANT_RENAME => ValueObjectInliner::inline([
new RenameClassConstant('Cake\View\View', 'NAME_ELEMENT', 'TYPE_ELEMENT'),
new RenameClassConstant('Cake\View\View', 'NAME_LAYOUT', 'TYPE_LAYOUT'),
new RenameClassConstant('Cake\Mailer\Email', 'MESSAGE_HTML', 'Cake\Mailer\Message::MESSAGE_HTML'),
new RenameClassConstant('Cake\Mailer\Email', 'MESSAGE_TEXT', 'Cake\Mailer\Message::MESSAGE_TEXT'),
new RenameClassConstant('Cake\Mailer\Email', 'MESSAGE_BOTH', 'Cake\Mailer\Message::MESSAGE_BOTH'),
new RenameClassConstant('Cake\Mailer\Email', 'EMAIL_PATTERN', 'Cake\Mailer\Message::EMAIL_PATTERN'),
RenameClassConstFetchRector::CLASS_CONSTANT_RENAME => ValueObjectInliner::inline([
new RenameClassConstFetch('Cake\View\View', 'NAME_ELEMENT', 'TYPE_ELEMENT'),
new RenameClassConstFetch('Cake\View\View', 'NAME_LAYOUT', 'TYPE_LAYOUT'),
new RenameClassAndConstFetch(
'Cake\Mailer\Email',
'MESSAGE_HTML',
'Cake\Mailer\Message',
'MESSAGE_HTML'
),
new RenameClassAndConstFetch(
'Cake\Mailer\Email',
'MESSAGE_TEXT',
'Cake\Mailer\Message',
'MESSAGE_TEXT'
),
new RenameClassAndConstFetch(
'Cake\Mailer\Email',
'MESSAGE_BOTH',
'Cake\Mailer\Message',
'MESSAGE_BOTH'
),
new RenameClassAndConstFetch(
'Cake\Mailer\Email',
'EMAIL_PATTERN',
'Cake\Mailer\Message',
'EMAIL_PATTERN'
),
]),
]]);

View File

@ -14,11 +14,11 @@ use Rector\Nette\Rector\MethodCall\MagicHtmlCallToAppendAttributeRector;
use Rector\Nette\Rector\MethodCall\MergeDefaultsInGetConfigCompilerExtensionRector;
use Rector\Nette\Rector\MethodCall\RequestGetCookieDefaultArgumentToCoalesceRector;
use Rector\NetteCodeQuality\Rector\ArrayDimFetch\ChangeFormArrayAccessToAnnotatedControlVariableRector;
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstantRector;
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\RenameClassConstant;
use Rector\Renaming\ValueObject\RenameClassConstFetch;
use Rector\Transform\Rector\StaticCall\StaticCallToMethodCallRector;
use Rector\Transform\ValueObject\StaticCallToMethodCall;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
@ -51,11 +51,11 @@ return static function (ContainerConfigurator $containerConfigurator): void {
]),
]]);
// https://github.com/contributte/event-dispatcher-extra/tree/v0.4.3 and higher
$services->set(RenameClassConstantRector::class)->call('configure', [[
RenameClassConstantRector::CLASS_CONSTANT_RENAME => ValueObjectInliner::inline([
new RenameClassConstant('Contributte\Events\Extra\Event\Security\LoggedInEvent', 'NAME', 'class'),
new RenameClassConstant('Contributte\Events\Extra\Event\Security\LoggedOutEvent', 'NAME', 'class'),
new RenameClassConstant('Contributte\Events\Extra\Event\Application\ShutdownEvent', 'NAME', 'class'),
$services->set(RenameClassConstFetchRector::class)->call('configure', [[
RenameClassConstFetchRector::CLASS_CONSTANT_RENAME => ValueObjectInliner::inline([
new RenameClassConstFetch('Contributte\Events\Extra\Event\Security\LoggedInEvent', 'NAME', 'class'),
new RenameClassConstFetch('Contributte\Events\Extra\Event\Security\LoggedOutEvent', 'NAME', 'class'),
new RenameClassConstFetch('Contributte\Events\Extra\Event\Application\ShutdownEvent', 'NAME', 'class'),
]),
]]);
$services->set(RenameClassRector::class)->call('configure', [[

View File

@ -10,11 +10,11 @@ use Rector\NetteToSymfony\Rector\ClassMethod\RouterListToControllerAnnotationsRe
use Rector\NetteToSymfony\Rector\Interface_\DeleteFactoryInterfaceRector;
use Rector\NetteToSymfony\Rector\MethodCall\FromHttpRequestGetHeaderToHeadersGetRector;
use Rector\NetteToSymfony\Rector\MethodCall\FromRequestGetParameterToAttributesGetRector;
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstantRector;
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\RenameClassConstant;
use Rector\Renaming\ValueObject\RenameClassAndConstFetch;
use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddReturnTypeDeclaration;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
@ -70,343 +70,410 @@ return static function (ContainerConfigurator $containerConfigurator): void {
RemoveInterfacesRector::INTERFACES_TO_REMOVE => ['Nette\Application\IPresenter'],
]]);
$services->set(RenameClassConstantRector::class)
$services->set(RenameClassConstFetchRector::class)
->call('configure', [[
RenameClassConstantRector::CLASS_CONSTANT_RENAME => ValueObjectInliner::inline([
new RenameClassConstant(
RenameClassConstFetchRector::CLASS_CONSTANT_RENAME => ValueObjectInliner::inline([
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S100_CONTINUE',
'Symfony\Component\HttpFoundation\Response::HTTP_CONTINUE'
'Symfony\Component\HttpFoundation\Response',
'HTTP_CONTINUE'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S101_SWITCHING_PROTOCOLS',
'Symfony\Component\HttpFoundation\Response::HTTP_SWITCHING_PROTOCOLS'
'Symfony\Component\HttpFoundation\Response',
'HTTP_SWITCHING_PROTOCOLS'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S102_PROCESSING',
'Symfony\Component\HttpFoundation\Response::HTTP_PROCESSING'
'Symfony\Component\HttpFoundation\Response',
'HTTP_PROCESSING'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S200_OK',
'Symfony\Component\HttpFoundation\Response::HTTP_OK'
'Symfony\Component\HttpFoundation\Response',
'HTTP_OK'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S201_CREATED',
'Symfony\Component\HttpFoundation\Response::HTTP_CREATED'
'Symfony\Component\HttpFoundation\Response',
'HTTP_CREATED'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S202_ACCEPTED',
'Symfony\Component\HttpFoundation\Response::HTTP_ACCEPTED'
'Symfony\Component\HttpFoundation\Response',
'HTTP_ACCEPTED'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S203_NON_AUTHORITATIVE_INFORMATION',
'Symfony\Component\HttpFoundation\Response::HTTP_NON_AUTHORITATIVE_INFORMATION'
'Symfony\Component\HttpFoundation\Response',
'HTTP_NON_AUTHORITATIVE_INFORMATION'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S204_NO_CONTENT',
'Symfony\Component\HttpFoundation\Response::HTTP_NO_CONTENT'
'Symfony\Component\HttpFoundation\Response',
'HTTP_NO_CONTENT'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S205_RESET_CONTENT',
'Symfony\Component\HttpFoundation\Response::HTTP_RESET_CONTENT'
'Symfony\Component\HttpFoundation\Response',
'HTTP_RESET_CONTENT'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S206_PARTIAL_CONTENT',
'Symfony\Component\HttpFoundation\Response::HTTP_PARTIAL_CONTENT'
'Symfony\Component\HttpFoundation\Response',
'HTTP_PARTIAL_CONTENT'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S207_MULTI_STATUS',
'Symfony\Component\HttpFoundation\Response::HTTP_MULTI_STATUS'
'Symfony\Component\HttpFoundation\Response',
'HTTP_MULTI_STATUS'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S208_ALREADY_REPORTED',
'Symfony\Component\HttpFoundation\Response::HTTP_ALREADY_REPORTED'
'Symfony\Component\HttpFoundation\Response',
'HTTP_ALREADY_REPORTED'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S226_IM_USED',
'Symfony\Component\HttpFoundation\Response::HTTP_IM_USED'
'Symfony\Component\HttpFoundation\Response',
'HTTP_IM_USED'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S300_MULTIPLE_CHOICES',
'Symfony\Component\HttpFoundation\Response::HTTP_MULTIPLE_CHOICES'
'Symfony\Component\HttpFoundation\Response',
'HTTP_MULTIPLE_CHOICES'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S301_MOVED_PERMANENTLY',
'Symfony\Component\HttpFoundation\Response::HTTP_MOVED_PERMANENTLY'
'Symfony\Component\HttpFoundation\Response',
'HTTP_MOVED_PERMANENTLY'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S302_FOUND',
'Symfony\Component\HttpFoundation\Response::HTTP_FOUND'
'Symfony\Component\HttpFoundation\Response',
'HTTP_FOUND'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S303_SEE_OTHER',
'Symfony\Component\HttpFoundation\Response::HTTP_SEE_OTHER'
'Symfony\Component\HttpFoundation\Response',
'HTTP_SEE_OTHER'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S303_POST_GET',
'Symfony\Component\HttpFoundation\Response::HTTP_SEE_OTHER'
'Symfony\Component\HttpFoundation\Response',
'HTTP_SEE_OTHER'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S304_NOT_MODIFIED',
'Symfony\Component\HttpFoundation\Response::HTTP_NOT_MODIFIED'
'Symfony\Component\HttpFoundation\Response',
'HTTP_NOT_MODIFIED'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S305_USE_PROXY',
'Symfony\Component\HttpFoundation\Response::HTTP_USE_PROXY'
'Symfony\Component\HttpFoundation\Response',
'HTTP_USE_PROXY'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S307_TEMPORARY_REDIRECT',
'Symfony\Component\HttpFoundation\Response::HTTP_TEMPORARY_REDIRECT'
'Symfony\Component\HttpFoundation\Response',
'HTTP_TEMPORARY_REDIRECT'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S308_PERMANENT_REDIRECT',
'Symfony\Component\HttpFoundation\Response::HTTP_PERMANENTLY_REDIRECT'
'Symfony\Component\HttpFoundation\Response',
'HTTP_PERMANENTLY_REDIRECT'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S400_BAD_REQUEST',
'Symfony\Component\HttpFoundation\Response::HTTP_BAD_REQUEST'
'Symfony\Component\HttpFoundation\Response',
'HTTP_BAD_REQUEST'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S401_UNAUTHORIZED',
'Symfony\Component\HttpFoundation\Response::HTTP_UNAUTHORIZED'
'Symfony\Component\HttpFoundation\Response',
'HTTP_UNAUTHORIZED'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S402_PAYMENT_REQUIRED',
'Symfony\Component\HttpFoundation\Response::HTTP_PAYMENT_REQUIRED'
'Symfony\Component\HttpFoundation\Response',
'HTTP_PAYMENT_REQUIRED'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S403_FORBIDDEN',
'Symfony\Component\HttpFoundation\Response::HTTP_FORBIDDEN'
'Symfony\Component\HttpFoundation\Response',
'HTTP_FORBIDDEN'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S404_NOT_FOUND',
'Symfony\Component\HttpFoundation\Response::HTTP_NOT_FOUND'
'Symfony\Component\HttpFoundation\Response',
'HTTP_NOT_FOUND'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S405_METHOD_NOT_ALLOWED',
'Symfony\Component\HttpFoundation\Response::HTTP_METHOD_NOT_ALLOWED'
'Symfony\Component\HttpFoundation\Response',
'HTTP_METHOD_NOT_ALLOWED'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S406_NOT_ACCEPTABLE',
'Symfony\Component\HttpFoundation\Response::HTTP_NOT_ACCEPTABLE'
'Symfony\Component\HttpFoundation\Response',
'HTTP_NOT_ACCEPTABLE'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S407_PROXY_AUTHENTICATION_REQUIRED',
'Symfony\Component\HttpFoundation\Response::HTTP_PROXY_AUTHENTICATION_REQUIRED'
'Symfony\Component\HttpFoundation\Response',
'HTTP_PROXY_AUTHENTICATION_REQUIRED'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S408_REQUEST_TIMEOUT',
'Symfony\Component\HttpFoundation\Response::HTTP_REQUEST_TIMEOUT'
'Symfony\Component\HttpFoundation\Response',
'HTTP_REQUEST_TIMEOUT'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S409_CONFLICT',
'Symfony\Component\HttpFoundation\Response::HTTP_CONFLICT'
'Symfony\Component\HttpFoundation\Response',
'HTTP_CONFLICT'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S410_GONE',
'Symfony\Component\HttpFoundation\Response::HTTP_GONE'
'Symfony\Component\HttpFoundation\Response',
'HTTP_GONE'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S411_LENGTH_REQUIRED',
'Symfony\Component\HttpFoundation\Response::HTTP_LENGTH_REQUIRED'
'Symfony\Component\HttpFoundation\Response',
'HTTP_LENGTH_REQUIRED'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S412_PRECONDITION_FAILED',
'Symfony\Component\HttpFoundation\Response::HTTP_PRECONDITION_FAILED'
'Symfony\Component\HttpFoundation\Response',
'HTTP_PRECONDITION_FAILED'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S413_REQUEST_ENTITY_TOO_LARGE',
'Symfony\Component\HttpFoundation\Response::HTTP_REQUEST_ENTITY_TOO_LARGE'
'Symfony\Component\HttpFoundation\Response',
'HTTP_REQUEST_ENTITY_TOO_LARGE'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S414_REQUEST_URI_TOO_LONG',
'Symfony\Component\HttpFoundation\Response::HTTP_REQUEST_URI_TOO_LONG'
'Symfony\Component\HttpFoundation\Response',
'HTTP_REQUEST_URI_TOO_LONG'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S415_UNSUPPORTED_MEDIA_TYPE',
'Symfony\Component\HttpFoundation\Response::HTTP_UNSUPPORTED_MEDIA_TYPE'
'Symfony\Component\HttpFoundation\Response',
'HTTP_UNSUPPORTED_MEDIA_TYPE'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S416_REQUESTED_RANGE_NOT_SATISFIABLE',
'Symfony\Component\HttpFoundation\Response::HTTP_REQUESTED_RANGE_NOT_SATISFIABLE'
'Symfony\Component\HttpFoundation\Response',
'HTTP_REQUESTED_RANGE_NOT_SATISFIABLE'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S417_EXPECTATION_FAILED',
'Symfony\Component\HttpFoundation\Response::HTTP_EXPECTATION_FAILED'
'Symfony\Component\HttpFoundation\Response',
'HTTP_EXPECTATION_FAILED'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S421_MISDIRECTED_REQUEST',
'Symfony\Component\HttpFoundation\Response::HTTP_MISDIRECTED_REQUEST'
'Symfony\Component\HttpFoundation\Response',
'HTTP_MISDIRECTED_REQUEST'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S422_UNPROCESSABLE_ENTITY',
'Symfony\Component\HttpFoundation\Response::HTTP_UNPROCESSABLE_ENTITY'
'Symfony\Component\HttpFoundation\Response',
'HTTP_UNPROCESSABLE_ENTITY'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S423_LOCKED',
'Symfony\Component\HttpFoundation\Response::HTTP_LOCKED'
'Symfony\Component\HttpFoundation\Response',
'HTTP_LOCKED'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S424_FAILED_DEPENDENCY',
'Symfony\Component\HttpFoundation\Response::HTTP_FAILED_DEPENDENCY'
'Symfony\Component\HttpFoundation\Response',
'HTTP_FAILED_DEPENDENCY'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S426_UPGRADE_REQUIRED',
'Symfony\Component\HttpFoundation\Response::HTTP_UPGRADE_REQUIRED'
'Symfony\Component\HttpFoundation\Response',
'HTTP_UPGRADE_REQUIRED'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S428_PRECONDITION_REQUIRED',
'Symfony\Component\HttpFoundation\Response::HTTP_PRECONDITION_REQUIRED'
'Symfony\Component\HttpFoundation\Response',
'HTTP_PRECONDITION_REQUIRED'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S429_TOO_MANY_REQUESTS',
'Symfony\Component\HttpFoundation\Response::HTTP_TOO_MANY_REQUESTS'
'Symfony\Component\HttpFoundation\Response',
'HTTP_TOO_MANY_REQUESTS'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S431_REQUEST_HEADER_FIELDS_TOO_LARGE',
'Symfony\Component\HttpFoundation\Response::HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE'
'Symfony\Component\HttpFoundation\Response',
'HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S451_UNAVAILABLE_FOR_LEGAL_REASONS',
'Symfony\Component\HttpFoundation\Response::HTTP_UNAVAILABLE_FOR_LEGAL_REASONS'
'Symfony\Component\HttpFoundation\Response',
'HTTP_UNAVAILABLE_FOR_LEGAL_REASONS'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S500_INTERNAL_SERVER_ERROR',
'Symfony\Component\HttpFoundation\Response::HTTP_INTERNAL_SERVER_ERROR'
'Symfony\Component\HttpFoundation\Response',
'HTTP_INTERNAL_SERVER_ERROR'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S501_NOT_IMPLEMENTED',
'Symfony\Component\HttpFoundation\Response::HTTP_NOT_IMPLEMENTED'
'Symfony\Component\HttpFoundation\Response',
'HTTP_NOT_IMPLEMENTED'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S502_BAD_GATEWAY',
'Symfony\Component\HttpFoundation\Response::HTTP_BAD_GATEWAY'
'Symfony\Component\HttpFoundation\Response',
'HTTP_BAD_GATEWAY'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S503_SERVICE_UNAVAILABLE',
'Symfony\Component\HttpFoundation\Response::HTTP_SERVICE_UNAVAILABLE'
'Symfony\Component\HttpFoundation\Response',
'HTTP_SERVICE_UNAVAILABLE'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S504_GATEWAY_TIMEOUT',
'Symfony\Component\HttpFoundation\Response::HTTP_GATEWAY_TIMEOUT'
'Symfony\Component\HttpFoundation\Response',
'HTTP_GATEWAY_TIMEOUT'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S505_HTTP_VERSION_NOT_SUPPORTED',
'Symfony\Component\HttpFoundation\Response::HTTP_VERSION_NOT_SUPPORTED'
'Symfony\Component\HttpFoundation\Response',
'HTTP_VERSION_NOT_SUPPORTED'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S506_VARIANT_ALSO_NEGOTIATES',
'Symfony\Component\HttpFoundation\Response::HTTP_VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL'
'Symfony\Component\HttpFoundation\Response',
'HTTP_VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S507_INSUFFICIENT_STORAGE',
'Symfony\Component\HttpFoundation\Response::HTTP_INSUFFICIENT_STORAGE'
'Symfony\Component\HttpFoundation\Response',
'HTTP_INSUFFICIENT_STORAGE'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S508_LOOP_DETECTED',
'Symfony\Component\HttpFoundation\Response::HTTP_LOOP_DETECTED'
'Symfony\Component\HttpFoundation\Response',
'HTTP_LOOP_DETECTED'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S510_NOT_EXTENDED',
'Symfony\Component\HttpFoundation\Response::HTTP_NOT_EXTENDED'
'Symfony\Component\HttpFoundation\Response',
'HTTP_NOT_EXTENDED'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Response',
'S511_NETWORK_AUTHENTICATION_REQUIRED',
'Symfony\Component\HttpFoundation\Response::HTTP_NETWORK_AUTHENTICATION_REQUIRED'
'Symfony\Component\HttpFoundation\Response',
'HTTP_NETWORK_AUTHENTICATION_REQUIRED'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Request',
'GET',
'Symfony\Component\HttpFoundation\Request::METHOD_GET'
'Symfony\Component\HttpFoundation\Request',
'METHOD_GET'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Request',
'POST',
'Symfony\Component\HttpFoundation\Request::METHOD_POST'
'Symfony\Component\HttpFoundation\Request',
'METHOD_POST'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Request',
'HEAD',
'Symfony\Component\HttpFoundation\Request::METHOD_HEAD'
'Symfony\Component\HttpFoundation\Request',
'METHOD_HEAD'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Request',
'PUT',
'Symfony\Component\HttpFoundation\Request::METHOD_PUT'
'Symfony\Component\HttpFoundation\Request',
'METHOD_PUT'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Request',
'DELETE',
'Symfony\Component\HttpFoundation\Request::METHOD_DELETE'
'Symfony\Component\HttpFoundation\Request',
'METHOD_DELETE'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Request',
'PATCH',
'Symfony\Component\HttpFoundation\Request::METHOD_PATCH'
'Symfony\Component\HttpFoundation\Request',
'METHOD_PATCH'
),
new RenameClassConstant(
new RenameClassAndConstFetch(
'Nette\Http\*Request',
'OPTIONS',
'Symfony\Component\HttpFoundation\Request::METHOD_OPTIONS'
'Symfony\Component\HttpFoundation\Request',
'METHOD_OPTIONS'
),
]),
]]);

View File

@ -2,12 +2,12 @@
declare(strict_types=1);
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstantRector;
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\RenameClassConstant;
use Rector\Renaming\ValueObject\RenameClassConstFetch;
use Rector\Symfony3\Rector\ClassMethod\FormTypeGetParentRector;
use Rector\Symfony3\Rector\ClassMethod\GetRequestRector;
use Rector\Symfony3\Rector\ClassMethod\RemoveDefaultGetBlockPrefixRector;
@ -42,23 +42,23 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(ChangeStringCollectionOptionToConstantRector::class);
$services->set(ChangeCollectionTypeOptionNameFromTypeToEntryTypeRector::class);
$services->set(RenameClassConstantRector::class)
$services->set(RenameClassConstFetchRector::class)
->call('configure', [[
RenameClassConstantRector::CLASS_CONSTANT_RENAME => ValueObjectInliner::inline([
new RenameClassConstant('Symfony\Component\Form\FormEvents', 'PRE_BIND', 'PRE_SUBMIT'),
new RenameClassConstant('Symfony\Component\Form\FormEvents', 'BIND', 'SUBMIT'),
new RenameClassConstant('Symfony\Component\Form\FormEvents', 'POST_BIND', 'POST_SUBMIT'),
new RenameClassConstant(
RenameClassConstFetchRector::CLASS_CONSTANT_RENAME => ValueObjectInliner::inline([
new RenameClassConstFetch('Symfony\Component\Form\FormEvents', 'PRE_BIND', 'PRE_SUBMIT'),
new RenameClassConstFetch('Symfony\Component\Form\FormEvents', 'BIND', 'SUBMIT'),
new RenameClassConstFetch('Symfony\Component\Form\FormEvents', 'POST_BIND', 'POST_SUBMIT'),
new RenameClassConstFetch(
'Symfony\Component\Form\Extension\Core\DataTransformer',
'ROUND_HALFEVEN',
'ROUND_HALF_EVEN'
),
new RenameClassConstant(
new RenameClassConstFetch(
'Symfony\Component\Form\Extension\Core\DataTransformer',
'ROUND_HALFUP',
'ROUND_HALF_UP'
),
new RenameClassConstant(
new RenameClassConstFetch(
'Symfony\Component\Form\Extension\Core\DataTransformer',
'ROUND_HALFDOWN',
'ROUND_HALF_DOWN'

144
config/set/symfony51.php Normal file
View File

@ -0,0 +1,144 @@
<?php
declare(strict_types=1);
use PHPStan\Type\ObjectType;
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector;
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\RenameClassAndConstFetch;
use Rector\Transform\Rector\New_\NewArgToMethodCallRector;
use Rector\Transform\Rector\StaticCall\StaticCallToNewRector;
use Rector\Transform\ValueObject\NewArgToMethodCall;
use Rector\Transform\ValueObject\StaticCallToNew;
use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddParamTypeDeclaration;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
# https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.1.md
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(RenameClassRector::class)
->call('configure', [[
RenameClassRector::OLD_TO_NEW_CLASSES => [
'Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy' => 'Symfony\Component\EventDispatcher\EventDispatcherInterface',
'Symfony\Component\Form\Extension\Validator\Util\ServerParams' => 'Symfony\Component\Form\Util\ServerParams',
// see https://github.com/symfony/symfony/pull/35092
'Symfony\Component\Inflector' => 'Symfony\Component\String\Inflector\InflectorInterface',
],
]]);
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::METHOD_CALL_RENAMES => ValueObjectInliner::inline([
new MethodCallRename(
'Symfony\Component\Config\Definition\BaseNode',
'getDeprecationMessage',
'getDeprecation'
),
new MethodCallRename(
'Symfony\Component\DependencyInjection\Definition',
'getDeprecationMessage',
'getDeprecation'
),
new MethodCallRename(
'Symfony\Component\DependencyInjection\Alias',
'getDeprecationMessage',
'getDeprecation'
),
]),
]]);
$services->set(RenameFunctionRector::class)
->call('configure', [[
RenameFunctionRector::OLD_FUNCTION_TO_NEW_FUNCTION => [
'Symfony\Component\DependencyInjection\Loader\Configuraton\inline' => 'Symfony\Component\DependencyInjection\Loader\Configuraton\inline_service',
'Symfony\Component\DependencyInjection\Loader\Configuraton\ref' => 'Symfony\Component\DependencyInjection\Loader\Configuraton\service',
],
]]);
// https://github.com/symfony/symfony/pull/35308
$services->set(NewArgToMethodCallRector::class)
->call('configure', [[
NewArgToMethodCallRector::NEW_ARGS_TO_METHOD_CALLS => ValueObjectInliner::inline([
new NewArgToMethodCall('Symfony\Component\Dotenv\Dotenv', true, 'usePutenv'),
]),
]]);
$services->set(RenameClassConstFetchRector::class)
->call('configure', [[
RenameClassConstFetchRector::CLASS_CONSTANT_RENAME => ValueObjectInliner::inline([
new RenameClassAndConstFetch(
'Symfony\Component\Form\Extension\Core\DataTransformer\NumberToLocalizedStringTransformer',
'ROUND_FLOOR',
'NumberFormatter',
'ROUND_FLOOR'
),
new RenameClassAndConstFetch(
'Symfony\Component\Form\Extension\Core\DataTransformer\NumberToLocalizedStringTransformer',
'ROUND_DOWN',
'NumberFormatter',
'ROUND_DOWN'
),
new RenameClassAndConstFetch(
'Symfony\Component\Form\Extension\Core\DataTransformer\NumberToLocalizedStringTransformer',
'ROUND_HALF_DOWN',
'NumberFormatter',
'ROUND_HALFDOWN'
),
new RenameClassAndConstFetch(
'Symfony\Component\Form\Extension\Core\DataTransformer\NumberToLocalizedStringTransformer',
'ROUND_HALF_EVEN',
'NumberFormatter',
'ROUND_HALFEVEN'
),
new RenameClassAndConstFetch(
'Symfony\Component\Form\Extension\Core\DataTransformer\NumberToLocalizedStringTransformer',
'ROUND_HALFUP',
'NumberFormatter',
'ROUND_HALFUP'
),
new RenameClassAndConstFetch(
'Symfony\Component\Form\Extension\Core\DataTransformer\NumberToLocalizedStringTransformer',
'ROUND_UP',
'NumberFormatter',
'ROUND_UP'
),
new RenameClassAndConstFetch(
'Symfony\Component\Form\Extension\Core\DataTransformer\NumberToLocalizedStringTransformer',
'ROUND_CEILING',
'NumberFormatter',
'ROUND_CEILING'
),
]),
]]);
$services->set(AddParamTypeDeclarationRector::class)
->call('configure', [[
// see https://github.com/symfony/symfony/pull/36943
AddParamTypeDeclarationRector::PARAMETER_TYPEHINTS => ValueObjectInliner::inline([
new AddParamTypeDeclaration(
'Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait',
'configureRoutes',
0,
new ObjectType('Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator'),
),
]),
]]);
$services->set(StaticCallToNewRector::class)
->call('configure', [[
// see https://github.com/symfony/symfony/pull/36943
StaticCallToNewRector::STATIC_CALLS_TO_NEWS => ValueObjectInliner::inline([
new StaticCallToNew('Symfony\Component\HttpFoundation\Response', 'create'),
new StaticCallToNew('Symfony\Component\HttpFoundation\JsonResponse', 'create'),
new StaticCallToNew('Symfony\Component\HttpFoundation\RedirectResponse', 'create'),
new StaticCallToNew('Symfony\Component\HttpFoundation\StreamedResponse', 'create'),
]),
]]);
};

View File

@ -2,10 +2,10 @@
declare(strict_types=1);
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstantRector;
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\RenameClassConstant;
use Rector\Renaming\ValueObject\RenameClassAndConstFetch;
use Rector\Symfony5\Rector\MethodCall\DefinitionAliasSetPrivateToSetPublicRector;
use Rector\Symfony5\Rector\MethodCall\ReflectionExtractorEnableMagicCallExtractorRector;
use Rector\Symfony5\Rector\New_\PropertyAccessorCreationBooleanToFlagsRector;
@ -42,13 +42,14 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(ReflectionExtractorEnableMagicCallExtractorRector::class);
# https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#security
$services->set(RenameClassConstantRector::class)
$services->set(RenameClassConstFetchRector::class)
->call('configure', [[
RenameClassConstantRector::CLASS_CONSTANT_RENAME => ValueObjectInliner::inline([
new RenameClassConstant(
RenameClassConstFetchRector::CLASS_CONSTANT_RENAME => ValueObjectInliner::inline([
new RenameClassAndConstFetch(
'Symfony\Component\Security\Http\Firewall\AccessListener',
'PUBLIC_ACCESS',
'Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter::PUBLIC_ACCESS'
'Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter',
'PUBLIC_ACCESS'
),
]),
]]);

View File

@ -7773,7 +7773,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameClassConstantsUseToStringsRector::class)
->call('configure', [[
RenameClassConstantsUseToStringsRector::OLD_CONSTANTS_TO_NEW_VALUES_BY_TYPE => [
RenameClassConstantsUseToStringsRector::CLASS_CONST_FETCHES_TO_VALUES => [
'Nette\Configurator' => [
'DEVELOPMENT' => 'development',
'PRODUCTION' => 'production',
@ -14479,19 +14479,19 @@ Replaces defined class constants in their calls.
- class: `Rector\Renaming\Rector\ClassConstFetch\RenameClassConstantRector`
```php
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstantRector;
use Rector\Renaming\ValueObject\RenameClassConstant;
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector;
use Rector\Renaming\ValueObject\RenameClassConstFetch;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(RenameClassConstantRector::class)
$services->set(RenameClassConstFetchRector::class)
->call('configure', [[
RenameClassConstantRector::CLASS_CONSTANT_RENAME => ValueObjectInliner::inline([
new RenameClassConstant('SomeClass', 'OLD_CONSTANT', 'NEW_CONSTANT'),
new RenameClassConstant('SomeClass', 'OTHER_OLD_CONSTANT', 'DifferentClass::NEW_CONSTANT'),
RenameClassConstFetchRector::CLASS_CONSTANT_RENAME => ValueObjectInliner::inline([
new RenameClassConstFetch('SomeClass', 'OLD_CONSTANT', 'NEW_CONSTANT'),
new RenameClassConstFetch('SomeClass', 'OTHER_OLD_CONSTANT', 'DifferentClass::NEW_CONSTANT'),
]),
]]);
};

View File

@ -84,6 +84,7 @@ final class ConfigurationNodeFactory
$classConsts = [];
foreach (array_keys($ruleConfiguration) as $constantName) {
$constantName = strtoupper($constantName);
$constantValue = strtolower($constantName);
$classConst = $this->nodeFactory->createPublicClassConst($constantName, $constantValue);
$classConsts[] = $classConst;

View File

@ -160,6 +160,8 @@ final class TemplateVariablesFactory
{
$arrayItems = [];
foreach ($configuration as $constantName => $variableConfiguration) {
$constantName = strtoupper($constantName);
if ($rectorClass === self::SELF) {
$class = new Name(self::SELF);
} else {

View File

@ -4,13 +4,15 @@ declare(strict_types=1);
namespace Rector\Generic\Rector\ClassConstFetch;
use PhpParser\BuilderHelpers;
use PhpParser\Node;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Scalar\String_;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Generic\ValueObject\ClassConstFetchToValue;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;
/**
* @see \Rector\Generic\Tests\Rector\ClassConstFetch\RenameClassConstantsUseToStringsRector\RenameClassConstantsUseToStringsRectorTest
@ -20,27 +22,27 @@ final class RenameClassConstantsUseToStringsRector extends AbstractRector implem
/**
* @var string
*/
public const OLD_CONSTANTS_TO_NEW_VALUES_BY_TYPE = '$oldConstantsToNewValuesByType';
public const CLASS_CONST_FETCHES_TO_VALUES = 'old_constants_to_new_valuesByType';
/**
* @var string[][]
* @var ClassConstFetchToValue[]
*/
private $oldConstantsToNewValuesByType = [];
private $classConstFetchesToValues = [];
public function getRuleDefinition(): RuleDefinition
{
$configuration = [
self::CLASS_CONST_FETCHES_TO_VALUES => [
new ClassConstFetchToValue('Nette\Configurator', 'DEVELOPMENT', 'development'),
new ClassConstFetchToValue('Nette\Configurator', 'PRODUCTION', 'production'),
],
];
return new RuleDefinition('Replaces constant by value', [
new ConfiguredCodeSample(
'$value === Nette\Configurator::DEVELOPMENT',
'$value === "development"',
[
self::OLD_CONSTANTS_TO_NEW_VALUES_BY_TYPE => [
'Nette\Configurator' => [
'DEVELOPMENT' => 'development',
'PRODUCTION' => 'production',
],
],
]
$configuration
),
]);
}
@ -58,25 +60,29 @@ final class RenameClassConstantsUseToStringsRector extends AbstractRector implem
*/
public function refactor(Node $node): ?Node
{
foreach ($this->oldConstantsToNewValuesByType as $type => $oldConstantsToNewValues) {
if (! $this->isObjectType($node->class, $type)) {
foreach ($this->classConstFetchesToValues as $classConstFetchToValue) {
if (! $this->isObjectType($node->class, $classConstFetchToValue->getClass())) {
continue;
}
foreach ($oldConstantsToNewValues as $oldConstant => $newValue) {
if (! $this->isName($node->name, $oldConstant)) {
continue;
}
return new String_($newValue);
if (! $this->isName($node->name, $classConstFetchToValue->getConstant())) {
continue;
}
return BuilderHelpers::normalizeValue($classConstFetchToValue->getValue());
}
return $node;
}
/**
* @param array<string, ClassConstFetchToValue[]> $configuration
*/
public function configure(array $configuration): void
{
$this->oldConstantsToNewValuesByType = $configuration[self::OLD_CONSTANTS_TO_NEW_VALUES_BY_TYPE] ?? [];
$classConstFetchesToValues = $configuration[self::CLASS_CONST_FETCHES_TO_VALUES] ?? [];
Assert::allIsInstanceOf($classConstFetchesToValues, ClassConstFetchToValue::class);
$this->classConstFetchesToValues = $classConstFetchesToValues;
}
}

View File

@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace Rector\Generic\ValueObject;
final class ClassConstFetchToValue
{
/**
* @var string
*/
private $class;
/**
* @var string
*/
private $constant;
/**
* @var mixed
*/
private $value;
/**
* @param mixed $value
*/
public function __construct(string $class, string $constant, $value)
{
$this->class = $class;
$this->constant = $constant;
$this->value = $value;
}
public function getClass(): string
{
return $this->class;
}
public function getConstant(): string
{
return $this->constant;
}
/**
* @return mixed
*/
public function getValue()
{
return $this->value;
}
}

View File

@ -7,6 +7,7 @@ namespace Rector\Generic\Tests\Rector\ClassConstFetch\RenameClassConstantsUseToS
use Iterator;
use Rector\Generic\Rector\ClassConstFetch\RenameClassConstantsUseToStringsRector;
use Rector\Generic\Tests\Rector\ClassConstFetch\RenameClassConstantsUseToStringsRector\Source\OldClassWithConstants;
use Rector\Generic\ValueObject\ClassConstFetchToValue;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -32,11 +33,9 @@ final class RenameClassConstantsUseToStringsRectorTest extends AbstractRectorTes
{
return [
RenameClassConstantsUseToStringsRector::class => [
RenameClassConstantsUseToStringsRector::OLD_CONSTANTS_TO_NEW_VALUES_BY_TYPE => [
OldClassWithConstants::class => [
'DEVELOPMENT' => 'development',
'PRODUCTION' => 'production',
],
RenameClassConstantsUseToStringsRector::CLASS_CONST_FETCHES_TO_VALUES => [
new ClassConstFetchToValue(OldClassWithConstants::class, 'DEVELOPMENT', 'development'),
new ClassConstFetchToValue(OldClassWithConstants::class, 'PRODUCTION', 'production'),
],
],
];

View File

@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace Rector\Renaming\Contract;
interface RenameClassConstFetchInterface
{
public function getOldClass(): string;
public function getOldConstant(): string;
public function getNewConstant(): string;
}

View File

@ -4,22 +4,23 @@ declare(strict_types=1);
namespace Rector\Renaming\Rector\ClassConstFetch;
use Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name\FullyQualified;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Renaming\ValueObject\RenameClassConstant;
use Rector\Renaming\Contract\RenameClassConstFetchInterface;
use Rector\Renaming\ValueObject\RenameClassAndConstFetch;
use Rector\Renaming\ValueObject\RenameClassConstFetch;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;
/**
* @see \Rector\Renaming\Tests\Rector\ClassConstFetch\RenameClassConstantRector\RenameClassConstantRectorTest
* @see \Rector\Renaming\Tests\Rector\ClassConstFetch\RenameClassConstFetchRector\RenameClassConstFetchRectorTest
*/
final class RenameClassConstantRector extends AbstractRector implements ConfigurableRectorInterface
final class RenameClassConstFetchRector extends AbstractRector implements ConfigurableRectorInterface
{
/**
* @var string
@ -27,16 +28,16 @@ final class RenameClassConstantRector extends AbstractRector implements Configur
public const CLASS_CONSTANT_RENAME = 'constant_rename';
/**
* @var RenameClassConstant[]
* @var RenameClassConstFetchInterface[]
*/
private $classConstantRenames = [];
private $renameClassConstFetches = [];
public function getRuleDefinition(): RuleDefinition
{
$configuration = [
self::CLASS_CONSTANT_RENAME => [
new RenameClassConstant('SomeClass', 'OLD_CONSTANT', 'NEW_CONSTANT'),
new RenameClassConstant('SomeClass', 'OTHER_OLD_CONSTANT', 'DifferentClass::NEW_CONSTANT'),
new RenameClassConstFetch('SomeClass', 'OLD_CONSTANT', 'NEW_CONSTANT'),
new RenameClassAndConstFetch('SomeClass', 'OTHER_OLD_CONSTANT', 'DifferentClass', 'NEW_CONSTANT'),
],
];
@ -73,7 +74,7 @@ CODE_SAMPLE
*/
public function refactor(Node $node): ?Node
{
foreach ($this->classConstantRenames as $classConstantRename) {
foreach ($this->renameClassConstFetches as $classConstantRename) {
if (! $this->isObjectType($node, $classConstantRename->getOldClass())) {
continue;
}
@ -82,8 +83,8 @@ CODE_SAMPLE
continue;
}
if (Strings::contains($classConstantRename->getNewConstant(), '::')) {
return $this->createClassConstantFetchNodeFromDoubleColonFormat($classConstantRename->getNewConstant());
if ($classConstantRename instanceof RenameClassAndConstFetch) {
return $this->createClassAndConstFetch($classConstantRename);
}
$node->name = new Identifier($classConstantRename->getNewConstant());
@ -95,19 +96,21 @@ CODE_SAMPLE
}
/**
* @param mixed[] $configuration
* @param array<string, RenameClassConstFetchInterface[]> $configuration
*/
public function configure(array $configuration): void
{
$classConstantRenames = $configuration[self::CLASS_CONSTANT_RENAME] ?? [];
Assert::allIsInstanceOf($classConstantRenames, RenameClassConstant::class);
$this->classConstantRenames = $classConstantRenames;
$renameClassConstFetches = $configuration[self::CLASS_CONSTANT_RENAME] ?? [];
Assert::allIsInstanceOf($renameClassConstFetches, RenameClassConstFetchInterface::class);
$this->renameClassConstFetches = $renameClassConstFetches;
}
private function createClassConstantFetchNodeFromDoubleColonFormat(string $constant): ClassConstFetch
private function createClassAndConstFetch(RenameClassAndConstFetch $renameClassAndConstFetch): ClassConstFetch
{
[$constantClass, $constantName] = explode('::', $constant);
return new ClassConstFetch(new FullyQualified($constantClass), new Identifier($constantName));
return new ClassConstFetch(
new FullyQualified($renameClassAndConstFetch->getNewClass()),
new Identifier($renameClassAndConstFetch->getNewConstant())
);
}
}

View File

@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
namespace Rector\Renaming\ValueObject;
use Rector\Renaming\Contract\RenameClassConstFetchInterface;
final class RenameClassAndConstFetch implements RenameClassConstFetchInterface
{
/**
* @var string
*/
private $oldClass;
/**
* @var string
*/
private $oldConstant;
/**
* @var string
*/
private $newConstant;
/**
* @var string
*/
private $newClass;
public function __construct(string $oldClass, string $oldConstant, string $newClass, string $newConstant)
{
$this->oldClass = $oldClass;
$this->oldConstant = $oldConstant;
$this->newConstant = $newConstant;
$this->newClass = $newClass;
}
public function getOldClass(): string
{
return $this->oldClass;
}
public function getOldConstant(): string
{
return $this->oldConstant;
}
public function getNewConstant(): string
{
return $this->newConstant;
}
public function getNewClass(): string
{
return $this->newClass;
}
}

View File

@ -4,7 +4,9 @@ declare(strict_types=1);
namespace Rector\Renaming\ValueObject;
final class RenameClassConstant
use Rector\Renaming\Contract\RenameClassConstFetchInterface;
final class RenameClassConstFetch implements RenameClassConstFetchInterface
{
/**
* @var string

View File

@ -1,8 +1,8 @@
<?php
namespace Rector\Renaming\Tests\Rector\ClassConstFetch\RenameClassConstantRector\Fixture;
namespace Rector\Renaming\Tests\Rector\ClassConstFetch\RenameClassConstFetchRector\Fixture;
use Rector\Renaming\Tests\Rector\ClassConstFetch\RenameClassConstantRector\Source\LocalFormEvents;
use Rector\Renaming\Tests\Rector\ClassConstFetch\RenameClassConstFetchRector\Source\LocalFormEvents;
class SomeClass
{
@ -20,9 +20,9 @@ class SomeClass
-----
<?php
namespace Rector\Renaming\Tests\Rector\ClassConstFetch\RenameClassConstantRector\Fixture;
namespace Rector\Renaming\Tests\Rector\ClassConstFetch\RenameClassConstFetchRector\Fixture;
use Rector\Renaming\Tests\Rector\ClassConstFetch\RenameClassConstantRector\Source\LocalFormEvents;
use Rector\Renaming\Tests\Rector\ClassConstFetch\RenameClassConstFetchRector\Source\LocalFormEvents;
class SomeClass
{
@ -31,7 +31,7 @@ class SomeClass
return [
LocalFormEvents::PRE_SUBMIT,
LocalFormEvents::PRE_SUBMIT,
\Rector\Renaming\Tests\Rector\ClassConstFetch\RenameClassConstantRector\Source\DifferentClass::NEW_CONSTANT,
\Rector\Renaming\Tests\Rector\ClassConstFetch\RenameClassConstFetchRector\Source\DifferentClass::NEW_CONSTANT,
];
}
}

View File

@ -2,17 +2,18 @@
declare(strict_types=1);
namespace Rector\Renaming\Tests\Rector\ClassConstFetch\RenameClassConstantRector;
namespace Rector\Renaming\Tests\Rector\ClassConstFetch\RenameClassConstFetchRector;
use Iterator;
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstantRector;
use Rector\Renaming\Tests\Rector\ClassConstFetch\RenameClassConstantRector\Source\DifferentClass;
use Rector\Renaming\Tests\Rector\ClassConstFetch\RenameClassConstantRector\Source\LocalFormEvents;
use Rector\Renaming\ValueObject\RenameClassConstant;
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector;
use Rector\Renaming\Tests\Rector\ClassConstFetch\RenameClassConstFetchRector\Source\DifferentClass;
use Rector\Renaming\Tests\Rector\ClassConstFetch\RenameClassConstFetchRector\Source\LocalFormEvents;
use Rector\Renaming\ValueObject\RenameClassAndConstFetch;
use Rector\Renaming\ValueObject\RenameClassConstFetch;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class RenameClassConstantRectorTest extends AbstractRectorTestCase
final class RenameClassConstFetchRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
@ -33,15 +34,16 @@ final class RenameClassConstantRectorTest extends AbstractRectorTestCase
protected function getRectorsWithConfiguration(): array
{
return [
RenameClassConstantRector::class => [
RenameClassConstantRector::CLASS_CONSTANT_RENAME => [
new RenameClassConstant(LocalFormEvents::class, 'PRE_BIND', 'PRE_SUBMIT'),
new RenameClassConstant(LocalFormEvents::class, 'BIND', 'SUBMIT'),
new RenameClassConstant(LocalFormEvents::class, 'POST_BIND', 'POST_SUBMIT'),
new RenameClassConstant(
RenameClassConstFetchRector::class => [
RenameClassConstFetchRector::CLASS_CONSTANT_RENAME => [
new RenameClassConstFetch(LocalFormEvents::class, 'PRE_BIND', 'PRE_SUBMIT'),
new RenameClassConstFetch(LocalFormEvents::class, 'BIND', 'SUBMIT'),
new RenameClassConstFetch(LocalFormEvents::class, 'POST_BIND', 'POST_SUBMIT'),
new RenameClassAndConstFetch(
LocalFormEvents::class,
'OLD_CONSTANT',
DifferentClass::class . '::NEW_CONSTANT'
DifferentClass::class,
'NEW_CONSTANT'
),
],
],

View File

@ -1,6 +1,6 @@
<?php declare (strict_types=1);
namespace Rector\Renaming\Tests\Rector\ClassConstFetch\RenameClassConstantRector\Source;
namespace Rector\Renaming\Tests\Rector\ClassConstFetch\RenameClassConstFetchRector\Source;
final class DifferentClass
{

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Renaming\Tests\Rector\ClassConstFetch\RenameClassConstantRector\Source;
namespace Rector\Renaming\Tests\Rector\ClassConstFetch\RenameClassConstFetchRector\Source;
final class LocalFormEvents
{

View File

@ -0,0 +1,110 @@
<?php
declare(strict_types=1);
namespace Rector\Transform\Rector\New_;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\New_;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Transform\ValueObject\NewArgToMethodCall;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;
/**
* @see https://github.com/symfony/symfony/pull/35308
*
* @see \Rector\Transform\Tests\Rector\New_\NewArgToMethodCallRector\NewArgToMethodCallRectorTest
*/
final class NewArgToMethodCallRector extends AbstractRector implements ConfigurableRectorInterface
{
/**
* @var string
*/
public const NEW_ARGS_TO_METHOD_CALLS = 'new_args_to_method_calls';
/**
* @var NewArgToMethodCall[]
*/
private $newArgsToMethodCalls = [];
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Change new with specific argument to method call', [
new ConfiguredCodeSample(
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
{
$dotenv = new Dotenv(true);
}
}
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
{
$dotenv = new Dotenv();
$dotenv->usePutenv();
}
}
CODE_SAMPLE
,
[
self::NEW_ARGS_TO_METHOD_CALLS => [new NewArgToMethodCall('Dotenv', true, 'usePutenv')],
]
),
]);
}
/**
* @return string[]
*/
public function getNodeTypes(): array
{
return [New_::class];
}
/**
* @param New_ $node
*/
public function refactor(Node $node): ?Node
{
foreach ($this->newArgsToMethodCalls as $newArgToMethodCall) {
if (! $this->isObjectType($node->class, $newArgToMethodCall->getType())) {
continue;
}
if (! isset($node->args[0])) {
return null;
}
$firstArgValue = $node->args[0]->value;
if (! $this->isValue($firstArgValue, $newArgToMethodCall->getValue())) {
continue;
}
unset($node->args[0]);
return new MethodCall($node, 'usePutenv');
}
return null;
}
/**
* @param array<string, NewArgToMethodCall[]> $configuration
*/
public function configure(array $configuration): void
{
$newArgsToMethodCalls = $configuration[self::NEW_ARGS_TO_METHOD_CALLS] ?? [];
Assert::allIsInstanceOf($newArgsToMethodCalls, NewArgToMethodCall::class);
$this->newArgsToMethodCalls = $newArgsToMethodCalls;
}
}

View File

@ -0,0 +1,106 @@
<?php
declare(strict_types=1);
namespace Rector\Transform\Rector\StaticCall;
use PhpParser\Node;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Name\FullyQualified;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Transform\ValueObject\StaticCallToNew;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see https://github.com/symfony/symfony/pull/35308
*
* @see \Rector\Transform\Tests\Rector\StaticCall\StaticCallToNewRector\StaticCallToNewRectorTest
*/
final class StaticCallToNewRector extends AbstractRector implements ConfigurableRectorInterface
{
/**
* @var string
*/
public const STATIC_CALLS_TO_NEWS = 'static_calls_to_news';
/**
* @var StaticCallToNew[]
*/
private $staticCallsToNews = [];
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Change static call to new instance', [
new ConfiguredCodeSample(
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
{
$dotenv = JsonResponse::create(true);
}
}
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
{
$dotenv = new JsonResponse();
}
}
CODE_SAMPLE
,
[
self::STATIC_CALLS_TO_NEWS => [new StaticCallToNew('JsonResponse', 'create')],
]
),
]);
}
/**
* @return string[]
*/
public function getNodeTypes(): array
{
return [StaticCall::class];
}
/**
* @param Node\Expr\StaticCall $node
*/
public function refactor(Node $node): ?Node
{
foreach ($this->staticCallsToNews as $staticCallToNew) {
if (! $this->isName($node->class, $staticCallToNew->getClass())) {
continue;
}
if (! $this->isName($node->name, $staticCallToNew->getMethod())) {
continue;
}
$class = $this->getName($node->class);
if ($class === null) {
continue;
}
return new New_(new FullyQualified($class));
}
return $node;
}
/**
* @param array<string, StaticCallToNew[]> $configuration
*/
public function configure(array $configuration): void
{
$staticCallsToNews = $configuration[self::STATIC_CALLS_TO_NEWS] ?? [];
$this->staticCallsToNews = $staticCallsToNews;
}
}

View File

@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace Rector\Transform\ValueObject;
final class NewArgToMethodCall
{
/**
* @var string
*/
private $type;
/**
* @var mixed
*/
private $value;
/**
* @var string
*/
private $methodCall;
/**
* @param mixed $value
*/
public function __construct(string $type, $value, string $methodCall)
{
$this->type = $type;
$this->value = $value;
$this->methodCall = $methodCall;
}
public function getType(): string
{
return $this->type;
}
/**
* @return mixed
*/
public function getValue()
{
return $this->value;
}
public function getMethodCall(): string
{
return $this->methodCall;
}
}

View File

@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace Rector\Transform\ValueObject;
final class StaticCallToNew
{
/**
* @var string
*/
private $class;
/**
* @var string
*/
private $method;
public function __construct(string $class, string $method)
{
$this->class = $class;
$this->method = $method;
}
public function getClass(): string
{
return $this->class;
}
public function getMethod(): string
{
return $this->method;
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace Rector\Transform\Tests\Rector\New_\NewArgToMethodCallRector\Fixture;
use Rector\Transform\Tests\Rector\New_\NewArgToMethodCallRector\Source\SomeDotenv;
class SomeClass
{
public function run()
{
$dotenv = new SomeDotenv(true);
}
}
?>
-----
<?php
namespace Rector\Transform\Tests\Rector\New_\NewArgToMethodCallRector\Fixture;
use Rector\Transform\Tests\Rector\New_\NewArgToMethodCallRector\Source\SomeDotenv;
class SomeClass
{
public function run()
{
$dotenv = (new SomeDotenv())->usePutenv();
}
}
?>

View File

@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace Rector\Transform\Tests\Rector\New_\NewArgToMethodCallRector;
use Iterator;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Transform\Rector\New_\NewArgToMethodCallRector;
use Rector\Transform\Tests\Rector\New_\NewArgToMethodCallRector\Source\SomeDotenv;
use Rector\Transform\ValueObject\NewArgToMethodCall;
use Symplify\SmartFileSystem\SmartFileInfo;
final class NewArgToMethodCallRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
/**
* @return mixed[]
*/
protected function getRectorsWithConfiguration(): array
{
return [
NewArgToMethodCallRector::class => [
NewArgToMethodCallRector::NEW_ARGS_TO_METHOD_CALLS => [
new NewArgToMethodCall(SomeDotenv::class, true, 'usePutenv'),
],
],
];
}
}

View File

@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace Rector\Transform\Tests\Rector\New_\NewArgToMethodCallRector\Source;
final class SomeDotenv
{
public function __construct($value)
{
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace Rector\Transform\Tests\Rector\StaticCall\StaticCallToNewRector\Fixture;
use Rector\Transform\Tests\Rector\StaticCall\StaticCallToNewRector\Source\SomeJsonResponse;
class SomeClass
{
public function run()
{
$dotenv = SomeJsonResponse::create(true);
}
}
?>
-----
<?php
namespace Rector\Transform\Tests\Rector\StaticCall\StaticCallToNewRector\Fixture;
use Rector\Transform\Tests\Rector\StaticCall\StaticCallToNewRector\Source\SomeJsonResponse;
class SomeClass
{
public function run()
{
$dotenv = new \Rector\Transform\Tests\Rector\StaticCall\StaticCallToNewRector\Source\SomeJsonResponse();
}
}
?>

View File

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Rector\Transform\Tests\Rector\StaticCall\StaticCallToNewRector\Source;
final class SomeJsonResponse
{
}

View File

@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace Rector\Transform\Tests\Rector\StaticCall\StaticCallToNewRector;
use Iterator;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Transform\Rector\StaticCall\StaticCallToNewRector;
use Rector\Transform\Tests\Rector\StaticCall\StaticCallToNewRector\Source\SomeJsonResponse;
use Rector\Transform\ValueObject\StaticCallToNew;
use Symplify\SmartFileSystem\SmartFileInfo;
final class StaticCallToNewRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
/**
* @return mixed[]
*/
protected function getRectorsWithConfiguration(): array
{
return [
StaticCallToNewRector::class =>
[
StaticCallToNewRector::STATIC_CALLS_TO_NEWS => [
new StaticCallToNew(SomeJsonResponse::class, 'create'),
],
],
];
}
}