[phpstan] Add rule for complex config (#4015)

* [phpstan] Add ForbiddenComplexArrayConfigInSetRule

* add MethodCallRename value object

* [SymfonyPhpConfig] Add array to value object configuration rule

* apply first MethodCallRename value object
This commit is contained in:
Tomas Votruba 2020-08-25 00:26:14 +02:00 committed by GitHub
parent de4748f935
commit c1653070f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
74 changed files with 1915 additions and 819 deletions

View File

@ -279,7 +279,10 @@
],
"check-cs": "vendor/bin/ecs check --ansi",
"fix-cs": "vendor/bin/ecs check --fix --ansi",
"phpstan": "vendor/bin/phpstan analyse --ansi --error-format symplify",
"phpstan": [
"vendor/bin/phpstan analyse --ansi --error-format symplify",
"vendor/bin/phpstan analyse config/set --ansi --error-format symplify"
],
"changelog": [
"vendor/bin/changelog-linker dump-merges --in-categories --ansi",
"vendor/bin/changelog-linker link --ansi",

View File

@ -9,6 +9,8 @@ use Rector\Generic\Rector\ClassMethod\NormalToFluentRector;
use Rector\Generic\Rector\PropertyFetch\RenamePropertyRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
@ -264,63 +266,50 @@ return static function (ContainerConfigurator $containerConfigurator): void {
],
]]);
$configuration = [
new MethodCallRename('Cake\Network\Request', 'param', 'getParam'),
new MethodCallRename('Cake\Network\Request', 'data', 'getData'),
new MethodCallRename('Cake\Network\Request', 'query', 'getQuery'),
new MethodCallRename('Cake\Network\Request', 'cookie', 'getCookie'),
new MethodCallRename('Cake\Network\Request', 'method', 'getMethod'),
new MethodCallRename('Cake\Network\Request', 'setInput', 'withBody'),
new MethodCallRename('Cake\Network\Response', 'location', 'withLocation'),
new MethodCallRename('Cake\Network\Response', 'disableCache', 'withDisabledCache'),
new MethodCallRename('Cake\Network\Response', 'type', 'withType'),
new MethodCallRename('Cake\Network\Response', 'charset', 'withCharset'),
new MethodCallRename('Cake\Network\Response', 'cache', 'withCache'),
new MethodCallRename('Cake\Network\Response', 'modified', 'withModified'),
new MethodCallRename('Cake\Network\Response', 'expires', 'withExpires'),
new MethodCallRename('Cake\Network\Response', 'sharable', 'withSharable'),
new MethodCallRename('Cake\Network\Response', 'maxAge', 'withMaxAge'),
new MethodCallRename('Cake\Network\Response', 'vary', 'withVary'),
new MethodCallRename('Cake\Network\Response', 'etag', 'withEtag'),
new MethodCallRename('Cake\Network\Response', 'compress', 'withCompression'),
new MethodCallRename('Cake\Network\Response', 'length', 'withLength'),
new MethodCallRename('Cake\Network\Response', 'mustRevalidate', 'withMustRevalidate'),
new MethodCallRename('Cake\Network\Response', 'notModified', 'withNotModified'),
new MethodCallRename('Cake\Network\Response', 'cookie', 'withCookie'),
new MethodCallRename('Cake\Network\Response', 'file', 'withFile'),
new MethodCallRename('Cake\Network\Response', 'download', 'withDownload'),
# psr-7
new MethodCallRename('Cake\Network\Response', 'header', 'getHeader'),
new MethodCallRename('Cake\Network\Response', 'body', 'withBody'),
new MethodCallRename('Cake\Network\Response', 'statusCode', 'getStatusCode'),
new MethodCallRename('Cake\Network\Response', 'protocol', 'getProtocolVersion'),
new MethodCallRename('Cake\Event\Event', 'name', 'getName'),
new MethodCallRename('Cake\Event\Event', 'subject', 'getSubject'),
new MethodCallRename('Cake\Event\Event', 'result', 'getResult'),
new MethodCallRename('Cake\Event\Event', 'data', 'getData'),
new MethodCallRename('Cake\View\Helper\FormHelper', 'input', 'control'),
new MethodCallRename('Cake\View\Helper\FormHelper', 'inputs', 'controls'),
new MethodCallRename('Cake\View\Helper\FormHelper', 'allInputs', 'allControls'),
new MethodCallRename('Cake\Mailer\Mailer', 'layout', 'setLayout'),
new MethodCallRename('Cake\Routing\Route\Route', 'parse', 'parseRequest'),
new MethodCallRename('Cake\Routing\Router', 'parse', 'parseRequest'),
];
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Cake\Network\Request' => [
'param' => 'getParam',
'data' => 'getData',
'query' => 'getQuery',
'cookie' => 'getCookie',
'method' => 'getMethod',
'setInput' => 'withBody',
],
'Cake\Network\Response' => [
'location' => 'withLocation',
'disableCache' => 'withDisabledCache',
'type' => 'withType',
'charset' => 'withCharset',
'cache' => 'withCache',
'modified' => 'withModified',
'expires' => 'withExpires',
'sharable' => 'withSharable',
'maxAge' => 'withMaxAge',
'vary' => 'withVary',
'etag' => 'withEtag',
'compress' => 'withCompression',
'length' => 'withLength',
'mustRevalidate' => 'withMustRevalidate',
'notModified' => 'withNotModified',
'cookie' => 'withCookie',
'file' => 'withFile',
'download' => 'withDownload',
# psr-7
'header' => 'getHeader',
'body' => 'withBody',
'statusCode' => 'getStatusCode',
'protocol' => 'getProtocolVersion',
],
'Cake\Event\Event' => [
'name' => 'getName',
'subject' => 'getSubject',
'result' => 'getResult',
'data' => 'getData',
],
'Cake\View\Helper\FormHelper' => [
'input' => 'control',
'inputs' => 'controls',
'allInputs' => 'allControls',
],
'Cake\Mailer\Mailer' => [
'layout' => 'setLayout',
],
'Cake\Routing\Route\Route' => [
'parse' => 'parseRequest',
],
'Cake\Routing\Router' => [
'parse' => 'parseRequest',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects($configuration),
]]);
$services->set(ChangeMethodVisibilityRector::class)

View File

@ -5,6 +5,8 @@ declare(strict_types=1);
use Rector\CakePHP\Rector\MethodCall\ModalToGetSetRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
# source: https://book.cakephp.org/3.0/en/appendices/3-5-migration-guide.html
@ -21,13 +23,11 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Cake\Database\Schema\TableSchema' => [
'column' => 'getColumn',
'constraint' => 'getConstraint',
'index' => 'getIndex',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('Cake\Database\Schema\TableSchema', 'column', 'getColumn'),
new MethodCallRename('Cake\Database\Schema\TableSchema', 'constraint', 'getConstraint'),
new MethodCallRename('Cake\Database\Schema\TableSchema', 'index', 'getIndex'),
]),
]]);
$services->set(ModalToGetSetRector::class)

View File

@ -5,6 +5,8 @@ declare(strict_types=1);
use Rector\Generic\Rector\Assign\PropertyToMethodRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
@ -13,15 +15,11 @@ return static function (ContainerConfigurator $containerConfigurator): void {
# source: https://book.cakephp.org/3.0/en/appendices/3-6-migration-guide.html
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Cake\ORM\Table' => [
'association' => 'getAssociation',
],
'Cake\Validation\ValidationSet' => [
'isPresenceRequired' => 'requirePresence',
'isEmptyAllowed' => 'allowEmpty',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('Cake\ORM\Table', 'association', 'getAssociation'),
new MethodCallRename('Cake\Validation\ValidationSet', 'isPresenceRequired', 'requirePresence'),
new MethodCallRename('Cake\Validation\ValidationSet', 'isEmptyAllowed', 'allowEmpty'),
]),
]]);
$services->set(PropertyToMethodRector::class)

View File

@ -7,6 +7,8 @@ use Rector\CakePHP\Rector\Property\ChangeSnakedFixtureNameToCamelRector;
use Rector\Generic\Rector\Assign\PropertyToMethodRector;
use Rector\Generic\Rector\MethodCall\MethodCallToAnotherMethodCallWithArgumentsRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
# source: https://book.cakephp.org/3.0/en/appendices/3-7-migration-guide.html
@ -15,23 +17,13 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Cake\Form\Form' => [
'errors' => 'getErrors',
],
'Cake\Validation\Validation' => [
'cc' => 'creditCard',
],
'Cake\Filesystem\Folder' => [
'normalizePath' => 'correctSlashFor',
],
'Cake\Http\Client\Response' => [
'body' => 'getStringBody',
],
'Cake\Core\Plugin' => [
'unload' => 'clear',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('Cake\Form\Form', 'errors', 'getErrors'),
new MethodCallRename('Cake\Validation\Validation', 'cc', 'creditCard'),
new MethodCallRename('Cake\Filesystem\Folder', 'normalizePath', 'correctSlashFor'),
new MethodCallRename('Cake\Http\Client\Response', 'body', 'getStringBody'),
new MethodCallRename('Cake\Core\Plugin', 'unload', 'clear'),
]),
]]);
$services->set(PropertyToMethodRector::class)

View File

@ -3,6 +3,8 @@
declare(strict_types=1);
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
# source: https://book.cakephp.org/3.0/en/appendices/3-8-migration-guide.html
@ -12,10 +14,8 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Cake\ORM\Entity' => [
'visibleProperties' => 'getVisible',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('Cake\ORM\Entity', 'visibleProperties', 'getVisible'),
]),
]]);
};

View File

@ -10,6 +10,7 @@ use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstantRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\Rector\StaticCall\RenameStaticMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\StaticCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector;
@ -46,27 +47,15 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Cake\Form\Form' => [
'errors' => 'getErrors',
],
'Cake\Mailer\Email' => [
'set' => 'setViewVars',
],
'Cake\ORM\EntityInterface' => [
'unsetProperty' => 'unset',
],
'Cake\Cache\Cache' => [
'engine' => 'pool',
],
'Cake\Http\Cookie\Cookie' => [
'getStringValue' => 'getScalarValue',
],
'Cake\Validation\Validator' => [
'containsNonAlphaNumeric' => 'notAlphaNumeric',
'errors' => 'validate',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('Cake\Form\Form', 'errors', 'getErrors'),
new MethodCallRename('Cake\Mailer\Email', 'set', 'setViewVars'),
new MethodCallRename('Cake\ORM\EntityInterface', 'unsetProperty', 'unset'),
new MethodCallRename('Cake\Cache\Cache', 'engine', 'pool'),
new MethodCallRename('Cake\Http\Cookie\Cookie', 'getStringValue', 'getScalarValue'),
new MethodCallRename('Cake\Validation\Validator', 'containsNonAlphaNumeric', 'notAlphaNumeric'),
new MethodCallRename('Cake\Validation\Validator', 'errors', 'validate'),
]),
]]);
$configuration = [

View File

@ -5,6 +5,8 @@ declare(strict_types=1);
use Rector\CakePHP\Rector\MethodCall\ModalToGetSetRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
@ -20,24 +22,18 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Cake\Database\Schema\TableSchema' => [
'getPrimary' => 'getPrimaryKey',
],
'Cake\Database\Type\DateTimeType' => [
'setTimezone' => 'setDatabaseTimezone',
],
'Cake\Database\Expression\QueryExpression' => [
'or_' => 'or',
'and_' => 'and',
],
'Cake\View\Form\ContextInterface' => [
'primaryKey' => 'getPrimaryKey',
],
'Cake\Http\Middleware\CsrfProtectionMiddleware' => [
'whitelistCallback' => 'skipCheckCallback',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('Cake\Database\Schema\TableSchema', 'getPrimary', 'getPrimaryKey'),
new MethodCallRename('Cake\Database\Type\DateTimeType', 'setTimezone', 'setDatabaseTimezone'),
new MethodCallRename('Cake\Database\Expression\QueryExpression', 'or_', 'or'),
new MethodCallRename('Cake\Database\Expression\QueryExpression', 'and_', 'and'),
new MethodCallRename('Cake\View\Form\ContextInterface', 'primaryKey', 'getPrimaryKey'),
new MethodCallRename(
'Cake\Http\Middleware\CsrfProtectionMiddleware',
'whitelistCallback',
'skipCheckCallback'
),
]),
]]);
$services->set(ModalToGetSetRector::class)

View File

@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
use Rector\Architecture\Rector\Class_\ConstructorInjectionToActionInjectionRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(ConstructorInjectionToActionInjectionRector::class);
};

View File

@ -3,12 +3,12 @@
declare(strict_types=1);
use Rector\Doctrine\Rector\Class_\ManagerRegistryGetManagerToEntityManagerRector;
use Rector\DoctrineCodeQuality\Rector\Class_\CorrectDefaultTypesOnEntityPropertyRector;
use Rector\DoctrineCodeQuality\Rector\Class_\InitializeDefaultEntityCollectionRector;
use Rector\DoctrineCodeQuality\Rector\Class_\MoveCurrentDateTimeDefaultInEntityToConstructorRector;
use Rector\DoctrineCodeQuality\Rector\ClassMethod\MakeEntityDateTimePropertyDateTimeInterfaceRector;
use Rector\DoctrineCodeQuality\Rector\ClassMethod\MakeEntitySetterNullabilityInSyncWithPropertyRector;
use Rector\DoctrineCodeQuality\Rector\Property\ChangeBigIntEntityPropertyToIntTypeRector;
use Rector\DoctrineCodeQuality\Rector\Property\CorrectDefaultTypesOnEntityPropertyRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
use Rector\Generic\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
# https://github.com/doctrine/dbal/blob/master/UPGRADE.md#bc-break-changes-in-handling-string-and-binary-columns
@ -12,14 +14,14 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'DBAL\Platforms\AbstractPlatform' => [
'getVarcharTypeDeclarationSQL' => 'getStringTypeDeclarationSQL',
],
'Doctrine\DBAL\Driver\DriverException' => [
'getErrorCode' => 'getCode',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename(
'DBAL\Platforms\AbstractPlatform',
'getVarcharTypeDeclarationSQL',
'getStringTypeDeclarationSQL'
),
new MethodCallRename('Doctrine\DBAL\Driver\DriverException', 'getErrorCode', 'getCode'),
]),
]]);
$services->set(AddReturnTypeDeclarationRector::class)

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
# https://www.php.net/manual/en/book.gmagick.php → https://www.php.net/manual/en/book.imagick.php
@ -20,151 +22,147 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Gmagick' => [
'addimage' => 'addImage',
'addnoiseimage' => 'addNoiseImage',
'annotateimage' => 'annotateImage',
'blurimage' => 'blurImage',
'borderimage' => 'borderImage',
'charcoalimage' => 'charcoalImage',
'chopimage' => 'chopImage',
'commentimage' => 'commentImage',
'compositeimage' => 'compositeImage',
'cropimage' => 'cropImage',
'cropthumbnailimage' => 'cropThumbnailImage',
'cyclecolormapimage' => 'cycleColormapImage',
'deconstructimages' => 'deconstructImages',
'despeckleimage' => 'despeckleImage',
'drawimage' => 'drawImage',
'edgeimage' => 'edgeImage',
'embossimage' => 'embossImage',
'enhanceimage' => 'enhanceImage',
'equalizeimage' => 'equalizeImage',
'flipimage' => 'flipImage',
'flopimage' => 'flopImage',
'frameimage' => 'frameImage',
'gammaimage' => 'gammaImage',
'getcopyright' => 'getCopyright',
'getfilename' => 'getFilename',
'getimagebackgroundcolor' => 'getImageBackgroundColor',
'getimageblueprimary' => 'getImageBluePrimary',
'getimagebordercolor' => 'getImageBorderColor',
'getimagechanneldepth' => 'getImageChannelDepth',
'getimagecolors' => 'getImageColors',
'getimagecolorspace' => 'getImageColorspace',
'getimagecompose' => 'getImageCompose',
'getimagedelay' => 'getImageDelay',
'getimagedepth' => 'getImageDepth',
'getimagedispose' => 'getImageDispose',
'getimageextrema' => 'getImageExtrema',
'getimagefilename' => 'getImageFilename',
'getimageformat' => 'getImageFormat',
'getimagegamma' => 'getImageGamma',
'getimagegreenprimary' => 'getImageGreenPrimary',
'getimageheight' => 'getImageHeight',
'getimagehistogram' => 'getImageHistogram',
'getimageindex' => 'getImageIndex',
'getimageinterlacescheme' => 'getImageInterlaceScheme',
'getimageiterations' => 'getImageIterations',
'getimagematte' => 'getImageMatte',
'getimagemattecolor' => 'getImageMatteColor',
'getimageprofile' => 'getImageProfile',
'getimageredprimary' => 'getImageRedPrimary',
'getimagerenderingintent' => 'getImageRenderingIntent',
'getimageresolution' => 'getImageResolution',
'getimagescene' => 'getImageScene',
'getimagesignature' => 'getImageSignature',
'getimagetype' => 'getImageType',
'getimageunits' => 'getImageUnits',
'getimagewhitepoint' => 'getImageWhitePoint',
'getimagewidth' => 'getImageWidth',
'getpackagename' => 'getPackageName',
'getquantumdepth' => 'getQuantumDepth',
'getreleasedate' => 'getReleaseDate',
'getsamplingfactors' => 'getSamplingFactors',
'getsize' => 'getSize',
'getversion' => 'getVersion',
'hasnextimage' => 'hasNextImage',
'haspreviousimage' => 'hasPreviousImage',
'implodeimage' => 'implodeImage',
'labelimage' => 'labelImage',
'levelimage' => 'levelImage',
'magnifyimage' => 'magnifyImage',
'mapimage' => 'mapImage',
'medianfilterimage' => 'medianFilterImage',
'minifyimage' => 'minifyImage',
'modulateimage' => 'modulateImage',
'motionblurimage' => 'motionBlurImage',
'newimage' => 'newImage',
'nextimage' => 'nextImage',
'normalizeimage' => 'normalizeImage',
'oilpaintimage' => 'oilPaintImage',
'previousimage' => 'previousImage',
'profileimage' => 'profileImage',
'quantizeimage' => 'quantizeImage',
'quantizeimages' => 'quantizeImages',
'queryfontmetrics' => 'queryFontMetrics',
'queryfonts' => 'queryFonts',
'queryformats' => 'queryFormats',
'radialblurimage' => 'radialBlurImage',
'raiseimage' => 'raiseImage',
'readimage' => 'readimages',
'readimageblob' => 'readImageBlob',
'readimagefile' => 'readImageFile',
'reducenoiseimage' => 'reduceNoiseImage',
'removeimage' => 'removeImage',
'removeimageprofile' => 'removeImageProfile',
'resampleimage' => 'resampleImage',
'resizeimage' => 'resizeImage',
'rollimage' => 'rollImage',
'rotateimage' => 'rotateImage',
'scaleimage' => 'scaleImage',
'separateimagechannel' => 'separateImageChannel',
'setCompressionQuality' => 'getCompressionQuality',
'setfilename' => 'setFilename',
'setimagebackgroundcolor' => 'setImageBackgroundColor',
'setimageblueprimary' => 'setImageBluePrimary',
'setimagebordercolor' => 'setImageBorderColor',
'setimagechanneldepth' => 'setImageChannelDepth',
'setimagecolorspace' => 'setImageColorspace',
'setimagecompose' => 'setImageCompose',
'setimagedelay' => 'setImageDelay',
'setimagedepth' => 'setImageDepth',
'setimagedispose' => 'setImageDispose',
'setimagefilename' => 'setImageFilename',
'setimageformat' => 'setImageFormat',
'setimagegamma' => 'setImageGamma',
'setimagegreenprimary' => 'setImageGreenPrimary',
'setimageindex' => 'setImageIndex',
'setimageinterlacescheme' => 'setImageInterlaceScheme',
'setimageiterations' => 'setImageIterations',
'setimageprofile' => 'setImageProfile',
'setimageredprimary' => 'setImageRedPrimary',
'setimagerenderingintent' => 'setImageRenderingIntent',
'setimageresolution' => 'setImageResolution',
'setimagescene' => 'setImageScene',
'setimagetype' => 'setImageType',
'setimageunits' => 'setImageUnits',
'setimagewhitepoint' => 'setImageWhitePoint',
'setsamplingfactors' => 'setSamplingFactors',
'setsize' => 'setSize',
'shearimage' => 'shearImage',
'solarizeimage' => 'solarizeImage',
'spreadimage' => 'spreadImage',
'stripimage' => 'stripImage',
'swirlimage' => 'swirlImage',
'thumbnailimage' => 'thumbnailImage',
'trimimage' => 'trimImage',
'writeimage' => 'writeImage',
],
'GmagickPixel' => [
'getcolor' => 'getColor',
'getcolorcount' => 'getColorCount',
'getcolorvalue' => 'getColorValue',
'setcolor' => 'setColor',
'setcolorvalue' => 'setColorValue',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('Gmagick', 'addimage', 'addImage'),
new MethodCallRename('Gmagick', 'addnoiseimage', 'addNoiseImage'),
new MethodCallRename('Gmagick', 'annotateimage', 'annotateImage'),
new MethodCallRename('Gmagick', 'blurimage', 'blurImage'),
new MethodCallRename('Gmagick', 'borderimage', 'borderImage'),
new MethodCallRename('Gmagick', 'charcoalimage', 'charcoalImage'),
new MethodCallRename('Gmagick', 'chopimage', 'chopImage'),
new MethodCallRename('Gmagick', 'commentimage', 'commentImage'),
new MethodCallRename('Gmagick', 'compositeimage', 'compositeImage'),
new MethodCallRename('Gmagick', 'cropimage', 'cropImage'),
new MethodCallRename('Gmagick', 'cropthumbnailimage', 'cropThumbnailImage'),
new MethodCallRename('Gmagick', 'cyclecolormapimage', 'cycleColormapImage'),
new MethodCallRename('Gmagick', 'deconstructimages', 'deconstructImages'),
new MethodCallRename('Gmagick', 'despeckleimage', 'despeckleImage'),
new MethodCallRename('Gmagick', 'drawimage', 'drawImage'),
new MethodCallRename('Gmagick', 'edgeimage', 'edgeImage'),
new MethodCallRename('Gmagick', 'embossimage', 'embossImage'),
new MethodCallRename('Gmagick', 'enhanceimage', 'enhanceImage'),
new MethodCallRename('Gmagick', 'equalizeimage', 'equalizeImage'),
new MethodCallRename('Gmagick', 'flipimage', 'flipImage'),
new MethodCallRename('Gmagick', 'flopimage', 'flopImage'),
new MethodCallRename('Gmagick', 'frameimage', 'frameImage'),
new MethodCallRename('Gmagick', 'gammaimage', 'gammaImage'),
new MethodCallRename('Gmagick', 'getcopyright', 'getCopyright'),
new MethodCallRename('Gmagick', 'getfilename', 'getFilename'),
new MethodCallRename('Gmagick', 'getimagebackgroundcolor', 'getImageBackgroundColor'),
new MethodCallRename('Gmagick', 'getimageblueprimary', 'getImageBluePrimary'),
new MethodCallRename('Gmagick', 'getimagebordercolor', 'getImageBorderColor'),
new MethodCallRename('Gmagick', 'getimagechanneldepth', 'getImageChannelDepth'),
new MethodCallRename('Gmagick', 'getimagecolors', 'getImageColors'),
new MethodCallRename('Gmagick', 'getimagecolorspace', 'getImageColorspace'),
new MethodCallRename('Gmagick', 'getimagecompose', 'getImageCompose'),
new MethodCallRename('Gmagick', 'getimagedelay', 'getImageDelay'),
new MethodCallRename('Gmagick', 'getimagedepth', 'getImageDepth'),
new MethodCallRename('Gmagick', 'getimagedispose', 'getImageDispose'),
new MethodCallRename('Gmagick', 'getimageextrema', 'getImageExtrema'),
new MethodCallRename('Gmagick', 'getimagefilename', 'getImageFilename'),
new MethodCallRename('Gmagick', 'getimageformat', 'getImageFormat'),
new MethodCallRename('Gmagick', 'getimagegamma', 'getImageGamma'),
new MethodCallRename('Gmagick', 'getimagegreenprimary', 'getImageGreenPrimary'),
new MethodCallRename('Gmagick', 'getimageheight', 'getImageHeight'),
new MethodCallRename('Gmagick', 'getimagehistogram', 'getImageHistogram'),
new MethodCallRename('Gmagick', 'getimageindex', 'getImageIndex'),
new MethodCallRename('Gmagick', 'getimageinterlacescheme', 'getImageInterlaceScheme'),
new MethodCallRename('Gmagick', 'getimageiterations', 'getImageIterations'),
new MethodCallRename('Gmagick', 'getimagematte', 'getImageMatte'),
new MethodCallRename('Gmagick', 'getimagemattecolor', 'getImageMatteColor'),
new MethodCallRename('Gmagick', 'getimageprofile', 'getImageProfile'),
new MethodCallRename('Gmagick', 'getimageredprimary', 'getImageRedPrimary'),
new MethodCallRename('Gmagick', 'getimagerenderingintent', 'getImageRenderingIntent'),
new MethodCallRename('Gmagick', 'getimageresolution', 'getImageResolution'),
new MethodCallRename('Gmagick', 'getimagescene', 'getImageScene'),
new MethodCallRename('Gmagick', 'getimagesignature', 'getImageSignature'),
new MethodCallRename('Gmagick', 'getimagetype', 'getImageType'),
new MethodCallRename('Gmagick', 'getimageunits', 'getImageUnits'),
new MethodCallRename('Gmagick', 'getimagewhitepoint', 'getImageWhitePoint'),
new MethodCallRename('Gmagick', 'getimagewidth', 'getImageWidth'),
new MethodCallRename('Gmagick', 'getpackagename', 'getPackageName'),
new MethodCallRename('Gmagick', 'getquantumdepth', 'getQuantumDepth'),
new MethodCallRename('Gmagick', 'getreleasedate', 'getReleaseDate'),
new MethodCallRename('Gmagick', 'getsamplingfactors', 'getSamplingFactors'),
new MethodCallRename('Gmagick', 'getsize', 'getSize'),
new MethodCallRename('Gmagick', 'getversion', 'getVersion'),
new MethodCallRename('Gmagick', 'hasnextimage', 'hasNextImage'),
new MethodCallRename('Gmagick', 'haspreviousimage', 'hasPreviousImage'),
new MethodCallRename('Gmagick', 'implodeimage', 'implodeImage'),
new MethodCallRename('Gmagick', 'labelimage', 'labelImage'),
new MethodCallRename('Gmagick', 'levelimage', 'levelImage'),
new MethodCallRename('Gmagick', 'magnifyimage', 'magnifyImage'),
new MethodCallRename('Gmagick', 'mapimage', 'mapImage'),
new MethodCallRename('Gmagick', 'medianfilterimage', 'medianFilterImage'),
new MethodCallRename('Gmagick', 'minifyimage', 'minifyImage'),
new MethodCallRename('Gmagick', 'modulateimage', 'modulateImage'),
new MethodCallRename('Gmagick', 'motionblurimage', 'motionBlurImage'),
new MethodCallRename('Gmagick', 'newimage', 'newImage'),
new MethodCallRename('Gmagick', 'nextimage', 'nextImage'),
new MethodCallRename('Gmagick', 'normalizeimage', 'normalizeImage'),
new MethodCallRename('Gmagick', 'oilpaintimage', 'oilPaintImage'),
new MethodCallRename('Gmagick', 'previousimage', 'previousImage'),
new MethodCallRename('Gmagick', 'profileimage', 'profileImage'),
new MethodCallRename('Gmagick', 'quantizeimage', 'quantizeImage'),
new MethodCallRename('Gmagick', 'quantizeimages', 'quantizeImages'),
new MethodCallRename('Gmagick', 'queryfontmetrics', 'queryFontMetrics'),
new MethodCallRename('Gmagick', 'queryfonts', 'queryFonts'),
new MethodCallRename('Gmagick', 'queryformats', 'queryFormats'),
new MethodCallRename('Gmagick', 'radialblurimage', 'radialBlurImage'),
new MethodCallRename('Gmagick', 'raiseimage', 'raiseImage'),
new MethodCallRename('Gmagick', 'readimage', 'readimages'),
new MethodCallRename('Gmagick', 'readimageblob', 'readImageBlob'),
new MethodCallRename('Gmagick', 'readimagefile', 'readImageFile'),
new MethodCallRename('Gmagick', 'reducenoiseimage', 'reduceNoiseImage'),
new MethodCallRename('Gmagick', 'removeimage', 'removeImage'),
new MethodCallRename('Gmagick', 'removeimageprofile', 'removeImageProfile'),
new MethodCallRename('Gmagick', 'resampleimage', 'resampleImage'),
new MethodCallRename('Gmagick', 'resizeimage', 'resizeImage'),
new MethodCallRename('Gmagick', 'rollimage', 'rollImage'),
new MethodCallRename('Gmagick', 'rotateimage', 'rotateImage'),
new MethodCallRename('Gmagick', 'scaleimage', 'scaleImage'),
new MethodCallRename('Gmagick', 'separateimagechannel', 'separateImageChannel'),
new MethodCallRename('Gmagick', 'setCompressionQuality', 'getCompressionQuality'),
new MethodCallRename('Gmagick', 'setfilename', 'setFilename'),
new MethodCallRename('Gmagick', 'setimagebackgroundcolor', 'setImageBackgroundColor'),
new MethodCallRename('Gmagick', 'setimageblueprimary', 'setImageBluePrimary'),
new MethodCallRename('Gmagick', 'setimagebordercolor', 'setImageBorderColor'),
new MethodCallRename('Gmagick', 'setimagechanneldepth', 'setImageChannelDepth'),
new MethodCallRename('Gmagick', 'setimagecolorspace', 'setImageColorspace'),
new MethodCallRename('Gmagick', 'setimagecompose', 'setImageCompose'),
new MethodCallRename('Gmagick', 'setimagedelay', 'setImageDelay'),
new MethodCallRename('Gmagick', 'setimagedepth', 'setImageDepth'),
new MethodCallRename('Gmagick', 'setimagedispose', 'setImageDispose'),
new MethodCallRename('Gmagick', 'setimagefilename', 'setImageFilename'),
new MethodCallRename('Gmagick', 'setimageformat', 'setImageFormat'),
new MethodCallRename('Gmagick', 'setimagegamma', 'setImageGamma'),
new MethodCallRename('Gmagick', 'setimagegreenprimary', 'setImageGreenPrimary'),
new MethodCallRename('Gmagick', 'setimageindex', 'setImageIndex'),
new MethodCallRename('Gmagick', 'setimageinterlacescheme', 'setImageInterlaceScheme'),
new MethodCallRename('Gmagick', 'setimageiterations', 'setImageIterations'),
new MethodCallRename('Gmagick', 'setimageprofile', 'setImageProfile'),
new MethodCallRename('Gmagick', 'setimageredprimary', 'setImageRedPrimary'),
new MethodCallRename('Gmagick', 'setimagerenderingintent', 'setImageRenderingIntent'),
new MethodCallRename('Gmagick', 'setimageresolution', 'setImageResolution'),
new MethodCallRename('Gmagick', 'setimagescene', 'setImageScene'),
new MethodCallRename('Gmagick', 'setimagetype', 'setImageType'),
new MethodCallRename('Gmagick', 'setimageunits', 'setImageUnits'),
new MethodCallRename('Gmagick', 'setimagewhitepoint', 'setImageWhitePoint'),
new MethodCallRename('Gmagick', 'setsamplingfactors', 'setSamplingFactors'),
new MethodCallRename('Gmagick', 'setsize', 'setSize'),
new MethodCallRename('Gmagick', 'shearimage', 'shearImage'),
new MethodCallRename('Gmagick', 'solarizeimage', 'solarizeImage'),
new MethodCallRename('Gmagick', 'spreadimage', 'spreadImage'),
new MethodCallRename('Gmagick', 'stripimage', 'stripImage'),
new MethodCallRename('Gmagick', 'swirlimage', 'swirlImage'),
new MethodCallRename('Gmagick', 'thumbnailimage', 'thumbnailImage'),
new MethodCallRename('Gmagick', 'trimimage', 'trimImage'),
new MethodCallRename('Gmagick', 'writeimage', 'writeImage'),
new MethodCallRename('GmagickPixel', 'getcolor', 'getColor'),
new MethodCallRename('GmagickPixel', 'getcolorcount', 'getColorCount'),
new MethodCallRename('GmagickPixel', 'getcolorvalue', 'getColorValue'),
new MethodCallRename('GmagickPixel', 'setcolor', 'setColor'),
new MethodCallRename('GmagickPixel', 'setcolorvalue', 'setColorValue'),
]),
]]);
};

View File

@ -9,6 +9,7 @@ use Rector\Generic\ValueObject\FuncNameToMethodCallName;
use Rector\Guzzle\Rector\MethodCall\MessageAsArrayRector;
use Rector\MagicDisclosure\Rector\MethodCall\FluentChainMethodCallToNormalMethodCallRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
@ -57,10 +58,8 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'GuzzleHttp\Message\MessageInterface' => [
'getHeaderLines' => 'getHeaderAsArray',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('GuzzleHttp\Message\MessageInterface', 'getHeaderLines', 'getHeaderAsArray'),
]),
]]);
};

View File

@ -6,6 +6,8 @@ use Rector\Generic\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\NetteToSymfony\Rector\MethodCall\WrapTransParameterNameRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
@ -22,14 +24,10 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Kdyby\Translation\Translator' => [
'translate' => 'trans',
],
'Kdyby\RabbitMq\IConsumer' => [
'process' => 'execute',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('Kdyby\Translation\Translator', 'translate', 'trans'),
new MethodCallRename('Kdyby\RabbitMq\IConsumer', 'process', 'execute'),
]),
]]);
$services->set(RenameClassRector::class)

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
# see: https://laravel.com/docs/5.0/upgrade
@ -21,16 +23,14 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Illuminate\Contracts\Pagination\Paginator' => [
'links' => 'render',
'getFrom' => 'firstItem',
'getTo' => 'lastItem',
'getPerPage' => 'perPage',
'getCurrentPage' => 'currentPage',
'getLastPage' => 'lastPage',
'getTotal' => 'total',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('Illuminate\Contracts\Pagination\Paginator', 'links', 'render'),
new MethodCallRename('Illuminate\Contracts\Pagination\Paginator', 'getFrom', 'firstItem'),
new MethodCallRename('Illuminate\Contracts\Pagination\Paginator', 'getTo', 'lastItem'),
new MethodCallRename('Illuminate\Contracts\Pagination\Paginator', 'getPerPage', 'perPage'),
new MethodCallRename('Illuminate\Contracts\Pagination\Paginator', 'getCurrentPage', 'currentPage'),
new MethodCallRename('Illuminate\Contracts\Pagination\Paginator', 'getLastPage', 'lastPage'),
new MethodCallRename('Illuminate\Contracts\Pagination\Paginator', 'getTotal', 'total'),
]),
]]);
};

View File

@ -5,6 +5,8 @@ declare(strict_types=1);
use Rector\Generic\Rector\String_\StringToClassConstantRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
# see: https://laravel.com/docs/5.4/upgrade
@ -34,40 +36,30 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Illuminate\Support\Collection' => [
'every' => 'nth',
],
'Illuminate\Database\Eloquent\Relations\BelongsToMany' => [
'setJoin' => 'performJoin',
'getRelatedIds' => 'allRelatedIds',
],
'Illuminate\Routing\Router' => [
'middleware' => 'aliasMiddleware',
],
'Illuminate\Routing\Route' => [
'getPath' => 'uri',
'getUri' => 'uri',
'getMethods' => 'methods',
'getParameter' => 'parameter',
],
'Illuminate\Contracts\Session\Session' => [
'set' => 'put',
'getToken' => 'token',
],
'Illuminate\Support\Facades\Request' => [
'setSession' => 'setLaravelSession',
],
'Illuminate\Http\Request' => [
'setSession' => 'setLaravelSession',
],
'Illuminate\Routing\UrlGenerator' => [
'forceSchema' => 'forceScheme',
],
'Illuminate\Validation\Validator' => [
'addError' => 'addFailure',
'doReplacements' => 'makeReplacements',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('Illuminate\Support\Collection', 'every', 'nth'),
new MethodCallRename(
'Illuminate\Database\Eloquent\Relations\BelongsToMany',
'setJoin',
'performJoin'
),
new MethodCallRename(
'Illuminate\Database\Eloquent\Relations\BelongsToMany',
'getRelatedIds',
'allRelatedIds'
),
new MethodCallRename('Illuminate\Routing\Router', 'middleware', 'aliasMiddleware'),
new MethodCallRename('Illuminate\Routing\Route', 'getPath', 'uri'),
new MethodCallRename('Illuminate\Routing\Route', 'getUri', 'uri'),
new MethodCallRename('Illuminate\Routing\Route', 'getMethods', 'methods'),
new MethodCallRename('Illuminate\Routing\Route', 'getParameter', 'parameter'),
new MethodCallRename('Illuminate\Contracts\Session\Session', 'set', 'put'),
new MethodCallRename('Illuminate\Contracts\Session\Session', 'getToken', 'token'),
new MethodCallRename('Illuminate\Support\Facades\Request', 'setSession', 'setLaravelSession'),
new MethodCallRename('Illuminate\Http\Request', 'setSession', 'setLaravelSession'),
new MethodCallRename('Illuminate\Routing\UrlGenerator', 'forceSchema', 'forceScheme'),
new MethodCallRename('Illuminate\Validation\Validator', 'addError', 'addFailure'),
new MethodCallRename('Illuminate\Validation\Validator', 'doReplacements', 'makeReplacements'),
]),
]]);
};

View File

@ -5,6 +5,8 @@ declare(strict_types=1);
use Rector\Generic\Rector\PropertyFetch\RenamePropertyRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
# see: https://laravel.com/docs/5.5/upgrade
@ -14,11 +16,9 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Illuminate\Console\Command' => [
'fire' => 'handle',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('Illuminate\Console\Command', 'fire', 'handle'),
]),
]]);
$services->set(RenamePropertyRector::class)

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
use Rector\Generic\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
# see: https://laravel.com/docs/5.6/upgrade
@ -13,14 +15,18 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Illuminate\Validation\ValidatesWhenResolvedTrait' => [
'validate' => 'validateResolved',
],
'Illuminate\Contracts\Validation\ValidatesWhenResolved' => [
'validate' => 'validateResolved',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename(
'Illuminate\Validation\ValidatesWhenResolvedTrait',
'validate',
'validateResolved'
),
new MethodCallRename(
'Illuminate\Contracts\Validation\ValidatesWhenResolved',
'validate',
'validateResolved'
),
]),
]]);
$services->set(ChangeMethodVisibilityRector::class)

View File

@ -8,6 +8,7 @@ use Rector\Generic\Rector\Expression\MethodCallToReturnRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\Rector\StaticCall\RenameStaticMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\StaticCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector;
@ -31,21 +32,27 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Illuminate\Auth\Access\Gate' => [
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename(
'Illuminate\Auth\Access\Gate',
# https://github.com/laravel/framework/commit/69de466ddc25966a0f6551f48acab1afa7bb9424
'access' => 'inspect',
],
'Illuminate\Support\Facades\Lang' => [
'access',
'inspect'
),
new MethodCallRename(
'Illuminate\Support\Facades\Lang',
# https://github.com/laravel/framework/commit/efbe23c4116f86846ad6edc0d95cd56f4175a446
'trans' => 'get',
'transChoice' => 'choice',
],
'Illuminate\Translation\Translator' => [
'trans',
'get'
),
new MethodCallRename('Illuminate\Support\Facades\Lang', 'transChoice', 'choice'),
new MethodCallRename(
'Illuminate\Translation\Translator',
# https://github.com/laravel/framework/commit/697b898a1c89881c91af83ecc4493fa681e2aa38
'getFromJson' => 'get',
],
],
'getFromJson',
'get'
),
]),
]]);
$configuration = [

View File

@ -3,6 +3,8 @@
declare(strict_types=1);
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
# https://github.com/Seldaek/monolog/commit/39f8a20e6dadc0194e846b254c5f23d1c732290b#diff-dce565f403e044caa5e6a0d988339430
@ -11,21 +13,19 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Monolog\Logger' => [
'addDebug' => 'debug',
'addInfo' => 'info',
'addNotice' => 'notice',
'addWarning' => 'warning',
'addError' => 'error',
'addCritical' => 'critical',
'addAlert' => 'alert',
'addEmergency' => 'emergency',
'warn' => 'warning',
'err' => 'error',
'crit' => 'critical',
'emerg' => 'emergency',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('Monolog\Logger', 'addDebug', 'debug'),
new MethodCallRename('Monolog\Logger', 'addInfo', 'info'),
new MethodCallRename('Monolog\Logger', 'addNotice', 'notice'),
new MethodCallRename('Monolog\Logger', 'addWarning', 'warning'),
new MethodCallRename('Monolog\Logger', 'addError', 'error'),
new MethodCallRename('Monolog\Logger', 'addCritical', 'critical'),
new MethodCallRename('Monolog\Logger', 'addAlert', 'alert'),
new MethodCallRename('Monolog\Logger', 'addEmergency', 'emergency'),
new MethodCallRename('Monolog\Logger', 'warn', 'warning'),
new MethodCallRename('Monolog\Logger', 'err', 'error'),
new MethodCallRename('Monolog\Logger', 'crit', 'critical'),
new MethodCallRename('Monolog\Logger', 'emerg', 'emergency'),
]),
]]);
};

View File

@ -16,6 +16,7 @@ use Rector\NetteCodeQuality\Rector\ArrayDimFetch\ChangeFormArrayAccessToAnnotate
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstantRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
@ -118,29 +119,29 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
// @see https://github.com/nette/forms/commit/b99385aa9d24d729a18f6397a414ea88eab6895a
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Nette\Forms\Controls\BaseControl' => [
'setAttribute' => 'setHtmlAttribute',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('Nette\Forms\Controls\BaseControl', 'setAttribute', 'setHtmlAttribute'),
]),
]]);
$services->set(RenameMethodRector::class)->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Nette\Forms\Controls\BaseControl' => [
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename(
'Nette\Forms\Controls\BaseControl',
# see https://github.com/nette/forms/commit/b99385aa9d24d729a18f6397a414ea88eab6895a
'setType' => 'setHtmlType',
'setAttribute' => 'setHtmlAttribute',
],
'Nette\DI\Definitions\ServiceDefinition' => [
'setType',
'setHtmlType'
),
new MethodCallRename('Nette\Forms\Controls\BaseControl', 'setAttribute', 'setHtmlAttribute'),
new MethodCallRename(
'Nette\DI\Definitions\ServiceDefinition',
# see https://github.com/nette/di/commit/1705a5db431423fc610a6f339f88dead1b5dc4fb
'setClass' => 'setType',
'getClass' => 'getType',
],
'Nette\DI\Definitions\Definition' => [
'isAutowired' => 'getAutowired',
],
],
'setClass',
'setType'
),
new MethodCallRename('Nette\DI\Definitions\ServiceDefinition', 'getClass', 'getType'),
new MethodCallRename('Nette\DI\Definitions\Definition', 'isAutowired', 'getAutowired'),
]),
]]);
$services->set(MagicHtmlCallToAppendAttributeRector::class);

View File

@ -12,6 +12,8 @@ use Rector\NetteToSymfony\Rector\MethodCall\FromRequestGetParameterToAttributesG
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstantRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
@ -55,20 +57,12 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Nette\Application\IPresenter' => [
'run' => '__invoke',
],
'Nette\DI\Container' => [
'getByType' => 'get',
],
'Nette\Configurator' => [
'addConfig' => 'load',
],
'Symfony\Component\Config\Loader\LoaderInterface' => [
'addConfig' => 'load',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('Nette\Application\IPresenter', 'run', '__invoke'),
new MethodCallRename('Nette\DI\Container', 'getByType', 'get'),
new MethodCallRename('Nette\Configurator', 'addConfig', 'load'),
new MethodCallRename('Symfony\Component\Config\Loader\LoaderInterface', 'addConfig', 'load'),
]),
]]);
$services->set(RemoveInterfacesRector::class)

View File

@ -9,6 +9,8 @@ use Rector\Phalcon\Rector\MethodCall\AddRequestToHandleMethodCallRector;
use Rector\Renaming\Rector\ConstFetch\RenameConstantRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
# https://docs.phalcon.io/4.0/en/upgrade#general-notes
@ -106,44 +108,28 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Phalcon\Acl\AdapterInterface' => [
'isResource' => 'isComponent',
'addResource' => 'addComponent',
'addResourceAccess' => 'addComponentAccess',
'dropResourceAccess' => 'dropComponentAccess',
'getActiveResource' => 'getActiveComponent',
'getResources' => 'getComponents',
],
'Phalcon\Acl\Adapter\Memory' => [
'isResource' => 'isComponent',
'addResource' => 'addComponent',
'addResourceAccess' => 'addComponentAccess',
'dropResourceAccess' => 'dropComponentAccess',
'getResources' => 'getComponents',
],
'Phalcon\Cli\Console' => [
'addModules' => 'registerModules',
],
'Phalcon\Dispatcher' => [
'setModelBinding' => 'setModelBinder',
],
'Phalcon\Assets\Manager' => [
'addResource' => 'addAsset',
'addResourceByType' => 'addAssetByType',
'collectionResourcesByType' => 'collectionAssetsByType',
],
'Phalcon\Http\RequestInterface' => [
'isSecureRequest' => 'isSecure',
'isSoapRequested' => 'isSoap',
],
'Phalcon\Paginator' => [
'getPaginate' => 'paginate',
],
'Phalcon\Mvc\Model\Criteria' => [
'order' => 'orderBy',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('Phalcon\Acl\AdapterInterface', 'isResource', 'isComponent'),
new MethodCallRename('Phalcon\Acl\AdapterInterface', 'addResource', 'addComponent'),
new MethodCallRename('Phalcon\Acl\AdapterInterface', 'addResourceAccess', 'addComponentAccess'),
new MethodCallRename('Phalcon\Acl\AdapterInterface', 'dropResourceAccess', 'dropComponentAccess'),
new MethodCallRename('Phalcon\Acl\AdapterInterface', 'getActiveResource', 'getActiveComponent'),
new MethodCallRename('Phalcon\Acl\AdapterInterface', 'getResources', 'getComponents'),
new MethodCallRename('Phalcon\Acl\Adapter\Memory', 'isResource', 'isComponent'),
new MethodCallRename('Phalcon\Acl\Adapter\Memory', 'addResource', 'addComponent'),
new MethodCallRename('Phalcon\Acl\Adapter\Memory', 'addResourceAccess', 'addComponentAccess'),
new MethodCallRename('Phalcon\Acl\Adapter\Memory', 'dropResourceAccess', 'dropComponentAccess'),
new MethodCallRename('Phalcon\Acl\Adapter\Memory', 'getResources', 'getComponents'),
new MethodCallRename('Phalcon\Cli\Console', 'addModules', 'registerModules'),
new MethodCallRename('Phalcon\Dispatcher', 'setModelBinding', 'setModelBinder'),
new MethodCallRename('Phalcon\Assets\Manager', 'addResource', 'addAsset'),
new MethodCallRename('Phalcon\Assets\Manager', 'addResourceByType', 'addAssetByType'),
new MethodCallRename('Phalcon\Assets\Manager', 'collectionResourcesByType', 'collectionAssetsByType'),
new MethodCallRename('Phalcon\Http\RequestInterface', 'isSecureRequest', 'isSecure'),
new MethodCallRename('Phalcon\Http\RequestInterface', 'isSoapRequested', 'isSoap'),
new MethodCallRename('Phalcon\Paginator', 'getPaginate', 'paginate'),
new MethodCallRename('Phalcon\Mvc\Model\Criteria', 'order', 'orderBy'),
]),
]]);
$services->set(RenameConstantRector::class)

View File

@ -19,6 +19,7 @@ use Rector\PHPOffice\Rector\StaticCall\ChangeSearchLocationToRegisterReaderRecto
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\Rector\StaticCall\RenameStaticMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\StaticCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
@ -59,17 +60,15 @@ return static function (ContainerConfigurator $containerConfigurator): void {
# beware! this can be run only once, since its circular change
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'PHPExcel_Worksheet' => [
# https://github.com/PHPOffice/PhpSpreadsheet/blob/master/docs/topics/migration-from-PHPExcel.md#worksheetsetsharedstyle
'setSharedStyle' => 'duplicateStyle',
# https://github.com/PHPOffice/PhpSpreadsheet/blob/master/docs/topics/migration-from-PHPExcel.md#worksheetgetselectedcell
'getSelectedCell' => 'getSelectedCells',
# https://github.com/PHPOffice/PhpSpreadsheet/blob/master/docs/topics/migration-from-PHPExcel.md#cell-caching
'getCellCacheController' => 'getCellCollection',
'getCellCollection' => 'getCoordinates',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
// https://github.com/PHPOffice/PhpSpreadsheet/blob/master/docs/topics/migration-from-PHPExcel.md#worksheetsetsharedstyle
new MethodCallRename('PHPExcel_Worksheet', 'setSharedStyle', 'duplicateStyle'),
// https://github.com/PHPOffice/PhpSpreadsheet/blob/master/docs/topics/migration-from-PHPExcel.md#worksheetgetselectedcell
new MethodCallRename('PHPExcel_Worksheet', 'getSelectedCell', 'getSelectedCells'),
// https://github.com/PHPOffice/PhpSpreadsheet/blob/master/docs/topics/migration-from-PHPExcel.md#cell-caching
new MethodCallRename('PHPExcel_Worksheet', 'getCellCacheController', 'getCellCollection'),
new MethodCallRename('PHPExcel_Worksheet', 'getCellCollection', 'getCoordinates'),
]),
]]);
$configuration = [

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
@ -11,13 +13,11 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'PhpSpec\ServiceContainer' => [
# @see http://www.phpspec.net/en/stable/manual/upgrading-to-phpspec-3.html
'set' => 'define',
'setShared' => 'define',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
// @see http://www.phpspec.net/en/stable/manual/upgrading-to-phpspec-3.html
new MethodCallRename('PhpSpec\ServiceContainer', 'set', 'define'),
new MethodCallRename('PhpSpec\ServiceContainer', 'setShared', 'define'),
]),
]]);
$services->set(RenameClassRector::class)

View File

@ -5,6 +5,8 @@ declare(strict_types=1);
use Rector\PHPUnit\Rector\ClassMethod\ExceptionAnnotationRector;
use Rector\PHPUnit\Rector\MethodCall\DelegateExceptionArgumentsRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
@ -17,11 +19,9 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'PHPUnit\Framework\TestClass' => [
'setExpectedException' => 'expectedException',
'setExpectedExceptionRegExp' => 'expectedException',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('PHPUnit\Framework\TestClass', 'setExpectedException', 'expectedException'),
new MethodCallRename('PHPUnit\Framework\TestClass', 'setExpectedExceptionRegExp', 'expectedException'),
]),
]]);
};

View File

@ -3,6 +3,8 @@
declare(strict_types=1);
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
@ -10,11 +12,13 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'PHPUnit_Framework_MockObject_MockObject' => [
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename(
'PHPUnit_Framework_MockObject_MockObject',
# see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/137
'staticExpects' => 'expects',
],
],
'staticExpects',
'expects'
),
]),
]]);
};

View File

@ -7,6 +7,8 @@ use Rector\PHPUnit\Rector\ClassMethod\AddDoesNotPerformAssertionToNonAssertingTe
use Rector\PHPUnit\Rector\MethodCall\GetMockBuilderGetMockToCreateMockRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
@ -16,11 +18,9 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'PHPUnit\Framework\TestCase' => [
'createMockBuilder' => 'getMockBuilder',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('PHPUnit\Framework\TestCase', 'createMockBuilder', 'getMockBuilder'),
]),
]]);
$services->set(RenameClassRector::class)

View File

@ -6,6 +6,8 @@ use Rector\PHPUnit\Rector\Class_\TestListenerToHooksRector;
use Rector\PHPUnit\Rector\MethodCall\ExplicitPhpErrorApiRector;
use Rector\PHPUnit\Rector\MethodCall\SpecificAssertContainsWithoutIdentityRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
@ -19,10 +21,14 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
# see https://github.com/sebastianbergmann/phpunit/issues/3957
'expectExceptionMessageRegExp' => 'expectExceptionMessageMatches',
'assertRegExp' => 'assertMatchesRegularExpression',
],
// see https://github.com/sebastianbergmann/phpunit/issues/3957
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename(
'PHPUnit\Framework\TestCase',
'expectExceptionMessageRegExp',
'expectExceptionMessageMatches'
),
new MethodCallRename('PHPUnit\Framework\TestCase', 'assertRegExp', 'assertMatchesRegularExpression'),
]),
]]);
};

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
use Rector\PHPUnit\Rector\Class_\AddProphecyTraitRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
@ -13,10 +15,8 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'PHPUnit\Framework\TestCase' => [
'assertFileNotExists' => 'assertFileDoesNotExist',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('PHPUnit\Framework\TestCase', 'assertFileNotExists', 'assertFileDoesNotExist'),
]),
]]);
};

View File

@ -3,6 +3,8 @@
declare(strict_types=1);
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
@ -13,13 +15,11 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Enlight_Controller_Response_Response' => [
'getHttpResponseCode' => 'getStatusCode',
'setHttpResponseCode' => 'setStatusCode',
'sendCookies' => 'sendHeaders',
'setBody' => 'setContent',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('Enlight_Controller_Response_Response', 'getHttpResponseCode', 'getStatusCode'),
new MethodCallRename('Enlight_Controller_Response_Response', 'setHttpResponseCode', 'setStatusCode'),
new MethodCallRename('Enlight_Controller_Response_Response', 'sendCookies', 'sendHeaders'),
new MethodCallRename('Enlight_Controller_Response_Response', 'setBody', 'setContent'),
]),
]]);
};

View File

@ -6,6 +6,8 @@ use Rector\Generic\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\Generic\Rector\ClassMethod\ArgumentAdderRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
@ -14,22 +16,34 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Sylius\Component\Core\Repository\OrderRepositoryInterface' => [
# source: https://github.com/Sylius/Sylius/blob/master/UPGRADE-1.0.md#upgrade-from-100-beta3-to-100
'count' => 'countPlacedOrders',
'countByChannel' => 'countFulfilledByChannel',
],
'Sylius\Component\Product\Repository\ProductVariantRepositoryInterface' => [
'findByCodeAndProductCode' => 'findByCodesAndProductCode',
],
'Sylius\Component\Core\Model\OrderInterface' => [
'getLastNewPayment' => 'getLastPayment',
],
'Sylius\Component\Taxonomy\Model\TaxonInterface' => [
'getParents ' => 'getAncestors',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
// source: https://github.com/Sylius/Sylius/blob/master/UPGRADE-1.0.md#upgrade-from-100-beta3-to-100
new MethodCallRename(
'Sylius\Component\Core\Repository\OrderRepositoryInterface',
'count',
'countPlacedOrders'
),
new MethodCallRename(
'Sylius\Component\Core\Repository\OrderRepositoryInterface',
'countByChannel',
'countFulfilledByChannel'
),
new MethodCallRename(
'Sylius\Component\Product\Repository\ProductVariantRepositoryInterface',
'findByCodeAndProductCode',
'findByCodesAndProductCode'
),
new MethodCallRename(
'Sylius\Component\Core\Model\OrderInterface',
'getLastNewPayment',
'getLastPayment'
),
new MethodCallRename(
'Sylius\Component\Taxonomy\Model\TaxonInterface',
'getParents ',
'getAncestors'
),
]),
]]);
$services->set(AddParamTypeDeclarationRector::class)

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstantRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Symfony\Rector\ClassMethod\FormTypeGetParentRector;
use Rector\Symfony\Rector\ClassMethod\GetRequestRector;
use Rector\Symfony\Rector\ClassMethod\RemoveDefaultGetBlockPrefixRector;
@ -15,6 +16,7 @@ use Rector\Symfony\Rector\MethodCall\FormTypeInstanceToClassConstRector;
use Rector\Symfony\Rector\MethodCall\OptionNameRector;
use Rector\Symfony\Rector\MethodCall\ReadOnlyOptionToAttributeRector;
use Rector\Symfony\Rector\MethodCall\StringFormTypeToClassRector;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
@ -65,84 +67,112 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Symfony\Component\ClassLoader\UniversalClassLoader\UniversalClassLoader' => [
# class loader
'registerNamespaces' => 'addPrefixes',
'registerPrefixes' => 'addPrefixes',
'registerNamespace' => 'addPrefix',
'registerPrefix' => 'addPrefix',
'getNamespaces' => 'getPrefixes',
'getNamespaceFallbacks' => 'getFallbackDirs',
'getPrefixFallbacks' => 'getFallbackDirs',
],
'Symfony\Component\Form\AbstractType' => [
# form
'getName' => 'getBlockPrefix',
'setDefaultOptions' => 'configureOptions',
],
'Symfony\Component\Form\FormTypeInterface' => [
'getName' => 'getBlockPrefix',
'setDefaultOptions' => 'configureOptions',
],
'Symfony\Component\Form\ResolvedFormTypeInterface' => [
'getName' => 'getBlockPrefix',
],
'Symfony\Component\Form\AbstractTypeExtension' => [
'setDefaultOptions' => 'configureOptions',
],
'Symfony\Component\Form\Form' => [
'bind' => 'submit',
'isBound' => 'isSubmitted',
],
'Symfony\Component\Process\Process' => [
# process
'setStdin' => 'setInput',
'getStdin' => 'getInput',
],
'Symfony\Bridge\Monolog\Logger' => [
# monolog
'emerg' => 'emergency',
'crit' => 'critical',
'err' => 'error',
'warn' => 'warning',
],
'Symfony\Component\HttpKernel\Log\LoggerInterface' => [
# http kernel
'emerg' => 'emergency',
'crit' => 'critical',
'err' => 'error',
'warn' => 'warning',
],
'Symfony\Component\HttpKernel\Log\NullLogger' => [
'emerg' => 'emergency',
'crit' => 'critical',
'err' => 'error',
'warn' => 'warning',
],
'Symfony\Component\PropertyAccess\PropertyAccess' => [
# property access
'getPropertyAccessor' => 'createPropertyAccessor',
],
# serialazer
'Symfony\Component\Serializer\Exception\Exception' => 'Symfony\Component\Serializer\Exception\ExceptionInterface',
'Symfony\Component\Translation\Dumper\FileDumper' => [
# translator
'format' => 'formatCatalogue',
],
'Symfony\Component\Translation\Translator' => [
'getMessages' => 'getCatalogue',
],
'Symfony\Component\Validator\ConstraintViolationInterface' => [
# validator
'getMessageParameters' => 'getParameters',
'getMessagePluralization' => 'getPlural',
],
'Symfony\Component\Validator\ConstraintViolation' => [
'getMessageParameters' => 'getParameters',
'getMessagePluralization' => 'getPlural',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
// class loader
new MethodCallRename(
'Symfony\Component\ClassLoader\UniversalClassLoader\UniversalClassLoader',
'registerNamespaces',
'addPrefixes'
),
new MethodCallRename(
'Symfony\Component\ClassLoader\UniversalClassLoader\UniversalClassLoader',
'registerPrefixes',
'addPrefixes'
),
new MethodCallRename(
'Symfony\Component\ClassLoader\UniversalClassLoader\UniversalClassLoader',
'registerNamespace',
'addPrefix'
),
new MethodCallRename(
'Symfony\Component\ClassLoader\UniversalClassLoader\UniversalClassLoader',
'registerPrefix',
'addPrefix'
),
new MethodCallRename(
'Symfony\Component\ClassLoader\UniversalClassLoader\UniversalClassLoader',
'getNamespaces',
'getPrefixes'
),
new MethodCallRename(
'Symfony\Component\ClassLoader\UniversalClassLoader\UniversalClassLoader',
'getNamespaceFallbacks',
'getFallbackDirs'
),
new MethodCallRename(
'Symfony\Component\ClassLoader\UniversalClassLoader\UniversalClassLoader',
'getPrefixFallbacks',
'getFallbackDirs'
),
// form
new MethodCallRename('Symfony\Component\Form\AbstractType', 'getName', 'getBlockPrefix'),
new MethodCallRename('Symfony\Component\Form\AbstractType', 'setDefaultOptions', 'configureOptions'),
new MethodCallRename('Symfony\Component\Form\FormTypeInterface', 'getName', 'getBlockPrefix'),
new MethodCallRename(
'Symfony\Component\Form\FormTypeInterface',
'setDefaultOptions',
'configureOptions'
),
new MethodCallRename('Symfony\Component\Form\ResolvedFormTypeInterface', 'getName', 'getBlockPrefix'),
new MethodCallRename(
'Symfony\Component\Form\AbstractTypeExtension',
'setDefaultOptions',
'configureOptions'
),
new MethodCallRename('Symfony\Component\Form\Form', 'bind', 'submit'),
new MethodCallRename('Symfony\Component\Form\Form', 'isBound', 'isSubmitted'),
// process
new MethodCallRename('Symfony\Component\Process\Process', 'setStdin', 'setInput'),
new MethodCallRename('Symfony\Component\Process\Process', 'getStdin', 'getInput'),
// monolog
new MethodCallRename('Symfony\Bridge\Monolog\Logger', 'emerg', 'emergency'),
new MethodCallRename('Symfony\Bridge\Monolog\Logger', 'crit', 'critical'),
new MethodCallRename('Symfony\Bridge\Monolog\Logger', 'err', 'error'),
new MethodCallRename('Symfony\Bridge\Monolog\Logger', 'warn', 'warning'),
# http kernel
new MethodCallRename('Symfony\Component\HttpKernel\Log\LoggerInterface', 'emerg', 'emergency'),
new MethodCallRename('Symfony\Component\HttpKernel\Log\LoggerInterface', 'crit', 'critical'),
new MethodCallRename('Symfony\Component\HttpKernel\Log\LoggerInterface', 'err', 'error'),
new MethodCallRename('Symfony\Component\HttpKernel\Log\LoggerInterface', 'warn', 'warning'),
new MethodCallRename('Symfony\Component\HttpKernel\Log\NullLogger', 'emerg', 'emergency'),
new MethodCallRename('Symfony\Component\HttpKernel\Log\NullLogger', 'crit', 'critical'),
new MethodCallRename('Symfony\Component\HttpKernel\Log\NullLogger', 'err', 'error'),
new MethodCallRename('Symfony\Component\HttpKernel\Log\NullLogger', 'warn', 'warning'),
// property access
new MethodCallRename(
'getPropertyAccessor',
'Symfony\Component\PropertyAccess\PropertyAccess',
'createPropertyAccessor'
),
// translator
new MethodCallRename(
'Symfony\Component\Translation\Dumper\FileDumper',
'format',
'formatCatalogue'
),
new MethodCallRename('Symfony\Component\Translation\Translator', 'getMessages', 'getCatalogue'),
// validator
new MethodCallRename(
'Symfony\Component\Validator\ConstraintViolationInterface',
'getMessageParameters',
'getParameters'
),
new MethodCallRename(
'Symfony\Component\Validator\ConstraintViolationInterface',
'getMessagePluralization',
'getPlural'
),
new MethodCallRename(
'Symfony\Component\Validator\ConstraintViolation',
'getMessageParameters',
'getParameters'
),
new MethodCallRename(
'Symfony\Component\Validator\ConstraintViolation',
'getMessagePluralization',
'getPlural'
),
]),
]]);
$services->set(RenameClassRector::class)

View File

@ -5,7 +5,9 @@ declare(strict_types=1);
use Rector\Generic\Rector\ClassMethod\ArgumentAdderRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Symfony\Rector\ClassConstFetch\ConsoleExceptionToErrorEventConstantRector;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
@ -63,11 +65,8 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Symfony\Component\DependencyInjection\Container' => [
# dependency-injection
'isFrozen' => 'isCompiled',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('Symfony\Component\DependencyInjection\Container', 'isFrozen', 'isCompiled'),
]),
]]);
};

View File

@ -4,6 +4,9 @@ declare(strict_types=1);
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\MethodCallRenameWithArrayKey;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
# https://github.com/symfony/symfony/blob/master/UPGRADE-4.1.md
@ -12,30 +15,44 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
# https://github.com/symfony/symfony/commit/463f986c28a497571967e37c1314e9911f1ef6ba
'Symfony\Component\Console\Helper\TableStyle' => [
'setHorizontalBorderChar' => 'setHorizontalBorderChars',
'setVerticalBorderChar' => 'setVerticalBorderChars',
'getVerticalBorderChar' => [
# special case to "getVerticalBorderChar" → "getBorderChars()[3]"
'name' => 'getBorderChars',
'array_key' => 3,
],
'getHorizontalBorderChar' => [
'name' => 'getBorderChars',
'array_key' => 2,
],
'setCrossingChar' => 'setDefaultCrossingChar',
],
'Symfony\Component\HttpFoundation\File\UploadedFile' => [
'getClientSize' => 'getSize',
],
'Symfony\Component\Workflow\DefinitionBuilder' => [
'reset' => 'clear',
'add' => 'addWorkflow',
],
],
new MethodCallRename(
'Symfony\Component\Console\Helper\TableStyle',
'setHorizontalBorderChar',
'setHorizontalBorderChars'
),
# https://github.com/symfony/symfony/commit/463f986c28a497571967e37c1314e9911f1ef6ba
new MethodCallRename(
'Symfony\Component\Console\Helper\TableStyle',
'setVerticalBorderChar',
'setVerticalBorderChars'
),
# https://github.com/symfony/symfony/commit/463f986c28a497571967e37c1314e9911f1ef6ba
new MethodCallRename(
'Symfony\Component\Console\Helper\TableStyle',
'setCrossingChar',
'setDefaultCrossingChar'
),
new MethodCallRename('Symfony\Component\HttpFoundation\File\UploadedFile', 'getClientSize', 'getSize'),
new MethodCallRename('Symfony\Component\Workflow\DefinitionBuilder', 'reset', 'clear'),
new MethodCallRename('Symfony\Component\Workflow\DefinitionBuilder', 'add', 'addWorkflow'),
# https://github.com/symfony/symfony/commit/463f986c28a497571967e37c1314e9911f1ef6ba
new MethodCallRenameWithArrayKey(
'Symfony\Component\Console\Helper\TableStyle',
'getVerticalBorderChar',
# special case to "getVerticalBorderChar" → "getBorderChars()[3]"
'getBorderChars',
3
),
# https://github.com/symfony/symfony/commit/463f986c28a497571967e37c1314e9911f1ef6ba
new MethodCallRenameWithArrayKey(
'Symfony\Component\Console\Helper\TableStyle',
'getHorizontalBorderChar',
'getBorderChars',
2
),
]),
]]);
$services->set(RenameClassRector::class)

View File

@ -11,9 +11,11 @@ use Rector\Generic\Rector\ClassMethod\WrapReturnRector;
use Rector\Generic\Rector\New_\NewToStaticCallRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Symfony\Rector\MethodCall\ContainerGetToConstructorInjectionRector;
use Rector\Symfony\Rector\New_\RootNodeTreeBuilderRector;
use Rector\Symfony\Rector\New_\StringToArrayArgumentProcessRector;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
# https://github.com/symfony/symfony/pull/28447
@ -119,14 +121,14 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Symfony\Component\Cache\CacheItem' => [
'getPreviousTags' => 'getMetadata',
],
'Symfony\Component\Form\AbstractTypeExtension' => [
'getExtendedType' => 'getExtendedTypes',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('Symfony\Component\Cache\CacheItem', 'getPreviousTags', 'getMetadata'),
new MethodCallRename(
'Symfony\Component\Form\AbstractTypeExtension',
'getExtendedType',
'getExtendedTypes'
),
]),
]]);
$services->set(AddReturnTypeDeclarationRector::class)

View File

@ -6,8 +6,10 @@ use Rector\Generic\Rector\ClassMethod\AddMethodParentCallRector;
use Rector\Generic\Rector\ClassMethod\ArgumentAdderRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Symfony\Rector\MethodCall\MakeDispatchFirstArgumentEventRector;
use Rector\Symfony\Rector\MethodCall\SimplifyWebTestCaseAssertionsRector;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
# https://github.com/symfony/symfony/blob/4.4/UPGRADE-4.3.md
@ -19,14 +21,10 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Symfony\Component\BrowserKit\Response' => [
'getStatus' => 'getStatusCode',
],
'Symfony\Component\Security\Http\Firewall' => [
'handleRequest' => 'callListeners',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('Symfony\Component\BrowserKit\Response', 'getStatus', 'getStatusCode'),
new MethodCallRename('Symfony\Component\Security\Http\Firewall', 'handleRequest', 'callListeners'),
]),
]]);
$services->set(MakeDispatchFirstArgumentEventRector::class);

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
# https://github.com/symfony/symfony/blob/5.0/UPGRADE-5.0.md
@ -22,11 +24,13 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Symfony\Component\Console\Application' => [
'renderException' => 'renderThrowable',
'doRenderException' => 'doRenderThrowable',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('Symfony\Component\Console\Application', 'renderException', 'renderThrowable'),
new MethodCallRename(
'Symfony\Component\Console\Application',
'doRenderException',
'doRenderThrowable'
),
]),
]]);
};

View File

@ -3,6 +3,8 @@
declare(strict_types=1);
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
@ -10,18 +12,12 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Twig_Node' => [
'getLine' => 'getTemplateLine',
'getFilename' => 'getTemplateName',
],
'Twig_Template' => [
'getSource' => 'getSourceContext',
],
'Twig_Error' => [
'getTemplateFile' => 'getTemplateName',
'getTemplateName' => 'setTemplateName',
],
],
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => inline_value_objects([
new MethodCallRename('Twig_Node', 'getLine', 'getTemplateLine'),
new MethodCallRename('Twig_Node', 'getFilename', 'getTemplateName'),
new MethodCallRename('Twig_Template', 'getSource', 'getSourceContext'),
new MethodCallRename('Twig_Error', 'getTemplateFile', 'getTemplateName'),
new MethodCallRename('Twig_Error', 'getTemplateName', 'setTemplateName'),
]),
]]);
};

View File

@ -1,4 +1,4 @@
# All 565 Rectors Overview
# All 566 Rectors Overview
- [Projects](#projects)
---
@ -69,7 +69,7 @@
- [Symfony](#symfony) (33)
- [SymfonyCodeQuality](#symfonycodequality) (1)
- [SymfonyPHPUnit](#symfonyphpunit) (1)
- [SymfonyPhpConfig](#symfonyphpconfig) (1)
- [SymfonyPhpConfig](#symfonyphpconfig) (2)
- [Twig](#twig) (1)
- [TypeDeclaration](#typedeclaration) (9)
@ -9473,7 +9473,9 @@ Remove `expect($this->any())` from mocks as it has no added value
Replace deprecated "assertArraySubset()" method with alternative methods
```diff
class SomeTest extends \PHPUnit\Framework\TestCase
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestCase
{
public function test()
{
@ -12617,9 +12619,7 @@ return function (ContainerConfigurator $containerConfigurator) : void {
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'SomeExampleClass' => [
'$oldToNewMethodsByClass' => [
'oldMethod' => 'newMethod']]]
\Rector\SymfonyPhpConfig\inline_object(new Rector\Renaming\ValueObject\MethodCallRename('SomeExampleClass', 'oldMethod', 'newMethod'))]
]]);
};
```
@ -14238,6 +14238,37 @@ return function (ContainerConfigurator $containerConfigurator) : void {
<br><br>
### `ReplaceArrayWithObjectRector`
- class: [`Rector\SymfonyPhpConfig\Rector\ArrayItem\ReplaceArrayWithObjectRector`](/../master/rules/symfony-php-config/src/Rector/ArrayItem/ReplaceArrayWithObjectRector.php)
- [test fixtures](/../master/rules/symfony-php-config/tests/Rector/ArrayItem/ReplaceArrayWithObjectRector/Fixture)
Replace complex array configuration in configs with value object
```php
<?php
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Rector\SymfonyPhpConfig\Rector\ArrayItem\ReplaceArrayWithObjectRector;
return function (ContainerConfigurator $containerConfigurator) : void {
$services = $containerConfigurator->services();
$services->set(ReplaceArrayWithObjectRector::class)
->call('configure', [[
ReplaceArrayWithObjectRector::CONSTANT_NAMES_TO_VALUE_OBJECTS => [
'Rector\Renaming\Rector\MethodCall\RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS' => 'Rector\Renaming\ValueObject\MethodCallRename']
]]);
};
```
```diff
```
<br><br>
## Twig
### `SimpleFunctionAndFilterRector`

View File

@ -103,6 +103,10 @@ final class RectorRecipe
$this->description = $description;
if ($codeBefore === $codeAfter) {
throw new ConfigurationException('Code before and after are identical. They have to be different');
}
$this->setCodeBefore($codeBefore);
$this->setCodeAfter($codeAfter);

View File

@ -76,11 +76,6 @@ final class SetList
*/
public const CODING_STYLE = __DIR__ . '/../../../../config/set/coding-style.php';
/**
* @var string
*/
public const CONSTRUCTOR_INJECTIN_TO_ACTION_INJECTION = __DIR__ . '/../../../../config/set/constructor-injectin-to-action-injection.php';
/**
* @var string
*/

View File

@ -6,7 +6,12 @@ namespace Rector\VendorLocker\NodeVendorLocker;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Privatization\VisibilityGuard\ClassMethodVisibilityGuard;
/**
* @deprecated
* Merge with @see ClassMethodVisibilityGuard
*/
final class ClassMethodVisibilityVendorLockResolver extends AbstractNodeVendorLockResolver
{
/**
@ -46,8 +51,8 @@ final class ClassMethodVisibilityVendorLockResolver extends AbstractNodeVendorLo
private function isInterfaceMethod(ClassMethod $classMethod, string $className): bool
{
$interfaceMethods = $this->getInterfaceMethods($className);
return $this->nodeNameResolver->isNames($classMethod, $interfaceMethods);
$interfaceMethodNames = $this->getInterfaceMethodNames($className);
return $this->nodeNameResolver->isNames($classMethod, $interfaceMethodNames);
}
private function hasParentMethod(string $className, string $methodName): bool
@ -87,7 +92,7 @@ final class ClassMethodVisibilityVendorLockResolver extends AbstractNodeVendorLo
/**
* @return string[]
*/
private function getInterfaceMethods(string $className): array
private function getInterfaceMethodNames(string $className): array
{
$interfaces = class_implements($className);

View File

@ -70,8 +70,8 @@ parameters:
- tests
- compiler/src
- utils
# this cannot be put it, because it wipes PHPStan cache on each run
#- config
# this cannot be put it, because it wipes PHPStan cache on each run :( - must run in separate
#- config/set
excludes_analyse:
# iterable types
@ -408,3 +408,8 @@ parameters:
- compiler/src/Composer/ComposerJsonManipulator.php
# not sure how to improve
- rules/symfony/src/ValueObject/Tag/EventListenerTag.php
- '#Cannot access property \$key on PhpParser\\Node\\Expr\\ArrayItem\|null#'
- '#Class Nette\\DI\\CompilerExtension not found#'
- '#Class Latte\\Macros\\MacroSet not found#'

View File

@ -0,0 +1,409 @@
includes:
- utils/phpstan-extensions/config/phpstan-extensions.neon
- vendor/slam/phpstan-extensions/conf/slam-rules.neon
- vendor/symplify/phpstan-extensions/config/config.neon
- vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon
# see https://github.com/symplify/coding-standard
- vendor/symplify/coding-standard/config/symplify-rules.neon
rules:
# should be fixed in next part of symplify CS release
- Symplify\CodingStandard\Rules\NoClassWithStaticMethodWithoutStaticNameRule
- Symplify\CodingStandard\Rules\SeeAnnotationToTestRule
services:
# this rule prevents bug in phar like these: https://github.com/rectorphp/rector/pull/3692/files
-
class: Rector\PHPStanExtensions\Rule\RequireStringArgumentInMethodCallRule
tags: [phpstan.rules.rule]
arguments:
constantArgByMethodByType:
Rector\Core\Rector\AbstractRector:
isObjectType: [1]
parameters:
level: max
# see https://github.com/symplify/coding-standard
symplify:
max_cognitive_complexity: 9 # default: 8
max_class_cognitive_complexity: 50
parent_classes:
- Rector
required_see_types:
- PHPStan\Rules\Rule
- Rector\Core\Rector\AbstractRector
- Rector\FileSystemRector\Rector\AbstractFileSystemRector
old_to_preffered_classes:
# prevent PHPStorm autocomplete mess
'Symfony\Component\DependencyInjection\Variable': 'PhpParser\Node\Expr\Variable'
'phpDocumentor\Reflection\Types\Expression': 'PhpParser\Node\Stmt\Expression'
'phpDocumentor\Reflection\DocBlock\Tags\Param': 'PhpParser\Node\Param'
'phpDocumentor\Reflection\DocBlock\Tags\Return_': 'PhpParser\Node\Stmt\Return_'
'Closure': 'PhpParser\Node\Expr\Closure'
'PHPUnit\TextUI\Configuration\Variable': 'PhpParser\Node\Expr\Variable'
'PhpCsFixer\FixerDefinition\CodeSample': 'Rector\Core\RectorDefinition\CodeSample'
'SebastianBergmann\Type\MixedType': 'PHPStan\Type\MixedType'
'Hoa\Protocol\Node\Node': 'PhpParser\Node'
# to allow installing with various phsptan versions without reporting old errors here
reportUnmatchedIgnoredErrors: false
checkGenericClassInNonGenericObjectType: false
scanDirectories:
- stubs
bootstrapFiles:
- vendor/symfony/dependency-injection/Loader/Configurator/ContainerConfigurator.php
paths:
- bin
- src
- rules
- packages
- tests
- compiler/src
- utils
# this cannot be put it, because it wipes PHPStan cache on each run :( - must run in separate
#- config/set
excludes_analyse:
# iterable types
- '#with no value type specified in iterable type array#'
- '#type specified in iterable type (array|iterable)#'
# phsptan bug
- utils/phpstan-extensions/src/Rule/PreventParentMethodVisibilityOverrideRule.php
- utils/phpstan-extensions/src/Rule/KeepRectorNamespaceForRectorRule.php
- packages/rector-generator/templates/*
# generated files
- 'packages/doctrine-annotation-generated/src/ConstantPreservingDocParser.php'
- 'packages/doctrine-annotation-generated/src/ConstantPreservingAnnotationReader.php'
- "*/Expected/*"
# complex printer
- '*tests/Rector/MethodCall/RenameMethodRector/**/SomeClass.php'
# tests files
- '*tests/*/Fixture/*'
- '*tests/*/Source/*'
- '*tests/Source/*'
# part of composer
- '*/tests/Rector/Psr4/MultipleClassFileToPsr4ClassesRector/Expected/Just*ExceptionWithoutNamespace.php'
ignoreErrors:
# @todo remove
# iterable types
- '#with no value type specified in iterable type array#'
- '#type specified in iterable type (array|iterable)#'
# false positive
- '#PHPDoc tag \@param for parameter \$node with type float is incompatible with native type PhpParser\\Node#'
# misuse of interface and class
- '#Parameter \#1 (.*?) expects Symfony\\Component\\DependencyInjection\\ContainerBuilder, Symfony\\Component\\DependencyInjection\\ContainerInterface given#'
- '#Strict comparison using === between string and null will always evaluate to false#'
# false positive - type is set by annotation above
- '#Array \(array<PhpParser\\Node\\Stmt>\) does not accept PhpParser\\Node#'
# irrelevant
- '#Call to function in_array\(\) with arguments string, (.*?) and true will always evaluate to false#'
# known values
- '#Access to an undefined property PhpParser\\Node\\Expr::\$right#'
- '#Access to an undefined property PhpParser\\Node\\Expr\\MethodCall\|PhpParser\\Node\\Stmt\\ClassMethod::\$params#'
- '#Cannot call method getName\(\) on PHPStan\\Reflection\\ClassReflection\|null#'
# false positive, has annotation type above
- '#Method Rector\\CodeQuality\\Rector\\Foreach_\\SimplifyForeachToCoalescingRector\:\:matchReturnOrAssignNode\(\) should return PhpParser\\Node\\Expr\\Assign\|PhpParser\\Node\\Stmt\\Return_\|null but returns PhpParser\\Node\|null#'
- '#Access to an undefined property PhpParser\\Node::\$(\w+)#'
# intentionally incorrect - part of the test
- '#Parameter \#2 \$codeSamples of class Rector\\Core\\RectorDefinition\\RectorDefinition constructor expects array<Rector\\Core\\Contract\\RectorDefinition\\CodeSampleInterface>, array<int, stdClass> given#'
# known values
- '#Cannot access property \$value on PhpParser\\Node\\Expr\\ArrayItem\|null#'
# known values
- '#Strict comparison using === between PhpParser\\Node\\Expr and null will always evaluate to false#'
- '#Access to an undefined property PhpParser\\Node\\Stmt\:\:\$expr#'
- '#Cannot access property \$stmts on PhpParser\\Node\\Stmt\\Else_\|null#'
# node finder
- '#Method Rector\\(.*?) should return array<PhpParser\\Node\\(.*?)> but returns array<PhpParser\\Node\>#'
# part of test
- '#(.*?)(AttributeAwareNodeInterface|AttributeAware(.*?)TagValueNode)(.*?)#'
- '#Parameter \#1 \$children of class PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PhpDocNode constructor expects array<PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PhpDocChildNode\>, array<int, PHPStan\\PhpDocParser\\Ast\\Node\> given#'
- '#Method Rector\\PHPUnit\\Rector\\MethodCall\\ReplaceAssertArraySubsetRector\:\:matchArray\(\) should return PhpParser\\Node\\Expr\\Array_\|null but returns PhpParser\\Node\\Expr#'
- '#(.*?)PhpParser\\Node\\Expr\\Error\|PhpParser\\Node\\Expr\\Variable given#'
# false positive 0.11.5
- '#Unreachable statement \- code above always terminates#'
- '#Negated boolean expression is always true#'
- '#Strict comparison using \=\=\= between PhpParser\\Node and null will always evaluate to false#'
# known types
- '#Access to an undefined property PhpParser\\Node\\Expr\\Error\|PhpParser\\Node\\Expr\\Variable\:\:\$name#'
- '#Strict comparison using \=\=\= between PhpParser\\Node\\Expr\\ArrayItem and null will always evaluate to false#'
- '#Parameter \#2 \.\.\.\$args of function array_merge expects array, array<int, string\>\|false given#'
- '#Access to an undefined property PhpParser\\Node\\Expr\:\:\$args#'
- '#Parameter \#2 \$name of method Rector\\Core\\Rector\\AbstractRector\:\:isName\(\) expects string, string\|null given#'
# cascade irrelevant
- '#Parameter (.*?) expects array<PhpParser\\Node\\Stmt\>, array<PhpParser\\Node\> given#'
# known value
- '#Cannot cast array<string\>\|bool\|string\|null to string#'
# array is callable
- '#If condition is always true#'
- '#Ternary operator condition is always true#'
- '#Access to an undefined property PhpParser\\Node\\FunctionLike\|PhpParser\\Node\\Stmt\\ClassLike\:\:\$stmts#'
- '#Property Rector\\TypeDeclaration\\TypeInferer\\(.*?)\:\:\$(.*?)TypeInferers \(array<Rector\\TypeDeclaration\\Contract\\TypeInferer\\(.*?)TypeInfererInterface\>\) does not accept array<Rector\\TypeDeclaration\\Contract\\TypeInferer\\PriorityAwareTypeInfererInterface\>#'
# sense-less errors
# 3rd party
-
message: '#Use default null value and nullable compare instead of isset on object#'
path: 'rules/symfony/src/ServiceMapProvider.php'
# PHP 7.4 1_000 support
- '#Property PhpParser\\Node\\Scalar\\DNumber\:\:\$value \(float\) does not accept string#'
- '#Call to function is_string\(\) with float will always evaluate to false#'
- '#Method Rector\\Doctrine\\Rector\\MethodCall\\ChangeSetIdToUuidValueRector\:\:getSetUuidMethodCallOnSameVariable\(\) should return PhpParser\\Node\\Expr\\MethodCall\|null but returns PhpParser\\Node\|null#'
# known value
- '#Method Rector\\StrictCodeQuality\\Rector\\Stmt\\VarInlineAnnotationToAssertRector\:\:findVariableByName\(\) should return PhpParser\\Node\\Expr\\Variable\|null but returns PhpParser\\Node\|null#'
- '#Method Rector\\NodeTypeResolver\\PHPStan\\Type\\TypeFactory\:\:createUnionOrSingleType\(\) should return PHPStan\\Type\\MixedType\|PHPStan\\Type\\UnionType but returns PHPStan\\Type\\Type#'
# test
- '#Class Rector\\DynamicTypeAnalysis\\Tests\\Rector\\ClassMethod\\AddArgumentTypeWithProbeDataRector\\Fixture\\SomeClass not found#'
-
message: '#Class Rector\\Generic\\Tests\\Rector\\StaticCall\\SwapClassMethodArgumentsRector\\Fixture\\SomeClass not found#'
path: rules/generic/tests/Rector/StaticCall/SwapClassMethodArgumentsRector/SwapClassMethodArgumentsRectorTest.php
# internal rule
- '#Class "Rector\\Utils\\(.*?)" is missing @see annotation with test case class reference#'
# mixed
- '#Offset int\|string\|null does not exist on array<PhpParser\\Node\\Stmt>\|null#'
- '#class-string<T of object>\|T of object#'
# known values
- '#Offset 0 does not exist on array<PhpParser\\Node\\Stmt>\|null#'
- '#Parameter \#1 \$left of class PhpParser\\Node\\Expr\\BinaryOp\\Spaceship constructor expects PhpParser\\Node\\Expr, PhpParser\\Node\\Expr\|null given#'
- '#Parameter \#2 \$right of class PhpParser\\Node\\Expr\\BinaryOp\\Spaceship constructor expects PhpParser\\Node\\Expr, PhpParser\\Node\\Expr\|null given#'
- '#Parameter \#3 \$nodeCallback of method PHPStan\\Analyser\\NodeScopeResolver::processNodes\(\) expects Closure\(PhpParser\\Node, PHPStan\\Analyser\\Scope\): void, Closure\(PhpParser\\Node, PHPStan\\Analyser\\MutatingScope\): void given#'
# false positive
- '#Comparison operation "<" between 0 and 2 is always true#'
- '#Method Rector\\Symfony\\Rector\\MethodCall\\AbstractToConstructorInjectionRector\:\:getServiceTypeFromMethodCallArgument\(\) should return PHPStan\\Type\\Type but returns PHPStan\\Type\\Type\|null#'
- '#Parameter \#1 \$expected of method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) expects class\-string<object\>, string given#'
- '#Unable to resolve the template type ExpectedType in call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\)#'
# fix Symplify 7.2 later
- '#Method (.*?) returns bool type, so the name should start with is/has/was#'
# known value
- '#Cannot cast \(array<string\>\)\|string\|true to string#'
- '#In method "Rector\\BetterPhpDocParser\\AnnotationReader\\NodeAnnotationReader\:\:createPropertyReflectionFromPropertyNode", caught "Throwable" must be rethrown\. Either catch a more specific exception or add a "throw" clause in the "catch" block to propagate the exception\. More info\: http\://bit\.ly/failloud#'
# doc is not enough
- '#Result of \|\| is always true#'
# known value
- '#Parameter \#2 \$name of class PhpParser\\Node\\Expr\\MethodCall constructor expects PhpParser\\Node\\Expr\|PhpParser\\Node\\Identifier\|string, string\|null given#'
- '#Parameter \#1 \$eventListenerTag of method Rector\\SymfonyCodeQuality\\Rector\\Class_\\EventListenerToEventSubscriberRector\:\:createEventItem\(\) expects Rector\\Symfony\\ValueObject\\Tag\\EventListenerTag, Rector\\Symfony\\Contract\\Tag\\TagInterface given#'
- '#Method Rector\\BetterPhpDocParser\\PhpDocInfo\\PhpDocInfoFactory\:\:parseTokensToPhpDocNode\(\) should return Rector\\AttributeAwarePhpDoc\\Ast\\PhpDoc\\AttributeAwarePhpDocNode but returns PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PhpDocNode#'
- '#Property PhpParser\\Node\\Stmt\\Expression\:\:\$expr \(PhpParser\\Node\\Expr\) does not accept PhpParser\\Node\\Expr\|null#'
- '#Call to an undefined method PHPStan\\Type\\Type\:\:getClassName\(\)#'
- '#Parameter \#1 \$typeNode of method Rector\\StaticTypeMapper\\StaticTypeMapper\:\:mapPHPStanPhpDocTypeNodeToPHPStanType\(\) expects PHPStan\\PhpDocParser\\Ast\\Type\\TypeNode, PHPStan\\PhpDocParser\\Ast\\Node given#'
- '#Parameter \#1 \$str of function preg_quote expects string, int\|string given#'
- '#Parameter \#1 \$sprintfFuncCall of method Rector\\Core\\PhpParser\\NodeTransformer\:\:transformSprintfToArray\(\) expects PhpParser\\Node\\Expr\\FuncCall, PhpParser\\Node given#'
- '#Parameter \#1 \$nodes of method Rector\\Core\\PhpParser\\Node\\BetterNodeFinder\:\:find\(\) expects array<PhpParser\\Node\>\|PhpParser\\Node, array<PhpParser\\Node\\Stmt\>\|null given#'
- '#Method Rector\\SOLID\\Reflection\\ParentConstantReflectionResolver\:\:(.*?)\(\) should return ReflectionClassConstant\|null but returns ReflectionClassConstant\|false#'
- '#Parameter \#1 \$firstStmt of method Rector\\Generic\\Rector\\ClassMethod\\NormalToFluentRector\:\:isBothMethodCallMatch\(\) expects PhpParser\\Node\\Stmt\\Expression, PhpParser\\Node\\Stmt given#'
- '#Method Rector\\Core\\Rector\\AbstractRector\:\:wrapToArg\(\) should return array<PhpParser\\Node\\Arg\> but returns array<PhpParser\\Node\\Arg\|PhpParser\\Node\\Expr\>#'
- '#Method Rector\\FileSystemRector\\Rector\\AbstractFileSystemRector\:\:wrapToArg\(\) should return array<PhpParser\\Node\\Arg\> but returns array<PhpParser\\Node\\Arg\|PhpParser\\Node\\Expr\>#'
- '#Cannot call method (.*?)\(\) on Rector\\BetterPhpDocParser\\PhpDocInfo\\PhpDocInfo\|null#'
- '#Parameter \#(.*?) (.*?) of class PhpParser\\Node\\Expr\\BinaryOp\\(.*?) constructor expects PhpParser\\Node\\Expr, PhpParser\\Node given#'
- '#Access to an undefined property PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PhpDocTagValueNode\:\:\$description#'
- '#Method Rector\\Php80\\Rector\\NotIdentical\\StrContainsRector\:\:matchNotIdenticalToFalse\(\) should return PhpParser\\Node\\Expr\\FuncCall\|null but returns PhpParser\\Node\\Expr#'
- '#Parameter \#2 \$name of method Rector\\Core\\Rector\\AbstractRector\:\:isVariableName\(\) expects string, string\|null given#'
# node finder
- '#Method Rector\\Core\\PhpParser\\Node\\Manipulator\\MethodCallManipulator\:\:findAssignToVariableName\(\) should return PhpParser\\Node\\Expr\\Assign\|null but returns PhpParser\\Node\|null#'
# broken
- '#Cannot call method getParentNode\(\) on Rector\\DeadCode\\ValueObject\\VariableNodeUse\|null#'
- '#Method Rector\\DeadCode\\NodeFinder\\PreviousVariableAssignNodeFinder\:\:find\(\) should return PhpParser\\Node\\Expr\\Assign\|null but returns PhpParser\\Node\|null#'
- '#Parameter \#2 \$name of method Rector\\NodeNameResolver\\NodeNameResolver\:\:isName\(\) expects string, string\|null given#'
- '#Method Rector\\PHPOffice\\Rector\\MethodCall\\IncreaseColumnIndexRector\:\:findVariableAssignName\(\) should return PhpParser\\Node\\Expr\\Assign\|null but returns PhpParser\\Node\|null#'
- '#Parameter \#1 \$keyName of method Rector\\AttributeAwarePhpDoc\\Ast\\Type\\AttributeAwareArrayShapeItemNode\:\:createKeyWithSpacePattern\(\) expects PHPStan\\PhpDocParser\\Ast\\ConstExpr\\ConstExprIntegerNode\|PHPStan\\PhpDocParser\\Ast\\Type\\IdentifierTypeNode\|null, PHPStan\\PhpDocParser\\Ast\\ConstExpr\\ConstExprIntegerNode\|PHPStan\\PhpDocParser\\Ast\\ConstExpr\\ConstExprStringNode\|PHPStan\\PhpDocParser\\Ast\\Type\\IdentifierTypeNode\|null given#'
- '#Method Rector\\Caching\\ChangedFilesDetector\:\:hashFile\(\) should return string but returns string\|false#'
- '#If condition is always false#'
- '#Parameter \#1 \$funcCall of method Rector\\Php80\\MatchAndRefactor\\StrStartsWithMatchAndRefactor\\AbstractMatchAndRefactor\:\:createStrStartsWithValueObjectFromFuncCall\(\) expects PhpParser\\Node\\Expr\\FuncCall, PhpParser\\Node\\Expr given#'
# mostly strings in tests
- '#Class (.*?) should be written with \:\:class notation, string found#'
- '#Parameter \#2 \$key of method Rector\\BetterPhpDocParser\\PhpDocNode\\AbstractTagValueNode\:\:printArrayItem\(\) expects string\|null, int\|string given#'
- '#Method Rector\\Naming\\Naming\\PropertyNaming\:\:resolveShortClassName\(\) should return string but returns string\|null#'
-
message: "#in iterable type Iterator#"
paths:
- *Test.php
- *TestCase.php
-
message: "#^Cognitive complexity for \"Rector\\\\BetterPhpDocParser\\\\Printer\\\\WhitespaceDetector\\:\\:detectOldWhitespaces\\(\\)\" is 18, keep it under 9$#"
count: 1
path: packages/better-php-doc-parser/src/Printer/WhitespaceDetector.php
-
message: "#^Parameter \\#1 \\$input of function array_splice expects array, array\\<PhpParser\\\\Node\\\\Stmt\\>\\|null given\\.$#"
count: 1
path: rules/coding-style/src/Rector/ClassMethod/NewlineBeforeNewAssignSetRector.php
-
message: "#^Cognitive complexity for \"Rector\\\\PhpSpecToPHPUnit\\\\Rector\\\\MethodCall\\\\PhpSpecPromisesToPHPUnitAssertRector\\:\\:refactor\\(\\)\" is 13, keep it under 9$#"
count: 1
path: rules/php-spec-to-phpunit/src/Rector/MethodCall/PhpSpecPromisesToPHPUnitAssertRector.php
-
message: "#^Class cognitive complexity for \"EregToPcreTransformer\" is (.*?), keep it under 50$#"
path: rules/php70/src/EregToPcreTransformer.php
-
message: "#Use explicit property fetch names over dynamic#"
path: packages/doctrine-annotation-generated/src/PhpDocNode/ConstantReferenceIdentifierRestorer.php
- "#^Cognitive complexity for \"Rector\\\\Php70\\\\EregToPcreTransformer\\:\\:(.*?)\" is (.*?), keep it under 9$#"
- '#Use explicit return value over magic &reference#'
- '#In method "Rector\\Utils\\ProjectValidator\\Process\\ParallelTaskRunner\:\:(.*?)", caught "Throwable" must be rethrown\. Either catch a more specific exception or add a "throw" clause in the "catch" block to propagate the exception#'
# weird
- '#Method (.*?) specified in iterable type Symfony\\Component\\Process\\Process#'
- '#Cannot cast PhpParser\\Node\\Expr\\Error\|PhpParser\\Node\\Identifier to string#'
- '#Class cognitive complexity for "DumpNodesCommand" is \d+, keep it under 50#'
- '#Cognitive complexity for "Rector\\Utils\\DocumentationGenerator\\Command\\DumpNodesCommand\:\:execute\(\)" is \d+, keep it under 9#'
- '#Parameter \#1 \$node of method Rector\\PostRector\\Collector\\NodesToAddCollector\:\:wrapToExpression\(\) expects PhpParser\\Node\\Expr\|PhpParser\\Node\\Stmt, PhpParser\\Node given#'
- '#Access to an undefined property PhpParser\\Node\\Expr\:\:\$class#'
- '#Method Rector\\BetterPhpDocParser\\Tests\\PhpDocParser\\AbstractPhpDocInfoTest\:\:parseFileAndGetFirstNodeOfType\(\) should return PhpParser\\Node but returns PhpParser\\Node\|null#'
- '#Property PhpParser\\Node\\Stmt\\Namespace_\:\:\$stmts \(array<PhpParser\\Node\\Stmt\>\) does not accept array<PhpParser\\Node\>#'
- '#Cognitive complexity for "Rector\\TypeDeclaration\\PHPStan\\Type\\ObjectTypeSpecifier\:\:matchShortenedObjectType\(\)" is 10, keep it under 9#'
- '#Parameter \#1 \$type of method PhpParser\\Builder\\FunctionLike\:\:setReturnType\(\) expects PhpParser\\Node\\Name\|PhpParser\\Node\\NullableType\|string, PhpParser\\Node\\Identifier\|PhpParser\\Node\\Name\|PhpParser\\Node\\NullableType\|PhpParser\\Node\\UnionType given#'
- '#Cognitive complexity for "Rector\\Core\\PhpParser\\Node\\Value\\ValueResolver\:\:getValue\(\)" is \d+, keep it under 9#'
- '#Cognitive complexity for "Rector\\NetteKdyby\\ContributeEventClassResolver\:\:resolveGetterMethodByEventClassAndParam\(\)" is \d+, keep it under 9#'
- '#Parameter \#1 \$type of class PhpParser\\Node\\NullableType constructor expects PhpParser\\Node\\Identifier\|PhpParser\\Node\\Name\|string, PhpParser\\Node\\Identifier\|PhpParser\\Node\\Name\|PhpParser\\Node\\NullableType\|PhpParser\\Node\\UnionType given#'
- '#Parameter \#1 \$object of function get_class expects object, PhpParser\\Node\|null given#'
- '#Class "Rector\\FileSystemRector\\Rector\\Removing\\RemoveProjectFileRector" is missing @see annotation with test case class reference#'
- '#Parameter \#1 \$type of method PhpParser\\Builder\\Param\:\:setType\(\) expects PhpParser\\Node\\Name\|PhpParser\\Node\\NullableType\|PhpParser\\Node\\UnionType\|string, PhpParser\\Node\\Identifier\|PhpParser\\Node\\Name\|PhpParser\\Node\\NullableType\|PhpParser\\Node\\UnionType given#'
- '#Parameter \#1 \$node of method Rector\\Core\\PhpParser\\Node\\BetterNodeFinder\:\:findFirstAncestorInstanceOf\(\) expects PhpParser\\Node, PhpParser\\Node\\Expr\\Variable\|null given#'
- '#Parameter \#1 \$objectType of method Rector\\Naming\\Naming\\PropertyNaming\:\:fqnToVariableName\(\) expects PHPStan\\Type\\ObjectType\|string, PHPStan\\Type\\Type given#'
- '#Method Rector\\Core\\PhpParser\\Node\\NodeFactory\:\:createConcat\(\) should return PhpParser\\Node\\Expr\\BinaryOp\\Concat\|null but returns PhpParser\\Node\\Expr#'
- '#Method Rector\\Core\\PhpParser\\Node\\BetterNodeFinder\:\:findFirstNonAnonymousClass\(\) should return PhpParser\\Node\\Stmt\\Class_\|null but returns PhpParser\\Node\|null#'
# known value
- '#Property PhpParser\\Node\\Stmt\\Foreach_\:\:\$valueVar \(PhpParser\\Node\\Expr\) does not accept PhpParser\\Node\\Expr\|null#'
- '#Access to an undefined property PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PhpDocTagValueNode\:\:\$type#'
# local type
-
message: '#Method call "isObjectType\(\)" argument on position 1 cannot use "\:\:class" reference#'
path: 'packages/dynamic-type-analysis/src/Rector/StaticCall/RemoveArgumentTypeProbeRector.php'
# only local use
-
message: '#Class "Rector\\RectorGenerator\\Rector\\Closure\\AddNewServiceToSymfonyPhpConfigRector" is missing @see annotation with test case class reference#'
path: 'packages/rector-generator/src/Rector/Closure/AddNewServiceToSymfonyPhpConfigRector.php'
- '#Call to an undefined method PhpParser\\Node\\Expr\\Error\|PhpParser\\Node\\Identifier\:\:toString\(\)#'
- '#Class Rector\\Renaming\\Tests\\Rector\\MethodCall\\RenameMethodRector\\Fixture\\SkipSelfMethodRename not found#'
# fixed in symplfiy dev
-
message: '#Separate function "Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\ref\(\)" in method call to standalone row to improve readability#'
path: 'packages/rector-generator/config/config.php'
- '#Method Rector\\Core\\PhpParser\\Node\\BetterNodeFinder\:\:findPreviousAssignToExpr\(\) should return PhpParser\\Node\\Expr\\Assign\|null but returns PhpParser\\Node\|null#'
- '#Parameter \#1 \$shortControlString of method Rector\\NetteCodeQuality\\Rector\\Assign\\MakeGetComponentAssignAnnotatedRector\:\:resolveTypeFromShortControlNameAndVariable\(\) expects PhpParser\\Node\\Scalar\\String_, PhpParser\\Node\\Expr\|null given#'
- '#Parameter \#1 \$variable of class Rector\\Php70\\ValueObject\\VariableAssignPair constructor expects PhpParser\\Node\\Expr\\ArrayDimFetch\|PhpParser\\Node\\Expr\\PropertyFetch\|PhpParser\\Node\\Expr\\StaticPropertyFetch\|PhpParser\\Node\\Expr\\Variable, PhpParser\\Node\\Expr given#'
# is nested expr
- '#Access to an undefined property PhpParser\\Node\\Expr\:\:\$expr#'
- '#Cognitive complexity for "Rector\\DeadCode\\NodeManipulator\\LivingCodeManipulator\:\:keepLivingCodeFromExpr\(\)" is \d+, keep it under 9#'
- '#Parameter \#1 \$files of method Symplify\\SmartFileSystem\\Finder\\FinderSanitizer\:\:sanitize\(\) expects \(iterable<SplFileInfo\|string\>&Nette\\Utils\\Finder\)\|Symfony\\Component\\Finder\\Finder, array<string\> given#'
- '#Static property Rector\\Core\\Testing\\PHPUnit\\AbstractGenericRectorTestCase\:\:\$allRectorContainer \(Rector\\Naming\\Tests\\Rector\\Class_\\RenamePropertyToMatchTypeRector\\Source\\ContainerInterface\|Symfony\\Component\\DependencyInjection\\Container\|null\) does not accept Psr\\Container\\ContainerInterface#'
# stubs
- '#Static property Symplify\\PackageBuilder\\Tests\\AbstractKernelTestCase\:\:\$container \(Psr\\Container\\ContainerInterface\) does not accept Rector\\Naming\\Tests\\Rector\\Class_\\RenamePropertyToMatchTypeRector\\Source\\ContainerInterface\|Symfony\\Component\\DependencyInjection\\Container#'
# wtf
-
message: '#Else branch is unreachable because ternary operator condition is always true#'
path: 'rules/psr4/src/Composer/PSR4NamespaceMatcher.php'
# false positive
- '#Parameter \#1 \$arrayItem of method Rector\\NetteKdyby\\NodeResolver\\ListeningMethodsCollector\:\:resolveCustomClassMethodAndEventClass\(\) expects PhpParser\\Node\\Expr\\ArrayItem, PhpParser\\Node given#'
- '#Parameter \#1 \$type of method Rector\\NodeCollector\\NodeCollector\\ParsedNodeCollector<TNodeType of PhpParser\\Node\>\:\:getNodesByType\(\) expects class\-string<TNodeType of PhpParser\\Node\>, string given#'
- '#Class with base "(.*?)" name is already used in "_HumbugBox(.*?)"#'
-
message: '#Class "Rector\\RectorGenerator\\ValueObject\\RectorRecipe" has invalid namespace category "ValueObject"\. Pick one of\: ""#'
path: packages/rector-generator/src/ValueObject/RectorRecipe.php
- '#Parameter \#2 \$currentNode of method Rector\\CodingStyle\\Rector\\Assign\\ManualJsonStringToJsonEncodeArrayRector\:\:matchNextExprAssignConcatToSameVariable\(\) expects PhpParser\\Node\\Expr\\Assign\|PhpParser\\Node\\Expr\\AssignOp\\Concat, PhpParser\\Node given#'
-
message: '#Array (with keys|explosion) is not allowed\. Use value object to pass data instead#'
paths:
# working with cvs file
# 3rd party package
- utils/project-validator/src/Command/ValidateFixtureContentCommand.php
- src/Testing/PHPUnit/AbstractRectorTestCase.php
- rules/php70/src/EregToPcreTransformer.php
# output format
- packages/changes-reporting/src/Output/JsonOutputFormatter.php
# template variables
- packages/rector-generator/src/TemplateVariablesFactory.php
# output format to json
- rules/doctrine/src/Collector/UuidMigrationDataCollector.php
# should be replaced by symplify/composer-json-manipulator in the future
- compiler/src/Composer/ComposerJsonManipulator.php
# not sure how to improve
- rules/symfony/src/ValueObject/Tag/EventListenerTag.php

View File

@ -3,9 +3,20 @@
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\SymfonyPhpConfig\Rector\ArrayItem\ReplaceArrayWithObjectRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(ReplaceArrayWithObjectRector::class)
->call('configure', [[
ReplaceArrayWithObjectRector::CONSTANT_NAMES_TO_VALUE_OBJECTS => [
'Rector\Renaming\Rector\MethodCall\RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS' => MethodCallRename::class,
],
]]);
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::AUTO_IMPORT_NAMES, true);

View File

@ -3,7 +3,6 @@
namespace Rector\DeadCode\Tests\Rector\Property\RemoveSetterOnlyPropertyAndMethodCallRector\Fixture;
use Rector\DeadCode\Tests\Rector\Property\RemoveSetterOnlyPropertyAndMethodCallRector\Source\PostTemplate;
use Doctrine\ORM\Mapping as ORM;
class KeepManyToOne

View File

@ -72,7 +72,7 @@ PHP
}
/**
* @return array<int, string>
* @return string[]
*/
public function getNodeTypes(): array
{

View File

@ -3,7 +3,6 @@
namespace Rector\Naming\Tests\Rector\ClassMethod\RenameParamToMatchTypeRector\Fixture;
use Rector\Naming\Tests\Rector\ClassMethod\RenameParamToMatchTypeRector\Source\AMP;
use DateTime;
class KeepCorrect

View File

@ -3,7 +3,6 @@
namespace Rector\Naming\Tests\Rector\ClassMethod\RenameParamToMatchTypeRector\Fixture;
use Rector\Naming\Tests\Rector\ClassMethod\RenameParamToMatchTypeRector\Source\AMP;
use DateTime;
class KeepIterable

View File

@ -3,7 +3,6 @@
namespace Rector\Naming\Tests\Rector\Class_\RenamePropertyToMatchTypeRector\Fixture;
use Rector\Naming\Tests\Rector\Class_\RenamePropertyToMatchTypeRector\Source\AMP;
use DateTime;
class KeepCorrect

View File

@ -3,7 +3,6 @@
namespace Rector\Naming\Tests\Rector\Class_\RenamePropertyToMatchTypeRector\Fixture;
use Rector\Naming\Tests\Rector\Class_\RenamePropertyToMatchTypeRector\Source\AMP;
use DateTime;
class KeepIterable

View File

@ -52,7 +52,7 @@ PHP
<<<'PHP'
use PHPUnit\Framework\TestCase;
class SomeTest extends TestCase
final class SomeTest extends TestCase
{
public function test()
{

View File

@ -11,12 +11,23 @@ use Rector\Core\Rector\AbstractRector;
use Rector\Core\RectorDefinition\CodeSample;
use Rector\Core\RectorDefinition\RectorDefinition;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Privatization\VisibilityGuard\ClassMethodVisibilityGuard;
/**
* @see \Rector\Privatization\Tests\Rector\ClassMethod\PrivatizeFinalClassMethodRector\PrivatizeFinalClassMethodRectorTest
*/
final class PrivatizeFinalClassMethodRector extends AbstractRector
{
/**
* @var ClassMethodVisibilityGuard
*/
private $classMethodVisibilityGuard;
public function __construct(ClassMethodVisibilityGuard $classMethodVisibilityGuard)
{
$this->classMethodVisibilityGuard = $classMethodVisibilityGuard;
}
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Change protected class method to private if possible', [
@ -73,7 +84,7 @@ PHP
return $node;
}
if ($this->isClassMethodVisibilityGuardedByParent($node, $classLike)) {
if ($this->classMethodVisibilityGuard->isClassMethodVisibilityGuardedByParent($node, $classLike)) {
return null;
}
@ -90,33 +101,4 @@ PHP
return ! $classMethod->isProtected();
}
private function isClassMethodVisibilityGuardedByParent(ClassMethod $classMethod, Class_ $class): bool
{
if ($class->extends === null) {
return false;
}
$parentClasses = $this->getParentClasses($class);
$propertyName = $this->getName($classMethod);
foreach ($parentClasses as $parentClass) {
if (method_exists($parentClass, $propertyName)) {
return true;
}
}
return false;
}
/**
* @return class-string[]
*/
private function getParentClasses(Class_ $class): array
{
/** @var string $className */
$className = $this->getName($class);
return class_parents($className);
}
}

View File

@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace Rector\Privatization\VisibilityGuard;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\NodeNameResolver\NodeNameResolver;
final class ClassMethodVisibilityGuard
{
/**
* @var NodeNameResolver
*/
private $nodeNameResolver;
public function __construct(NodeNameResolver $nodeNameResolver)
{
$this->nodeNameResolver = $nodeNameResolver;
}
public function isClassMethodVisibilityGuardedByParent(ClassMethod $classMethod, Class_ $class): bool
{
if ($class->extends === null) {
return false;
}
$parentClasses = $this->getParentClasses($class);
$propertyName = $this->nodeNameResolver->getName($classMethod);
foreach ($parentClasses as $parentClass) {
if (method_exists($parentClass, $propertyName)) {
return true;
}
}
return false;
}
/**
* @return class-string[]
*/
private function getParentClasses(Class_ $class): array
{
/** @var string $className */
$className = $this->nodeNameResolver->getName($class);
return class_parents($className);
}
}

View File

@ -0,0 +1,12 @@
<?php
namespace Rector\Privatization\Tests\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Fixture;
use Rector\Privatization\Tests\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Source\SomeContractWithGo;
class SkipContract implements SomeContractWithGo
{
public function go()
{
}
}

View File

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Rector\Privatization\Tests\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector\Source;
interface SomeContractWithGo
{
public function go();
}

View File

@ -149,7 +149,8 @@ PHP
[
self::TYPES_TO_SERVICES => ['StaticClass'],
]
), ]);
), ]
);
}
/**

View File

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

View File

@ -17,6 +17,9 @@ use Rector\Core\Rector\AbstractRector;
use Rector\Core\RectorDefinition\ConfiguredCodeSample;
use Rector\Core\RectorDefinition\RectorDefinition;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Renaming\Contract\MethodCallRenameInterface;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\MethodCallRenameWithArrayKey;
/**
* @see \Rector\Renaming\Tests\Rector\MethodCall\RenameMethodRector\RenameMethodRectorTest
@ -26,16 +29,12 @@ final class RenameMethodRector extends AbstractRector implements ConfigurableRec
/**
* @var string
*/
public const OLD_TO_NEW_METHODS_BY_CLASS = '$oldToNewMethodsByClass';
public const OLD_TO_NEW_METHODS_BY_CLASS = 'old_to_new_methods_by_class';
/**
* class => [
* oldMethod => newMethod
* ]
*
* @var array<string, array<string, string>>
* @var MethodCallRenameInterface[]
*/
private $oldToNewMethodsByClass = [];
private $methodCallRenames = [];
public function getDefinition(): RectorDefinition
{
@ -53,11 +52,7 @@ PHP
,
[
self::OLD_TO_NEW_METHODS_BY_CLASS => [
'SomeExampleClass' => [
'$oldToNewMethodsByClass' => [
'oldMethod' => 'newMethod',
],
],
new MethodCallRename('SomeExampleClass', 'oldMethod', 'newMethod'),
],
]
),
@ -77,25 +72,26 @@ PHP
*/
public function refactor(Node $node): ?Node
{
foreach ($this->oldToNewMethodsByClass as $type => $oldToNewMethods) {
if (! $this->isMethodStaticCallOrClassMethodObjectType($node, $type)) {
foreach ($this->methodCallRenames as $methodCallRename) {
if (! $this->isMethodStaticCallOrClassMethodObjectType($node, $methodCallRename->getOldClass())) {
continue;
}
foreach ($oldToNewMethods as $oldMethod => $newMethod) {
if (! $this->isName($node->name, $oldMethod)) {
continue;
}
if ($this->skipClassMethod($node, $newMethod, $type)) {
continue;
}
$newNode = $this->renameToMethod($node, $newMethod);
if ($newNode !== null) {
return $newNode;
}
if (! $this->isName($node->name, $methodCallRename->getOldMethod())) {
continue;
}
if ($this->skipClassMethod($node, $methodCallRename)) {
continue;
}
$node->name = new Identifier($methodCallRename->getNewMethod());
if ($methodCallRename instanceof MethodCallRenameWithArrayKey && ! $node instanceof ClassMethod) {
return new ArrayDimFetch($node, BuilderHelpers::normalizeValue($methodCallRename->getArrayKey()));
}
return $node;
}
return null;
@ -103,57 +99,29 @@ PHP
public function configure(array $configuration): void
{
$this->oldToNewMethodsByClass = $configuration[self::OLD_TO_NEW_METHODS_BY_CLASS] ?? [];
$this->methodCallRenames = $configuration[self::OLD_TO_NEW_METHODS_BY_CLASS] ?? [];
}
/**
* @param MethodCall|StaticCall|ClassMethod $node
* @param string|string[] $newMethod
*/
private function skipClassMethod(Node $node, $newMethod, string $type): bool
private function skipClassMethod(Node $node, MethodCallRenameInterface $methodCallRename): bool
{
if (! $node instanceof ClassMethod) {
return false;
}
if ($this->shouldSkipForAlreadyExistingClassMethod($node, $newMethod)) {
if ($this->shouldSkipForAlreadyExistingClassMethod($node, $methodCallRename)) {
return true;
}
return $this->shouldSkipForExactClassMethodForClassMethod($node, $type);
return $this->shouldSkipForExactClassMethodForClassMethod($node, $methodCallRename->getOldClass());
}
/**
* @param MethodCall|StaticCall|ClassMethod $node
* @param string|mixed[] $newMethod
*/
private function renameToMethod(Node $node, $newMethod): ?Node
{
if (is_string($newMethod)) {
$node->name = new Identifier($newMethod);
return $node;
}
// special case for array dim fetch
if (! $node instanceof ClassMethod) {
$node->name = new Identifier($newMethod['name']);
return new ArrayDimFetch($node, BuilderHelpers::normalizeValue($newMethod['array_key']));
}
return null;
}
/**
* @param string|mixed[] $newMethod
*/
private function shouldSkipForAlreadyExistingClassMethod(ClassMethod $classMethod, $newMethod): bool
{
if (! is_string($newMethod)) {
return false;
}
private function shouldSkipForAlreadyExistingClassMethod(
ClassMethod $classMethod,
MethodCallRenameInterface $methodCallRename
): bool {
if (! $classMethod instanceof ClassMethod) {
return false;
}
@ -164,7 +132,7 @@ PHP
return false;
}
return (bool) $classLike->getMethod($newMethod);
return (bool) $classLike->getMethod($methodCallRename->getNewMethod());
}
private function shouldSkipForExactClassMethodForClassMethod(ClassMethod $classMethod, string $type): bool

View File

@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace Rector\Renaming\ValueObject;
use Rector\Renaming\Contract\MethodCallRenameInterface;
final class MethodCallRename implements MethodCallRenameInterface
{
/**
* @var string
*/
private $oldClass;
/**
* @var string
*/
private $oldMethod;
/**
* @var string
*/
private $newMethod;
public function __construct(string $oldClass, string $oldMethod, string $newMethod)
{
$this->oldClass = $oldClass;
$this->oldMethod = $oldMethod;
$this->newMethod = $newMethod;
}
public function getOldClass(): string
{
return $this->oldClass;
}
public function getOldMethod(): string
{
return $this->oldMethod;
}
public function getNewMethod(): string
{
return $this->newMethod;
}
}

View File

@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
namespace Rector\Renaming\ValueObject;
use Rector\Renaming\Contract\MethodCallRenameInterface;
final class MethodCallRenameWithArrayKey implements MethodCallRenameInterface
{
/**
* @var string
*/
private $oldClass;
/**
* @var string
*/
private $oldMethod;
/**
* @var string
*/
private $newMethod;
/**
* @var mixed
*/
private $arrayKey;
/**
* @param mixed $arrayKey
*/
public function __construct(string $oldClass, string $oldMethod, string $newMethod, $arrayKey)
{
$this->oldClass = $oldClass;
$this->oldMethod = $oldMethod;
$this->newMethod = $newMethod;
$this->arrayKey = $arrayKey;
}
public function getOldClass(): string
{
return $this->oldClass;
}
public function getOldMethod(): string
{
return $this->oldMethod;
}
public function getNewMethod(): string
{
return $this->newMethod;
}
/**
* @return mixed
*/
public function getArrayKey()
{
return $this->arrayKey;
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace Rector\Renaming\Tests\Rector\MethodCall\RenameMethodRector\Fixture;
class RenameMethodCallWithArrayKey
{
private function createHtml()
{
$html = new \Nette\Utils\Html();
$html->addToArray('someContent');
}
}
?>
-----
<?php
namespace Rector\Renaming\Tests\Rector\MethodCall\RenameMethodRector\Fixture;
class RenameMethodCallWithArrayKey
{
private function createHtml()
{
$html = new \Nette\Utils\Html();
$html->addToHtmlArray('someContent')['hey'];
}
}
?>

View File

@ -10,7 +10,8 @@ use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Tests\Rector\MethodCall\RenameMethodRector\Fixture\SkipSelfMethodRename;
use Rector\Renaming\Tests\Rector\MethodCall\RenameMethodRector\Source\AbstractType;
use Rector\Renaming\Tests\Rector\MethodCall\RenameMethodRector\Source\FormMacros;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\MethodCallRenameWithArrayKey;
use Symplify\SmartFileSystem\SmartFileInfo;
final class RenameMethodRectorTest extends AbstractRectorTestCase
@ -36,25 +37,12 @@ final class RenameMethodRectorTest extends AbstractRectorTestCase
return [
RenameMethodRector::class => [
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
AbstractType::class => [
'setDefaultOptions' => 'configureOptions',
],
Html::class => [
'add' => 'addHtml',
'addToArray' => [
'name' => 'addHtmlArray',
'array_key' => 'hi',
],
],
FormMacros::class => [
'renderFormBegin' => ['Nette\Bridges\FormsLatte\Runtime', 'renderFormBegin'],
],
'*Presenter' => [
'run' => '__invoke',
],
SkipSelfMethodRename::class => [
'preventPHPStormRefactoring' => 'gone',
],
new MethodCallRename(AbstractType::class, 'setDefaultOptions', 'configureOptions'),
new MethodCallRename(Html::class, 'add', 'addHtml'),
new MethodCallRename('*Presenter', 'run', '__invoke'),
new MethodCallRename(SkipSelfMethodRename::class, 'preventPHPStormRefactoring', 'gone'),
// with array key
new MethodCallRenameWithArrayKey(Html::class, 'addToArray', 'addToHtmlArray', 'hey'),
],
],
];

View File

@ -214,7 +214,7 @@ final class ReturnClosurePrinter
// create arguments from object properties
$inlineObjectFuncCall = new FuncCall(new FullyQualified(
'Rector\SymfonyPhpConfig\inline_object'
'Rector\SymfonyPhpConfig\inline_value_object'
), $args);
$value[$key] = $inlineObjectFuncCall;
}

View File

@ -0,0 +1,180 @@
<?php
declare(strict_types=1);
namespace Rector\SymfonyPhpConfig\Rector\ArrayItem;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Scalar\String_;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\RectorDefinition\ConfiguredCodeSample;
use Rector\Core\RectorDefinition\RectorDefinition;
use Rector\Renaming\ValueObject\MethodCallRename;
/**
* @see \Rector\SymfonyPhpConfig\Tests\Rector\ArrayItem\ReplaceArrayWithObjectRector\ReplaceArrayWithObjectRectorTest
*/
final class ReplaceArrayWithObjectRector extends AbstractRector implements ConfigurableRectorInterface
{
/**
* @api
* @var string
*/
public const CONSTANT_NAMES_TO_VALUE_OBJECTS = 'constant_names_to_value_objects';
/**
* @var array<string, string>
*/
private $constantNamesToValueObjects = [];
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Replace complex array configuration in configs with value object', [
new ConfiguredCodeSample(
<<<'CODE_SAMPLE'
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Illuminate\Auth\Access\Gate' => [
'access' => 'inspect',
]
]]
]);
}
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => \Rector\SymfonyPhpConfig\inline_value_objects([
new \Rector\Renaming\ValueObject\MethodCallRename('Illuminate\Auth\Access\Gate', 'access', 'inspect'),
])
]]);
}
CODE_SAMPLE
,
[
self::CONSTANT_NAMES_TO_VALUE_OBJECTS => [
'Rector\Renaming\Rector\MethodCall\RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS' => MethodCallRename::class,
],
]),
]);
}
/**
* @return string[]
*/
public function getNodeTypes(): array
{
return [ArrayItem::class];
}
/**
* @param ArrayItem $node
*/
public function refactor(Node $node): ?Node
{
if (! $node->key instanceof ClassConstFetch) {
return null;
}
foreach ($this->constantNamesToValueObjects as $constantName => $valueObjectClass) {
if ($this->shouldSkip($node, $constantName)) {
continue;
}
/** @var Array_ $configurationValueArray */
$configurationValueArray = $node->value;
$newItems = [];
foreach ($configurationValueArray->items as $nestedArrayItem) {
if ($this->shouldSkipNestedArrayItem($nestedArrayItem)) {
continue;
}
/** @var Array_ $nestedArrayItemArray */
$nestedArrayItemArray = $nestedArrayItem->value;
foreach ($nestedArrayItemArray->items as $nestedNestedArrayItem) {
$args = $this->createArgs(
/** @var ArrayItem $nestedArrayItem */
/** @var ArrayItem $nestedNestedArrayItem */
[$nestedArrayItem->key, $nestedNestedArrayItem->key, $nestedNestedArrayItem->value]
);
$new = new New_(new FullyQualified($valueObjectClass), $args);
$newItems[] = new ArrayItem($new);
}
}
$configurationValueArray->items = $newItems;
// wrap with inline objects
$args = [new Arg($configurationValueArray)];
$node->value = new FuncCall(new FullyQualified('Rector\SymfonyPhpConfig\inline_value_objects'), $args);
return $node;
}
return null;
}
public function configure(array $configuration): void
{
$this->constantNamesToValueObjects = $configuration[self::CONSTANT_NAMES_TO_VALUE_OBJECTS] ?? [];
}
private function shouldSkip(ArrayItem $arrayItem, string $constantName): bool
{
if ($arrayItem->key === null) {
return true;
}
if (! $this->isValue($arrayItem->key, $constantName)) {
return true;
}
// already converted
if ($arrayItem->value instanceof FuncCall) {
return true;
}
return ! $arrayItem->value instanceof Array_;
}
private function shouldSkipNestedArrayItem(?ArrayItem $nestedArrayItem): bool
{
if (! $nestedArrayItem instanceof ArrayItem) {
return true;
}
if ($nestedArrayItem->key === null) {
return true;
}
if (! $nestedArrayItem->key instanceof String_) {
return true;
}
return ! $nestedArrayItem->value instanceof Array_;
}
}

View File

@ -0,0 +1,41 @@
<?php
namespace Rector\SymfonyPhpConfig\Tests\Rector\MethodCall\ReplaceArrayWithObjectRector\Fixture;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Twig_Node' => [
'getLine' => 'getTemplateLine',
'getFilename' => 'getTemplateName',
],
'Twig_Template' => [
'getSource' => 'getSourceContext',
],
]]]);
}
?>
-----
<?php
namespace Rector\SymfonyPhpConfig\Tests\Rector\MethodCall\ReplaceArrayWithObjectRector\Fixture;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => \Rector\SymfonyPhpConfig\inline_value_objects([new \Rector\Renaming\ValueObject\MethodCallRename('Twig_Node', 'getLine', 'getTemplateLine'), new \Rector\Renaming\ValueObject\MethodCallRename('Twig_Node', 'getFilename', 'getTemplateName'), new \Rector\Renaming\ValueObject\MethodCallRename('Twig_Template', 'getSource', 'getSourceContext')])]]);
}
?>

View File

@ -0,0 +1,41 @@
<?php
namespace Rector\SymfonyPhpConfig\Tests\Rector\MethodCall\ReplaceArrayWithObjectRector\Fixture;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => [
'Illuminate\Auth\Access\Gate' => [
'access' => 'inspect',
]
]]
]);
}
?>
-----
<?php
namespace Rector\SymfonyPhpConfig\Tests\Rector\MethodCall\ReplaceArrayWithObjectRector\Fixture;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS => \Rector\SymfonyPhpConfig\inline_value_objects([
new \Rector\Renaming\ValueObject\MethodCallRename('Illuminate\Auth\Access\Gate', 'access', 'inspect')
])]
]);
}
?>

View File

@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace Rector\SymfonyPhpConfig\Tests\Rector\ArrayItem\ReplaceArrayWithObjectRector;
use Iterator;
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\SymfonyPhpConfig\Rector\ArrayItem\ReplaceArrayWithObjectRector;
use Symplify\SmartFileSystem\SmartFileInfo;
final class ReplaceArrayWithObjectRectorTest 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 [
ReplaceArrayWithObjectRector::class => [
ReplaceArrayWithObjectRector::CONSTANT_NAMES_TO_VALUE_OBJECTS => [
'Rector\Renaming\Rector\MethodCall\RenameMethodRector::OLD_TO_NEW_METHODS_BY_CLASS' => MethodCallRename::class,
],
],
];
}
}

View File

@ -1,4 +1,8 @@
services:
# -
# class: Rector\PHPStanExtensions\Rule\ForbiddenComplexArrayConfigInSetRule
# tags: [phpstan.rules.rule]
-
class: Rector\PHPStanExtensions\Rule\ForbiddenArrayWithStringKeysRule
tags: [phpstan.rules.rule]

View File

@ -0,0 +1,88 @@
<?php
declare(strict_types=1);
namespace Rector\PHPStanExtensions\Rule;
use PhpParser\Node;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\ClassConstFetch;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\Native\NativeParameterReflection;
use PHPStan\Rules\Rule;
use PHPStan\Type\ObjectType;
/**
* @todo make part of core symplify
* @see \Rector\PHPStanExtensions\Tests\Rule\ForbiddenComplexArrayConfigInSetRule\ForbiddenComplexArrayConfigInSetRuleTest
*/
final class ForbiddenComplexArrayConfigInSetRule implements Rule
{
/**
* @var string
*/
public const ERROR_MESSAGE = 'For complex configuration use value object over array';
public function getNodeType(): string
{
return ArrayItem::class;
}
/**
* @param ArrayItem $node
* @return string[]
*/
public function processNode(Node $node, Scope $scope): array
{
// typical for configuration
if (! $node->key instanceof ClassConstFetch) {
return [];
}
if (! $this->isInSymfonyPhpConfigClosure($scope)) {
return [];
}
// simple → skip
if (! $node->value instanceof Array_) {
return [];
}
$valueArray = $node->value;
foreach ($valueArray->items as $nestedItem) {
if (! $nestedItem instanceof ArrayItem) {
continue;
}
// way too complex
if ($nestedItem->value instanceof Array_) {
return [self::ERROR_MESSAGE];
}
}
return [];
}
private function isInSymfonyPhpConfigClosure(Scope $scope): bool
{
// we are in a closure
if ($scope->getAnonymousFunctionReflection() === null) {
return false;
}
if (count($scope->getAnonymousFunctionReflection()->getParameters()) !== 1) {
return false;
}
/** @var NativeParameterReflection $onlyParameter */
$onlyParameter = $scope->getAnonymousFunctionReflection()->getParameters()[0];
$onlyParameterType = $onlyParameter->getType();
$containerConfiguratorObjectType = new ObjectType(
'Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator'
);
return $onlyParameterType->isSuperTypeOf($containerConfiguratorObjectType)->yes();
}
}

View File

@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace Rector\PHPStanExtensions\Tests\Rule\ForbiddenComplexArrayConfigInSetRule\Fixture;
use Rector\Generic\Rector\MethodCall\ServiceGetterToConstructorInjectionRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(ServiceGetterToConstructorInjectionRector::class)
->call('configure', [[
ServiceGetterToConstructorInjectionRector::METHOD_NAMES_BY_TYPES_TO_SERVICE_TYPES => [
'Doctrine\Common\Persistence\ManagerRegistry' => [
'getConnection' => 'Doctrine\DBAL\Connection',
],
],
]]);
};

View File

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace Rector\PHPStanExtensions\Tests\Rule\ForbiddenComplexArrayConfigInSetRule\Fixture;
use Rector\Generic\Rector\MethodCall\ServiceGetterToConstructorInjectionRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(ServiceGetterToConstructorInjectionRector::class)
->call('configure', [[
ServiceGetterToConstructorInjectionRector::METHOD_NAMES_BY_TYPES_TO_SERVICE_TYPES => [
'Doctrine\Common\Persistence\ManagerRegistry' => 'simple'
]
]]);
};

View File

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace Rector\PHPStanExtensions\Tests\Rule\ForbiddenComplexArrayConfigInSetRule;
use Iterator;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use Rector\PHPStanExtensions\Rule\ForbiddenComplexArrayConfigInSetRule;
final class ForbiddenComplexArrayConfigInSetRuleTest extends RuleTestCase
{
/**
* @dataProvider provideData()
*/
public function testRule(string $filePath, array $expectedErrorsWithLines): void
{
$this->analyse([$filePath], $expectedErrorsWithLines);
}
public function provideData(): Iterator
{
yield [__DIR__ . '/Fixture/ComplexConfig.php', [[ForbiddenComplexArrayConfigInSetRule::ERROR_MESSAGE, 15]]];
yield [__DIR__ . '/Fixture/SkipSimpleConfig.php', []];
}
protected function getRule(): Rule
{
return new ForbiddenComplexArrayConfigInSetRule();
}
}