Updated Rector to commit 40ab9ab2b4d529c8d465d5730c29b09efd5ed3ba

40ab9ab2b4 Move Rector Laravel to the community (#3019)
This commit is contained in:
Tomas Votruba 2022-10-27 17:45:09 +00:00
parent d8598b36c0
commit 52256749df
82 changed files with 17 additions and 4950 deletions

View File

@ -8,7 +8,7 @@ Rector instantly upgrades and refactors the PHP code of your application. It ca
### 1. Instant Upgrades
Rector now supports upgrades from PHP 5.3 to 8.1 and major open-source projects like [Symfony](https://github.com/rectorphp/rector-symfony), [PHPUnit](https://github.com/rectorphp/rector-phpunit), [Laravel](https://github.com/rectorphp/rector-laravel), and [Doctrine](https://github.com/rectorphp/rector-doctrine). Do you want to **be constantly on the latest PHP and Framework without effort**?
Rector now supports upgrades from PHP 5.3 to 8.1 and major open-source projects like [Symfony](https://github.com/rectorphp/rector-symfony), [PHPUnit](https://github.com/rectorphp/rector-phpunit), and [Doctrine](https://github.com/rectorphp/rector-doctrine). Do you want to **be constantly on the latest PHP and Framework without effort**?
Use Rector to handle **instant upgrades** for you.

View File

@ -23,7 +23,6 @@
"rector/rector-phpunit": "*",
"rector/rector-symfony": "*",
"rector/rector-doctrine": "*",
"rector/rector-laravel": "*",
"rector/rector-phpoffice": "*",
"rector/rector-php-parser": "*",
"rector/rector-downgrade-php": "*"

View File

@ -17,12 +17,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '4bf158721cf9fb872cda789f446709e6967a983f';
public const PACKAGE_VERSION = '40ab9ab2b4d529c8d465d5730c29b09efd5ed3ba';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2022-10-27 18:22:33';
public const RELEASE_DATE = '2022-10-27 19:39:22';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit2e654942ae56138f7908bab73a36df2b::getLoader();
return ComposerAutoloaderInitc793b2903aefa0a9aada52e902460e8f::getLoader();

View File

@ -1788,41 +1788,6 @@ return array(
'Rector\\FileSystemRector\\Parser\\FileInfoParser' => $baseDir . '/packages/FileSystemRector/Parser/FileInfoParser.php',
'Rector\\FileSystemRector\\ValueObject\\AddedFileWithContent' => $baseDir . '/packages/FileSystemRector/ValueObject/AddedFileWithContent.php',
'Rector\\FileSystemRector\\ValueObject\\AddedFileWithNodes' => $baseDir . '/packages/FileSystemRector/ValueObject/AddedFileWithNodes.php',
'Rector\\Laravel\\NodeAnalyzer\\LumenRouteRegisteringMethodAnalyzer' => $vendorDir . '/rector/rector-laravel/src/NodeAnalyzer/LumenRouteRegisteringMethodAnalyzer.php',
'Rector\\Laravel\\NodeAnalyzer\\StaticCallAnalyzer' => $vendorDir . '/rector/rector-laravel/src/NodeAnalyzer/StaticCallAnalyzer.php',
'Rector\\Laravel\\NodeFactory\\AppAssignFactory' => $vendorDir . '/rector/rector-laravel/src/NodeFactory/AppAssignFactory.php',
'Rector\\Laravel\\NodeFactory\\ModelFactoryNodeFactory' => $vendorDir . '/rector/rector-laravel/src/NodeFactory/ModelFactoryNodeFactory.php',
'Rector\\Laravel\\NodeFactory\\RouterRegisterNodeAnalyzer' => $vendorDir . '/rector/rector-laravel/src/NodeFactory/RouterRegisterNodeAnalyzer.php',
'Rector\\Laravel\\Rector\\Assign\\CallOnAppArrayAccessToStandaloneAssignRector' => $vendorDir . '/rector/rector-laravel/src/Rector/Assign/CallOnAppArrayAccessToStandaloneAssignRector.php',
'Rector\\Laravel\\Rector\\ClassMethod\\AddArgumentDefaultValueRector' => $vendorDir . '/rector/rector-laravel/src/Rector/ClassMethod/AddArgumentDefaultValueRector.php',
'Rector\\Laravel\\Rector\\ClassMethod\\AddGenericReturnTypeToRelationsRector' => $vendorDir . '/rector/rector-laravel/src/Rector/ClassMethod/AddGenericReturnTypeToRelationsRector.php',
'Rector\\Laravel\\Rector\\ClassMethod\\AddParentBootToModelClassMethodRector' => $vendorDir . '/rector/rector-laravel/src/Rector/ClassMethod/AddParentBootToModelClassMethodRector.php',
'Rector\\Laravel\\Rector\\ClassMethod\\AddParentRegisterToEventServiceProviderRector' => $vendorDir . '/rector/rector-laravel/src/Rector/ClassMethod/AddParentRegisterToEventServiceProviderRector.php',
'Rector\\Laravel\\Rector\\Class_\\AddMockConsoleOutputFalseToConsoleTestsRector' => $vendorDir . '/rector/rector-laravel/src/Rector/Class_/AddMockConsoleOutputFalseToConsoleTestsRector.php',
'Rector\\Laravel\\Rector\\Class_\\AnonymousMigrationsRector' => $vendorDir . '/rector/rector-laravel/src/Rector/Class_/AnonymousMigrationsRector.php',
'Rector\\Laravel\\Rector\\Class_\\PropertyDeferToDeferrableProviderToRector' => $vendorDir . '/rector/rector-laravel/src/Rector/Class_/PropertyDeferToDeferrableProviderToRector.php',
'Rector\\Laravel\\Rector\\Class_\\UnifyModelDatesWithCastsRector' => $vendorDir . '/rector/rector-laravel/src/Rector/Class_/UnifyModelDatesWithCastsRector.php',
'Rector\\Laravel\\Rector\\FuncCall\\FactoryFuncCallToStaticCallRector' => $vendorDir . '/rector/rector-laravel/src/Rector/FuncCall/FactoryFuncCallToStaticCallRector.php',
'Rector\\Laravel\\Rector\\FuncCall\\HelperFuncCallToFacadeClassRector' => $vendorDir . '/rector/rector-laravel/src/Rector/FuncCall/HelperFuncCallToFacadeClassRector.php',
'Rector\\Laravel\\Rector\\FuncCall\\RemoveDumpDataDeadCodeRector' => $vendorDir . '/rector/rector-laravel/src/Rector/FuncCall/RemoveDumpDataDeadCodeRector.php',
'Rector\\Laravel\\Rector\\MethodCall\\ChangeQueryWhereDateValueWithCarbonRector' => $vendorDir . '/rector/rector-laravel/src/Rector/MethodCall/ChangeQueryWhereDateValueWithCarbonRector.php',
'Rector\\Laravel\\Rector\\MethodCall\\FactoryApplyingStatesRector' => $vendorDir . '/rector/rector-laravel/src/Rector/MethodCall/FactoryApplyingStatesRector.php',
'Rector\\Laravel\\Rector\\MethodCall\\LumenRoutesStringActionToUsesArrayRector' => $vendorDir . '/rector/rector-laravel/src/Rector/MethodCall/LumenRoutesStringActionToUsesArrayRector.php',
'Rector\\Laravel\\Rector\\MethodCall\\LumenRoutesStringMiddlewareToArrayRector' => $vendorDir . '/rector/rector-laravel/src/Rector/MethodCall/LumenRoutesStringMiddlewareToArrayRector.php',
'Rector\\Laravel\\Rector\\MethodCall\\RedirectBackToBackHelperRector' => $vendorDir . '/rector/rector-laravel/src/Rector/MethodCall/RedirectBackToBackHelperRector.php',
'Rector\\Laravel\\Rector\\MethodCall\\RedirectRouteToToRouteHelperRector' => $vendorDir . '/rector/rector-laravel/src/Rector/MethodCall/RedirectRouteToToRouteHelperRector.php',
'Rector\\Laravel\\Rector\\Namespace_\\FactoryDefinitionRector' => $vendorDir . '/rector/rector-laravel/src/Rector/Namespace_/FactoryDefinitionRector.php',
'Rector\\Laravel\\Rector\\New_\\AddGuardToLoginEventRector' => $vendorDir . '/rector/rector-laravel/src/Rector/New_/AddGuardToLoginEventRector.php',
'Rector\\Laravel\\Rector\\PropertyFetch\\OptionalToNullsafeOperatorRector' => $vendorDir . '/rector/rector-laravel/src/Rector/PropertyFetch/OptionalToNullsafeOperatorRector.php',
'Rector\\Laravel\\Rector\\StaticCall\\MinutesToSecondsInCacheRector' => $vendorDir . '/rector/rector-laravel/src/Rector/StaticCall/MinutesToSecondsInCacheRector.php',
'Rector\\Laravel\\Rector\\StaticCall\\Redirect301ToPermanentRedirectRector' => $vendorDir . '/rector/rector-laravel/src/Rector/StaticCall/Redirect301ToPermanentRedirectRector.php',
'Rector\\Laravel\\Rector\\StaticCall\\RequestStaticValidateToInjectRector' => $vendorDir . '/rector/rector-laravel/src/Rector/StaticCall/RequestStaticValidateToInjectRector.php',
'Rector\\Laravel\\Rector\\StaticCall\\RouteActionCallableRector' => $vendorDir . '/rector/rector-laravel/src/Rector/StaticCall/RouteActionCallableRector.php',
'Rector\\Laravel\\Set\\LaravelLevelSetList' => $vendorDir . '/rector/rector-laravel/src/Set/LaravelLevelSetList.php',
'Rector\\Laravel\\Set\\LaravelSetList' => $vendorDir . '/rector/rector-laravel/src/Set/LaravelSetList.php',
'Rector\\Laravel\\ValueObject\\AddArgumentDefaultValue' => $vendorDir . '/rector/rector-laravel/src/ValueObject/AddArgumentDefaultValue.php',
'Rector\\Laravel\\ValueObject\\ServiceNameTypeAndVariableName' => $vendorDir . '/rector/rector-laravel/src/ValueObject/ServiceNameTypeAndVariableName.php',
'Rector\\Laravel\\ValueObject\\TypeToTimeMethodAndPosition' => $vendorDir . '/rector/rector-laravel/src/ValueObject/TypeToTimeMethodAndPosition.php',
'Rector\\MysqlToMysqli\\Rector\\Assign\\MysqlAssignToMysqliRector' => $baseDir . '/rules/MysqlToMysqli/Rector/Assign/MysqlAssignToMysqliRector.php',
'Rector\\MysqlToMysqli\\Rector\\FuncCall\\MysqlFuncCallToMysqliRector' => $baseDir . '/rules/MysqlToMysqli/Rector/FuncCall/MysqlFuncCallToMysqliRector.php',
'Rector\\MysqlToMysqli\\Rector\\FuncCall\\MysqlPConnectToMysqliConnectRector' => $baseDir . '/rules/MysqlToMysqli/Rector/FuncCall/MysqlPConnectToMysqliConnectRector.php',

View File

@ -15,7 +15,6 @@ return array(
'Rector\\PhpParser\\' => array($vendorDir . '/rector/rector-php-parser/src'),
'Rector\\PHPUnit\\' => array($vendorDir . '/rector/rector-phpunit/src'),
'Rector\\PHPOffice\\' => array($vendorDir . '/rector/rector-phpoffice/src'),
'Rector\\Laravel\\' => array($vendorDir . '/rector/rector-laravel/src'),
'Rector\\Doctrine\\' => array($vendorDir . '/rector/rector-doctrine/src'),
'Rector\\Core\\' => array($baseDir . '/src'),
'Rector\\' => array($baseDir . '/packages', $baseDir . '/rules', $vendorDir . '/rector/rector-downgrade-php/src', $vendorDir . '/rector/rector-downgrade-php/rules'),

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit2e654942ae56138f7908bab73a36df2b
class ComposerAutoloaderInitc793b2903aefa0a9aada52e902460e8f
{
private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInit2e654942ae56138f7908bab73a36df2b
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit2e654942ae56138f7908bab73a36df2b', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitc793b2903aefa0a9aada52e902460e8f', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit2e654942ae56138f7908bab73a36df2b', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitc793b2903aefa0a9aada52e902460e8f', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit2e654942ae56138f7908bab73a36df2b::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitc793b2903aefa0a9aada52e902460e8f::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInit2e654942ae56138f7908bab73a36df2b::$files;
$includeFiles = \Composer\Autoload\ComposerStaticInitc793b2903aefa0a9aada52e902460e8f::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire2e654942ae56138f7908bab73a36df2b($fileIdentifier, $file);
composerRequirec793b2903aefa0a9aada52e902460e8f($fileIdentifier, $file);
}
return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInit2e654942ae56138f7908bab73a36df2b
* @param string $file
* @return void
*/
function composerRequire2e654942ae56138f7908bab73a36df2b($fileIdentifier, $file)
function composerRequirec793b2903aefa0a9aada52e902460e8f($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit2e654942ae56138f7908bab73a36df2b
class ComposerStaticInitc793b2903aefa0a9aada52e902460e8f
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -32,7 +32,6 @@ class ComposerStaticInit2e654942ae56138f7908bab73a36df2b
'Rector\\PhpParser\\' => 17,
'Rector\\PHPUnit\\' => 15,
'Rector\\PHPOffice\\' => 17,
'Rector\\Laravel\\' => 15,
'Rector\\Doctrine\\' => 16,
'Rector\\Core\\' => 12,
'Rector\\' => 7,
@ -111,10 +110,6 @@ class ComposerStaticInit2e654942ae56138f7908bab73a36df2b
array (
0 => __DIR__ . '/..' . '/rector/rector-phpoffice/src',
),
'Rector\\Laravel\\' =>
array (
0 => __DIR__ . '/..' . '/rector/rector-laravel/src',
),
'Rector\\Doctrine\\' =>
array (
0 => __DIR__ . '/..' . '/rector/rector-doctrine/src',
@ -2043,41 +2038,6 @@ class ComposerStaticInit2e654942ae56138f7908bab73a36df2b
'Rector\\FileSystemRector\\Parser\\FileInfoParser' => __DIR__ . '/../..' . '/packages/FileSystemRector/Parser/FileInfoParser.php',
'Rector\\FileSystemRector\\ValueObject\\AddedFileWithContent' => __DIR__ . '/../..' . '/packages/FileSystemRector/ValueObject/AddedFileWithContent.php',
'Rector\\FileSystemRector\\ValueObject\\AddedFileWithNodes' => __DIR__ . '/../..' . '/packages/FileSystemRector/ValueObject/AddedFileWithNodes.php',
'Rector\\Laravel\\NodeAnalyzer\\LumenRouteRegisteringMethodAnalyzer' => __DIR__ . '/..' . '/rector/rector-laravel/src/NodeAnalyzer/LumenRouteRegisteringMethodAnalyzer.php',
'Rector\\Laravel\\NodeAnalyzer\\StaticCallAnalyzer' => __DIR__ . '/..' . '/rector/rector-laravel/src/NodeAnalyzer/StaticCallAnalyzer.php',
'Rector\\Laravel\\NodeFactory\\AppAssignFactory' => __DIR__ . '/..' . '/rector/rector-laravel/src/NodeFactory/AppAssignFactory.php',
'Rector\\Laravel\\NodeFactory\\ModelFactoryNodeFactory' => __DIR__ . '/..' . '/rector/rector-laravel/src/NodeFactory/ModelFactoryNodeFactory.php',
'Rector\\Laravel\\NodeFactory\\RouterRegisterNodeAnalyzer' => __DIR__ . '/..' . '/rector/rector-laravel/src/NodeFactory/RouterRegisterNodeAnalyzer.php',
'Rector\\Laravel\\Rector\\Assign\\CallOnAppArrayAccessToStandaloneAssignRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/Assign/CallOnAppArrayAccessToStandaloneAssignRector.php',
'Rector\\Laravel\\Rector\\ClassMethod\\AddArgumentDefaultValueRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/ClassMethod/AddArgumentDefaultValueRector.php',
'Rector\\Laravel\\Rector\\ClassMethod\\AddGenericReturnTypeToRelationsRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/ClassMethod/AddGenericReturnTypeToRelationsRector.php',
'Rector\\Laravel\\Rector\\ClassMethod\\AddParentBootToModelClassMethodRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/ClassMethod/AddParentBootToModelClassMethodRector.php',
'Rector\\Laravel\\Rector\\ClassMethod\\AddParentRegisterToEventServiceProviderRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/ClassMethod/AddParentRegisterToEventServiceProviderRector.php',
'Rector\\Laravel\\Rector\\Class_\\AddMockConsoleOutputFalseToConsoleTestsRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/Class_/AddMockConsoleOutputFalseToConsoleTestsRector.php',
'Rector\\Laravel\\Rector\\Class_\\AnonymousMigrationsRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/Class_/AnonymousMigrationsRector.php',
'Rector\\Laravel\\Rector\\Class_\\PropertyDeferToDeferrableProviderToRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/Class_/PropertyDeferToDeferrableProviderToRector.php',
'Rector\\Laravel\\Rector\\Class_\\UnifyModelDatesWithCastsRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/Class_/UnifyModelDatesWithCastsRector.php',
'Rector\\Laravel\\Rector\\FuncCall\\FactoryFuncCallToStaticCallRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/FuncCall/FactoryFuncCallToStaticCallRector.php',
'Rector\\Laravel\\Rector\\FuncCall\\HelperFuncCallToFacadeClassRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/FuncCall/HelperFuncCallToFacadeClassRector.php',
'Rector\\Laravel\\Rector\\FuncCall\\RemoveDumpDataDeadCodeRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/FuncCall/RemoveDumpDataDeadCodeRector.php',
'Rector\\Laravel\\Rector\\MethodCall\\ChangeQueryWhereDateValueWithCarbonRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/MethodCall/ChangeQueryWhereDateValueWithCarbonRector.php',
'Rector\\Laravel\\Rector\\MethodCall\\FactoryApplyingStatesRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/MethodCall/FactoryApplyingStatesRector.php',
'Rector\\Laravel\\Rector\\MethodCall\\LumenRoutesStringActionToUsesArrayRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/MethodCall/LumenRoutesStringActionToUsesArrayRector.php',
'Rector\\Laravel\\Rector\\MethodCall\\LumenRoutesStringMiddlewareToArrayRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/MethodCall/LumenRoutesStringMiddlewareToArrayRector.php',
'Rector\\Laravel\\Rector\\MethodCall\\RedirectBackToBackHelperRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/MethodCall/RedirectBackToBackHelperRector.php',
'Rector\\Laravel\\Rector\\MethodCall\\RedirectRouteToToRouteHelperRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/MethodCall/RedirectRouteToToRouteHelperRector.php',
'Rector\\Laravel\\Rector\\Namespace_\\FactoryDefinitionRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/Namespace_/FactoryDefinitionRector.php',
'Rector\\Laravel\\Rector\\New_\\AddGuardToLoginEventRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/New_/AddGuardToLoginEventRector.php',
'Rector\\Laravel\\Rector\\PropertyFetch\\OptionalToNullsafeOperatorRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/PropertyFetch/OptionalToNullsafeOperatorRector.php',
'Rector\\Laravel\\Rector\\StaticCall\\MinutesToSecondsInCacheRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/StaticCall/MinutesToSecondsInCacheRector.php',
'Rector\\Laravel\\Rector\\StaticCall\\Redirect301ToPermanentRedirectRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/StaticCall/Redirect301ToPermanentRedirectRector.php',
'Rector\\Laravel\\Rector\\StaticCall\\RequestStaticValidateToInjectRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/StaticCall/RequestStaticValidateToInjectRector.php',
'Rector\\Laravel\\Rector\\StaticCall\\RouteActionCallableRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/StaticCall/RouteActionCallableRector.php',
'Rector\\Laravel\\Set\\LaravelLevelSetList' => __DIR__ . '/..' . '/rector/rector-laravel/src/Set/LaravelLevelSetList.php',
'Rector\\Laravel\\Set\\LaravelSetList' => __DIR__ . '/..' . '/rector/rector-laravel/src/Set/LaravelSetList.php',
'Rector\\Laravel\\ValueObject\\AddArgumentDefaultValue' => __DIR__ . '/..' . '/rector/rector-laravel/src/ValueObject/AddArgumentDefaultValue.php',
'Rector\\Laravel\\ValueObject\\ServiceNameTypeAndVariableName' => __DIR__ . '/..' . '/rector/rector-laravel/src/ValueObject/ServiceNameTypeAndVariableName.php',
'Rector\\Laravel\\ValueObject\\TypeToTimeMethodAndPosition' => __DIR__ . '/..' . '/rector/rector-laravel/src/ValueObject/TypeToTimeMethodAndPosition.php',
'Rector\\MysqlToMysqli\\Rector\\Assign\\MysqlAssignToMysqliRector' => __DIR__ . '/../..' . '/rules/MysqlToMysqli/Rector/Assign/MysqlAssignToMysqliRector.php',
'Rector\\MysqlToMysqli\\Rector\\FuncCall\\MysqlFuncCallToMysqliRector' => __DIR__ . '/../..' . '/rules/MysqlToMysqli/Rector/FuncCall/MysqlFuncCallToMysqliRector.php',
'Rector\\MysqlToMysqli\\Rector\\FuncCall\\MysqlPConnectToMysqliConnectRector' => __DIR__ . '/../..' . '/rules/MysqlToMysqli/Rector/FuncCall/MysqlPConnectToMysqliConnectRector.php',
@ -3081,9 +3041,9 @@ class ComposerStaticInit2e654942ae56138f7908bab73a36df2b
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit2e654942ae56138f7908bab73a36df2b::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit2e654942ae56138f7908bab73a36df2b::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit2e654942ae56138f7908bab73a36df2b::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitc793b2903aefa0a9aada52e902460e8f::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitc793b2903aefa0a9aada52e902460e8f::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitc793b2903aefa0a9aada52e902460e8f::$classMap;
}, null, ClassLoader::class);
}

View File

@ -1917,74 +1917,6 @@
},
"install-path": "..\/rector\/rector-downgrade-php"
},
{
"name": "rector\/rector-laravel",
"version": "dev-main",
"version_normalized": "dev-main",
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-laravel.git",
"reference": "2decdcfeef9d117e4589ebc9e7fdbab11c030813"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-laravel\/zipball\/2decdcfeef9d117e4589ebc9e7fdbab11c030813",
"reference": "2decdcfeef9d117e4589ebc9e7fdbab11c030813",
"shasum": ""
},
"require": {
"php": ">=8.1"
},
"conflict": {
"rector\/rector": "<0.11"
},
"require-dev": {
"phpstan\/extension-installer": "^1.1",
"phpstan\/phpstan": "^1.8.2",
"phpstan\/phpstan-strict-rules": "^1.2",
"phpstan\/phpstan-webmozart-assert": "^1.1",
"phpunit\/phpunit": "^9.5",
"rector\/phpstan-rules": "^0.6",
"rector\/rector-debugging": "dev-main",
"rector\/rector-src": "dev-main",
"symplify\/easy-coding-standard": "^11.0",
"symplify\/monorepo-builder": "^11.0",
"symplify\/phpstan-extensions": "^11.0",
"symplify\/phpstan-rules": "^11.0",
"symplify\/rule-doc-generator": "^11.0",
"symplify\/vendor-patches": "^11.0"
},
"time": "2022-09-02T10:58:00+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
"enable-patching": true,
"branch-alias": {
"dev-main": "0.11-dev"
},
"rector": {
"includes": [
"config\/config.php"
]
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Rector\\Laravel\\": "src"
}
},
"notification-url": "https:\/\/packagist.org\/downloads\/",
"license": [
"MIT"
],
"description": "Rector upgrades rules for Laravel Framework",
"support": {
"issues": "https:\/\/github.com\/rectorphp\/rector-laravel\/issues",
"source": "https:\/\/github.com\/rectorphp\/rector-laravel\/tree\/main"
},
"install-path": "..\/rector\/rector-laravel"
},
{
"name": "rector\/rector-php-parser",
"version": "dev-main",

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
*/
final class GeneratedConfig
{
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 17bdb82'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main da1013f'), 'rector/rector-laravel' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-laravel', 'relative_install_path' => '../../rector-laravel', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 2decdcf'), 'rector/rector-php-parser' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-php-parser', 'relative_install_path' => '../../rector-php-parser', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9c21f5f'), 'rector/rector-phpoffice' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpoffice', 'relative_install_path' => '../../rector-phpoffice', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 294de0c'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 6fc267c'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 644c5a4'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 17bdb82'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main da1013f'), 'rector/rector-php-parser' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-php-parser', 'relative_install_path' => '../../rector-php-parser', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9c21f5f'), 'rector/rector-phpoffice' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpoffice', 'relative_install_path' => '../../rector-phpoffice', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 294de0c'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 6fc267c'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 644c5a4'));
private function __construct()
{
}

View File

@ -1,25 +0,0 @@
The MIT License
---------------
Copyright (c) 2017-present Tomáš Votruba (https://tomasvotruba.cz)
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

View File

@ -1,39 +0,0 @@
# Rector Rules for Laravel
See available [Laravel rules](/docs/rector_rules_overview.md)
## Install
This package is already part of [rector/rector](http://github.com/rectorphp/rector) package, so it works out of the box.
All you need to do is install the main package, and you're good to go:
```bash
composer require rector/rector --dev
```
## Use Sets
To add a set to your config, use `Rector\Laravel\Set\LaravelSetList` class and pick one of constants:
```php
use Rector\Laravel\Set\LaravelSetList;
use Rector\Config\RectorConfig;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([
LaravelSetList::LARAVEL_90
]);
};
```
<br>
## Learn Rector Faster
Rector is a tool that [we develop](https://getrector.org/) and share for free, so anyone can save hundreds of hours on refactoring. But not everyone has time to understand Rector and AST complexity. You have 2 ways to speed this process up:
* read a book - <a href="https://leanpub.com/rector-the-power-of-automated-refactoring">The Power of Automated Refactoring</a>
* hire our experienced team to <a href="https://getrector.org/contact">improve your code base</a>
Both ways support us to and improve Rector in sustainable way by learning from practical projects.

View File

@ -1,71 +0,0 @@
{
"name": "rector\/rector-laravel",
"type": "rector-extension",
"license": "MIT",
"description": "Rector upgrades rules for Laravel Framework",
"require": {
"php": ">=8.1"
},
"require-dev": {
"rector\/rector-src": "dev-main",
"phpunit\/phpunit": "^9.5",
"phpstan\/phpstan": "^1.8.2",
"symplify\/phpstan-rules": "^11.0",
"symplify\/phpstan-extensions": "^11.0",
"symplify\/easy-coding-standard": "^11.0",
"symplify\/rule-doc-generator": "^11.0",
"symplify\/monorepo-builder": "^11.0",
"rector\/phpstan-rules": "^0.6",
"phpstan\/extension-installer": "^1.1",
"phpstan\/phpstan-webmozart-assert": "^1.1",
"phpstan\/phpstan-strict-rules": "^1.2",
"symplify\/vendor-patches": "^11.0",
"rector\/rector-debugging": "dev-main"
},
"autoload": {
"psr-4": {
"Rector\\Laravel\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Rector\\Laravel\\Tests\\": "tests"
},
"classmap": [
"stubs"
]
},
"scripts": {
"release": "vendor\/bin\/monorepo-builder release patch --ansi",
"phpstan": "vendor\/bin\/phpstan analyse --ansi --error-format symplify",
"check-cs": "vendor\/bin\/ecs check --ansi",
"fix-cs": "vendor\/bin\/ecs check --fix --ansi",
"docs": [
"vendor\/bin\/rule-doc-generator generate src --output-file docs\/rector_rules_overview.md --ansi",
"vendor\/bin\/ecs check-markdown docs\/rector_rules_overview.md --ansi --fix"
]
},
"extra": {
"enable-patching": true,
"branch-alias": {
"dev-main": "0.11-dev"
},
"rector": {
"includes": [
"config\/config.php"
]
}
},
"conflict": {
"rector\/rector": "<0.11"
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"allow-plugins": {
"cweagans\/composer-patches": true,
"rector\/extension-installer": true,
"phpstan\/extension-installer": true
}
}
}

View File

@ -1,13 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Core\NonPhpFile\Rector\RenameClassNonPhpRector;
return static function (RectorConfig $rectorConfig) : void {
$services = $rectorConfig->services();
$services->defaults()->public()->autowire()->autoconfigure();
$services->load('Rector\\Laravel\\', __DIR__ . '/../src')->exclude([__DIR__ . '/../src/{Rector,ValueObject}']);
$services->set(RenameClassNonPhpRector::class);
};

View File

@ -1,13 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Transform\Rector\FuncCall\FuncCallToStaticCallRector;
use Rector\Transform\ValueObject\FuncCallToStaticCall;
// @see https://medium.freecodecamp.org/moving-away-from-magic-or-why-i-dont-want-to-use-laravel-anymore-2ce098c979bd
// @see https://laravel.com/docs/5.7/facades#facades-vs-dependency-injection
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->ruleWithConfiguration(FuncCallToStaticCallRector::class, [new FuncCallToStaticCall('array_add', 'Illuminate\\Support\\Arr', 'add'), new FuncCallToStaticCall('array_collapse', 'Illuminate\\Support\\Arr', 'collapse'), new FuncCallToStaticCall('array_divide', 'Illuminate\\Support\\Arr', 'divide'), new FuncCallToStaticCall('array_dot', 'Illuminate\\Support\\Arr', 'dot'), new FuncCallToStaticCall('array_except', 'Illuminate\\Support\\Arr', 'except'), new FuncCallToStaticCall('array_first', 'Illuminate\\Support\\Arr', 'first'), new FuncCallToStaticCall('array_flatten', 'Illuminate\\Support\\Arr', 'flatten'), new FuncCallToStaticCall('array_forget', 'Illuminate\\Support\\Arr', 'forget'), new FuncCallToStaticCall('array_get', 'Illuminate\\Support\\Arr', 'get'), new FuncCallToStaticCall('array_has', 'Illuminate\\Support\\Arr', 'has'), new FuncCallToStaticCall('array_last', 'Illuminate\\Support\\Arr', 'last'), new FuncCallToStaticCall('array_only', 'Illuminate\\Support\\Arr', 'only'), new FuncCallToStaticCall('array_pluck', 'Illuminate\\Support\\Arr', 'pluck'), new FuncCallToStaticCall('array_prepend', 'Illuminate\\Support\\Arr', 'prepend'), new FuncCallToStaticCall('array_pull', 'Illuminate\\Support\\Arr', 'pull'), new FuncCallToStaticCall('array_random', 'Illuminate\\Support\\Arr', 'random'), new FuncCallToStaticCall('array_sort', 'Illuminate\\Support\\Arr', 'sort'), new FuncCallToStaticCall('array_sort_recursive', 'Illuminate\\Support\\Arr', 'sortRecursive'), new FuncCallToStaticCall('array_where', 'Illuminate\\Support\\Arr', 'where'), new FuncCallToStaticCall('array_wrap', 'Illuminate\\Support\\Arr', 'wrap'), new FuncCallToStaticCall('array_set', 'Illuminate\\Support\\Arr', 'set'), new FuncCallToStaticCall('camel_case', 'Illuminate\\Support\\Str', 'camel'), new FuncCallToStaticCall('ends_with', 'Illuminate\\Support\\Str', 'endsWith'), new FuncCallToStaticCall('kebab_case', 'Illuminate\\Support\\Str', 'kebab'), new FuncCallToStaticCall('snake_case', 'Illuminate\\Support\\Str', 'snake'), new FuncCallToStaticCall('starts_with', 'Illuminate\\Support\\Str', 'startsWith'), new FuncCallToStaticCall('str_after', 'Illuminate\\Support\\Str', 'after'), new FuncCallToStaticCall('str_before', 'Illuminate\\Support\\Str', 'before'), new FuncCallToStaticCall('str_contains', 'Illuminate\\Support\\Str', 'contains'), new FuncCallToStaticCall('str_finish', 'Illuminate\\Support\\Str', 'finish'), new FuncCallToStaticCall('str_is', 'Illuminate\\Support\\Str', 'is'), new FuncCallToStaticCall('str_limit', 'Illuminate\\Support\\Str', 'limit'), new FuncCallToStaticCall('str_plural', 'Illuminate\\Support\\Str', 'plural'), new FuncCallToStaticCall('str_random', 'Illuminate\\Support\\Str', 'random'), new FuncCallToStaticCall('str_replace_array', 'Illuminate\\Support\\Str', 'replaceArray'), new FuncCallToStaticCall('str_replace_first', 'Illuminate\\Support\\Str', 'replaceFirst'), new FuncCallToStaticCall('str_replace_last', 'Illuminate\\Support\\Str', 'replaceLast'), new FuncCallToStaticCall('str_singular', 'Illuminate\\Support\\Str', 'singular'), new FuncCallToStaticCall('str_slug', 'Illuminate\\Support\\Str', 'slug'), new FuncCallToStaticCall('str_start', 'Illuminate\\Support\\Str', 'start'), new FuncCallToStaticCall('studly_case', 'Illuminate\\Support\\Str', 'studly'), new FuncCallToStaticCall('title_case', 'Illuminate\\Support\\Str', 'title')]);
};

View File

@ -1,10 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Laravel\Rector\Assign\CallOnAppArrayAccessToStandaloneAssignRector;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->rule(CallOnAppArrayAccessToStandaloneAssignRector::class);
};

View File

@ -1,18 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Laravel\Rector\FuncCall\FactoryFuncCallToStaticCallRector;
use Rector\Laravel\Rector\MethodCall\FactoryApplyingStatesRector;
use Rector\Laravel\Rector\Namespace_\FactoryDefinitionRector;
return static function (RectorConfig $rectorConfig) : void {
// https://laravel.com/docs/7.x/database-testing#writing-factories
// https://laravel.com/docs/8.x/database-testing#defining-model-factories
$rectorConfig->rule(FactoryDefinitionRector::class);
// https://laravel.com/docs/7.x/database-testing#using-factories
// https://laravel.com/docs/8.x/database-testing#creating-models-using-factories
$rectorConfig->rule(FactoryApplyingStatesRector::class);
$rectorConfig->rule(FactoryFuncCallToStaticCallRector::class);
};

View File

@ -1,60 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Laravel\Rector\FuncCall\HelperFuncCallToFacadeClassRector;
use Rector\Laravel\Rector\StaticCall\RequestStaticValidateToInjectRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Transform\Rector\FuncCall\ArgumentFuncCallToMethodCallRector;
use Rector\Transform\Rector\FuncCall\FuncCallToNewRector;
use Rector\Transform\Rector\StaticCall\StaticCallToMethodCallRector;
use Rector\Transform\ValueObject\ArgumentFuncCallToMethodCall;
use Rector\Transform\ValueObject\ArrayFuncCallToMethodCall;
use Rector\Transform\ValueObject\StaticCallToMethodCall;
/**
* @see https://www.freecodecamp.org/news/moving-away-from-magic-or-why-i-dont-want-to-use-laravel-anymore-2ce098c979bd/
* @see https://tomasvotruba.com/blog/2019/03/04/how-to-turn-laravel-from-static-to-dependency-injection-in-one-day/
* @see https://laravel.com/docs/5.7/facades#facades-vs-dependency-injection
*/
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->import(__DIR__ . '/laravel-array-str-functions-to-static-call.php');
$rectorConfig->ruleWithConfiguration(StaticCallToMethodCallRector::class, [new StaticCallToMethodCall('Illuminate\\Support\\Facades\\App', '*', 'Illuminate\\Foundation\\Application', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Artisan', '*', 'Illuminate\\Contracts\\Console\\Kernel', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Auth', '*', 'Illuminate\\Auth\\AuthManager', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Blade', '*', 'Illuminate\\View\\Compilers\\BladeCompiler', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Broadcast', '*', 'Illuminate\\Contracts\\Broadcasting\\Factory', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Bus', '*', 'Illuminate\\Contracts\\Bus\\Dispatcher', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Cache', '*', 'Illuminate\\Cache\\CacheManager', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Config', '*', 'Illuminate\\Config\\Repository', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Cookie', '*', 'Illuminate\\Cookie\\CookieJar', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Crypt', '*', 'Illuminate\\Encryption\\Encrypter', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\DB', '*', 'Illuminate\\Database\\DatabaseManager', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Event', '*', 'Illuminate\\Events\\Dispatcher', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\File', '*', 'Illuminate\\Filesystem\\Filesystem', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Gate', '*', 'Illuminate\\Contracts\\Auth\\Access\\Gate', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Hash', '*', 'Illuminate\\Contracts\\Hashing\\Hasher', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Lang', '*', 'Illuminate\\Translation\\Translator', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Log', '*', 'Illuminate\\Log\\LogManager', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Mail', '*', 'Illuminate\\Mail\\Mailer', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Notification', '*', 'Illuminate\\Notifications\\ChannelManager', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Password', '*', 'Illuminate\\Auth\\Passwords\\PasswordBrokerManager', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Queue', '*', 'Illuminate\\Queue\\QueueManager', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Redirect', '*', 'Illuminate\\Routing\\Redirector', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Redis', '*', 'Illuminate\\Redis\\RedisManager', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Request', '*', 'Illuminate\\Http\\Request', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Response', '*', 'Illuminate\\Contracts\\Routing\\ResponseFactory', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Route', '*', 'Illuminate\\Routing\\Router', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Schema', '*', 'Illuminate\\Database\\Schema\\Builder', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Session', '*', 'Illuminate\\Session\\SessionManager', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Storage', '*', 'Illuminate\\Filesystem\\FilesystemManager', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\URL', '*', 'Illuminate\\Routing\\UrlGenerator', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\Validator', '*', 'Illuminate\\Validation\\Factory', '*'), new StaticCallToMethodCall('Illuminate\\Support\\Facades\\View', '*', 'Illuminate\\View\\Factory', '*')]);
$rectorConfig->rule(RequestStaticValidateToInjectRector::class);
// @see https://github.com/laravel/framework/blob/78828bc779e410e03cc6465f002b834eadf160d2/src/Illuminate/Foundation/helpers.php#L959
// @see https://gist.github.com/barryvdh/bb6ffc5d11e0a75dba67
$rectorConfig->ruleWithConfiguration(ArgumentFuncCallToMethodCallRector::class, [
new ArgumentFuncCallToMethodCall('auth', 'Illuminate\\Contracts\\Auth\\Guard'),
new ArgumentFuncCallToMethodCall('policy', 'Illuminate\\Contracts\\Auth\\Access\\Gate', 'getPolicyFor'),
new ArgumentFuncCallToMethodCall('cookie', 'Illuminate\\Contracts\\Cookie\\Factory', 'make'),
// router
new ArgumentFuncCallToMethodCall('put', 'Illuminate\\Routing\\Router', 'put'),
new ArgumentFuncCallToMethodCall('get', 'Illuminate\\Routing\\Router', 'get'),
new ArgumentFuncCallToMethodCall('post', 'Illuminate\\Routing\\Router', 'post'),
new ArgumentFuncCallToMethodCall('patch', 'Illuminate\\Routing\\Router', 'patch'),
new ArgumentFuncCallToMethodCall('delete', 'Illuminate\\Routing\\Router', 'delete'),
new ArgumentFuncCallToMethodCall('resource', 'Illuminate\\Routing\\Router', 'resource'),
new ArgumentFuncCallToMethodCall('response', 'Illuminate\\Contracts\\Routing\\ResponseFactory', 'make'),
new ArgumentFuncCallToMethodCall('info', 'Illuminate\\Log\\Writer', 'info'),
new ArgumentFuncCallToMethodCall('view', 'Illuminate\\Contracts\\View\\Factory', 'make'),
new ArgumentFuncCallToMethodCall('bcrypt', 'Illuminate\\Hashing\\BcryptHasher', 'make'),
new ArgumentFuncCallToMethodCall('redirect', 'Illuminate\\Routing\\Redirector', 'to'),
new ArgumentFuncCallToMethodCall('broadcast', 'Illuminate\\Contracts\\Broadcasting\\Factory', 'event'),
new ArgumentFuncCallToMethodCall('event', 'Illuminate\\Events\\Dispatcher', 'dispatch'),
new ArgumentFuncCallToMethodCall('dispatch', 'Illuminate\\Events\\Dispatcher', 'dispatch'),
new ArgumentFuncCallToMethodCall('route', 'Illuminate\\Routing\\UrlGenerator', 'route'),
new ArgumentFuncCallToMethodCall('asset', 'Illuminate\\Routing\\UrlGenerator', 'asset'),
new ArgumentFuncCallToMethodCall('url', 'Illuminate\\Contracts\\Routing\\UrlGenerator', 'to'),
new ArgumentFuncCallToMethodCall('action', 'Illuminate\\Routing\\UrlGenerator', 'action'),
new ArgumentFuncCallToMethodCall('trans', 'Illuminate\\Translation\\Translator', 'trans'),
new ArgumentFuncCallToMethodCall('trans_choice', 'Illuminate\\Translation\\Translator', 'transChoice'),
new ArgumentFuncCallToMethodCall('logger', 'Illuminate\\Log\\Writer', 'debug'),
new ArgumentFuncCallToMethodCall('back', 'Illuminate\\Routing\\Redirector', 'back', 'back'),
new ArrayFuncCallToMethodCall('config', 'Illuminate\\Contracts\\Config\\Repository', 'set', 'get'),
new ArrayFuncCallToMethodCall('session', 'Illuminate\\Session\\SessionManager', 'put', 'get'),
]);
$rectorConfig->ruleWithConfiguration(FuncCallToNewRector::class, ['collect' => 'Illuminate\\Support\\Collection']);
$rectorConfig->rule(HelperFuncCallToFacadeClassRector::class);
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, ['App' => 'Illuminate\\Support\\Facades\\App', 'Artisan' => 'Illuminate\\Support\\Facades\\Artisan', 'Auth' => 'Illuminate\\Support\\Facades\\Auth', 'Blade' => 'Illuminate\\Support\\Facades\\Blade', 'Broadcast' => 'Illuminate\\Support\\Facades\\Broadcast', 'Bus' => 'Illuminate\\Support\\Facades\\Bus', 'Cache' => 'Illuminate\\Support\\Facades\\Cache', 'Config' => 'Illuminate\\Support\\Facades\\Config', 'Cookie' => 'Illuminate\\Support\\Facades\\Cookie', 'Crypt' => 'Illuminate\\Support\\Facades\\Crypt', 'DB' => 'Illuminate\\Support\\Facades\\DB', 'Date' => 'Illuminate\\Support\\Facades\\Date', 'Event' => 'Illuminate\\Support\\Facades\\Event', 'Facade' => 'Illuminate\\Support\\Facades\\Facade', 'File' => 'Illuminate\\Support\\Facades\\File', 'Gate' => 'Illuminate\\Support\\Facades\\Gate', 'Hash' => 'Illuminate\\Support\\Facades\\Hash', 'Http' => 'Illuminate\\Support\\Facades\\Http', 'Lang' => 'Illuminate\\Support\\Facades\\Lang', 'Log' => 'Illuminate\\Support\\Facades\\Log', 'Mail' => 'Illuminate\\Support\\Facades\\Mail', 'Notification' => 'Illuminate\\Support\\Facades\\Notification', 'Password' => 'Illuminate\\Support\\Facades\\Password', 'Queue' => 'Illuminate\\Support\\Facades\\Queue', 'RateLimiter' => 'Illuminate\\Support\\Facades\\RateLimiter', 'Redirect' => 'Illuminate\\Support\\Facades\\Redirect', 'Redis' => 'Illuminate\\Support\\Facades\\Redis', 'Request' => 'Illuminate\\Http\\Request', 'Response' => 'Illuminate\\Support\\Facades\\Response', 'Route' => 'Illuminate\\Support\\Facades\\Route', 'Schema' => 'Illuminate\\Support\\Facades\\Schema', 'Session' => 'Illuminate\\Support\\Facades\\Session', 'Storage' => 'Illuminate\\Support\\Facades\\Storage', 'URL' => 'Illuminate\\Support\\Facades\\URL', 'Validator' => 'Illuminate\\Support\\Facades\\Validator', 'View' => 'Illuminate\\Support\\Facades\\View']);
};

View File

@ -1,15 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
# see: https://laravel.com/docs/5.0/upgrade
return static function (RectorConfig $rectorConfig) : void {
# https://stackoverflow.com/a/24949656/1348344
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, ['Illuminate\\Cache\\CacheManager' => 'Illuminate\\Contracts\\Cache\\Repository', 'Illuminate\\Database\\Eloquent\\SoftDeletingTrait' => 'Illuminate\\Database\\Eloquent\\SoftDeletes']);
$rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [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

@ -1,11 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\Name\RenameClassRector;
# see: https://laravel.com/docs/5.1/upgrade
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, ['Illuminate\\Validation\\Validator' => 'Illuminate\\Contracts\\Validation\\Validator']);
};

View File

@ -1,14 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Transform\Rector\String_\StringToClassConstantRector;
use Rector\Transform\ValueObject\StringToClassConstant;
# see: https://laravel.com/docs/5.2/upgrade
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, ['Illuminate\\Auth\\Access\\UnauthorizedException' => 'Illuminate\\Auth\\Access\\AuthorizationException', 'Illuminate\\Http\\Exception\\HttpResponseException' => 'Illuminate\\Foundation\\Validation\\ValidationException', 'Illuminate\\Foundation\\Composer' => 'Illuminate\\Support\\Composer']);
$rectorConfig->ruleWithConfiguration(StringToClassConstantRector::class, [new StringToClassConstant('artisan.start', 'Illuminate\\Console\\Events\\ArtisanStarting', 'class'), new StringToClassConstant('auth.attempting', 'Illuminate\\Auth\\Events\\Attempting', 'class'), new StringToClassConstant('auth.login', 'Illuminate\\Auth\\Events\\Login', 'class'), new StringToClassConstant('auth.logout', 'Illuminate\\Auth\\Events\\Logout', 'class'), new StringToClassConstant('cache.missed', 'Illuminate\\Cache\\Events\\CacheMissed', 'class'), new StringToClassConstant('cache.hit', 'Illuminate\\Cache\\Events\\CacheHit', 'class'), new StringToClassConstant('cache.write', 'Illuminate\\Cache\\Events\\KeyWritten', 'class'), new StringToClassConstant('cache.delete', 'Illuminate\\Cache\\Events\\KeyForgotten', 'class'), new StringToClassConstant('illuminate.query', 'Illuminate\\Database\\Events\\QueryExecuted', 'class'), new StringToClassConstant('illuminate.queue.before', 'Illuminate\\Queue\\Events\\JobProcessing', 'class'), new StringToClassConstant('illuminate.queue.after', 'Illuminate\\Queue\\Events\\JobProcessed', 'class'), new StringToClassConstant('illuminate.queue.failed', 'Illuminate\\Queue\\Events\\JobFailed', 'class'), new StringToClassConstant('illuminate.queue.stopping', 'Illuminate\\Queue\\Events\\WorkerStopping', 'class'), new StringToClassConstant('mailer.sending', 'Illuminate\\Mail\\Events\\MessageSending', 'class'), new StringToClassConstant('router.matched', 'Illuminate\\Routing\\Events\\RouteMatched', 'class')]);
};

View File

@ -1,13 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Removing\Rector\Class_\RemoveTraitUseRector;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->ruleWithConfiguration(RemoveTraitUseRector::class, [
# see https://laravel.com/docs/5.3/upgrade
'Illuminate\\Foundation\\Auth\\Access\\AuthorizesResources',
]);
};

View File

@ -1,38 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Transform\Rector\String_\StringToClassConstantRector;
use Rector\Transform\ValueObject\StringToClassConstant;
# see: https://laravel.com/docs/5.4/upgrade
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->ruleWithConfiguration(StringToClassConstantRector::class, [new StringToClassConstant('kernel.handled', 'Illuminate\\Foundation\\Http\\Events\\RequestHandled', 'class'), new StringToClassConstant('locale.changed', 'Illuminate\\Foundation\\Events\\LocaleUpdated', 'class'), new StringToClassConstant('illuminate.log', 'Illuminate\\Log\\Events\\MessageLogged', 'class')]);
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, ['Illuminate\\Console\\AppNamespaceDetectorTrait' => 'Illuminate\\Console\\DetectsApplicationNamespace', 'Illuminate\\Http\\Exception\\HttpResponseException' => 'Illuminate\\Http\\Exceptions\\HttpResponseException', 'Illuminate\\Http\\Exception\\PostTooLargeException' => 'Illuminate\\Http\\Exceptions\\PostTooLargeException', 'Illuminate\\Foundation\\Http\\Middleware\\VerifyPostSize' => 'Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize', 'Symfony\\Component\\HttpFoundation\\Session\\SessionInterface' => 'Illuminate\\Contracts\\Session\\Session']);
$rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [
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'),
# https://github.com/laravel/framework/commit/f23ac640fa403ca8d4131c36367b53e123b6b852
new MethodCallRename('Illuminate\\Foundation\\Testing\\Concerns\\InteractsWithDatabase', 'seeInDatabase', 'assertDatabaseHas'),
new MethodCallRename('Illuminate\\Foundation\\Testing\\Concerns\\InteractsWithDatabase', 'missingFromDatabase', 'assertDatabaseMissing'),
new MethodCallRename('Illuminate\\Foundation\\Testing\\Concerns\\InteractsWithDatabase', 'dontSeeInDatabase', 'assertDatabaseMissing'),
new MethodCallRename('Illuminate\\Foundation\\Testing\\Concerns\\InteractsWithDatabase', 'notSeeInDatabase', 'assertDatabaseMissing'),
]);
};

View File

@ -1,17 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\Rector\PropertyFetch\RenamePropertyRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\RenameProperty;
# see: https://laravel.com/docs/5.5/upgrade
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [new MethodCallRename('Illuminate\\Console\\Command', 'fire', 'handle')]);
$rectorConfig->ruleWithConfiguration(RenamePropertyRector::class, [new RenameProperty('Illuminate\\Database\\Eloquent\\Concerns\\HasEvents', 'events', 'dispatchesEvents'), new RenameProperty('Illuminate\\Database\\Eloquent\\Relations\\Pivot', 'parent', 'pivotParent')]);
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, ['Illuminate\\Translation\\LoaderInterface' => 'Illuminate\\Contracts\\Translation\\Loader']);
};

View File

@ -1,16 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Core\ValueObject\Visibility;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Visibility\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\Visibility\ValueObject\ChangeMethodVisibility;
# see: https://laravel.com/docs/5.6/upgrade
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [new MethodCallRename('Illuminate\\Validation\\ValidatesWhenResolvedTrait', 'validate', 'validateResolved'), new MethodCallRename('Illuminate\\Contracts\\Validation\\ValidatesWhenResolved', 'validate', 'validateResolved')]);
$rectorConfig->ruleWithConfiguration(ChangeMethodVisibilityRector::class, [new ChangeMethodVisibility('Illuminate\\Routing\\Router', 'addRoute', Visibility::PUBLIC), new ChangeMethodVisibility('Illuminate\\Contracts\\Auth\\Access\\Gate', 'raw', Visibility::PUBLIC), new ChangeMethodVisibility('Illuminate\\Database\\Grammar', 'getDateFormat', Visibility::PUBLIC)]);
};

View File

@ -1,30 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use PHPStan\Type\ObjectType;
use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;
use Rector\Arguments\ValueObject\ArgumentAdder;
use Rector\Config\RectorConfig;
use Rector\Core\ValueObject\Visibility;
use Rector\Laravel\Rector\Class_\AddMockConsoleOutputFalseToConsoleTestsRector;
use Rector\Laravel\Rector\ClassMethod\AddParentBootToModelClassMethodRector;
use Rector\Laravel\Rector\MethodCall\ChangeQueryWhereDateValueWithCarbonRector;
use Rector\Laravel\Rector\New_\AddGuardToLoginEventRector;
use Rector\Laravel\Rector\StaticCall\Redirect301ToPermanentRedirectRector;
use Rector\Removing\Rector\ClassMethod\ArgumentRemoverRector;
use Rector\Removing\ValueObject\ArgumentRemover;
use Rector\Visibility\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\Visibility\ValueObject\ChangeMethodVisibility;
# see: https://laravel.com/docs/5.7/upgrade
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->ruleWithConfiguration(ChangeMethodVisibilityRector::class, [new ChangeMethodVisibility('Illuminate\\Routing\\Router', 'addRoute', Visibility::PUBLIC), new ChangeMethodVisibility('Illuminate\\Contracts\\Auth\\Access\\Gate', 'raw', Visibility::PUBLIC)]);
$rectorConfig->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdder('Illuminate\\Auth\\Middleware\\Authenticate', 'authenticate', 0, 'request'), new ArgumentAdder('Illuminate\\Foundation\\Auth\\ResetsPasswords', 'sendResetResponse', 0, 'request', null, new ObjectType('Illuminate\\Http\\Illuminate\\Http')), new ArgumentAdder('Illuminate\\Foundation\\Auth\\SendsPasswordResetEmails', 'sendResetLinkResponse', 0, 'request', null, new ObjectType('Illuminate\\Http\\Illuminate\\Http')), new ArgumentAdder('Illuminate\\Database\\ConnectionInterface', 'select', 2, 'useReadPdo', \true), new ArgumentAdder('Illuminate\\Database\\ConnectionInterface', 'selectOne', 2, 'useReadPdo', \true)]);
$rectorConfig->rule(Redirect301ToPermanentRedirectRector::class);
$rectorConfig->ruleWithConfiguration(ArgumentRemoverRector::class, [new ArgumentRemover('Illuminate\\Foundation\\Application', 'register', 1, ['name' => 'options'])]);
$rectorConfig->rule(AddParentBootToModelClassMethodRector::class);
$rectorConfig->rule(ChangeQueryWhereDateValueWithCarbonRector::class);
$rectorConfig->rule(AddMockConsoleOutputFalseToConsoleTestsRector::class);
$rectorConfig->rule(AddGuardToLoginEventRector::class);
};

View File

@ -1,23 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use PHPStan\Type\BooleanType;
use Rector\Config\RectorConfig;
use Rector\Laravel\Rector\Class_\PropertyDeferToDeferrableProviderToRector;
use Rector\Laravel\Rector\StaticCall\MinutesToSecondsInCacheRector;
use Rector\Renaming\Rector\PropertyFetch\RenamePropertyRector;
use Rector\Renaming\ValueObject\RenameProperty;
use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddReturnTypeDeclaration;
# https://laravel-news.com/laravel-5-8-deprecates-string-and-array-helpers
# https://github.com/laravel/framework/pull/26898
# see: https://laravel.com/docs/5.8/upgrade
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->import(__DIR__ . '/laravel-array-str-functions-to-static-call.php');
$rectorConfig->rule(MinutesToSecondsInCacheRector::class);
$rectorConfig->ruleWithConfiguration(AddReturnTypeDeclarationRector::class, [new AddReturnTypeDeclaration('Illuminate\\Contracts\\Cache\\Repository', 'put', new BooleanType()), new AddReturnTypeDeclaration('Illuminate\\Contracts\\Cache\\Repository', 'forever', new BooleanType()), new AddReturnTypeDeclaration('Illuminate\\Contracts\\Cache\\Store', 'put', new BooleanType()), new AddReturnTypeDeclaration('Illuminate\\Contracts\\Cache\\Store', 'putMany', new BooleanType()), new AddReturnTypeDeclaration('Illuminate\\Contracts\\Cache\\Store', 'forever', new BooleanType())]);
$rectorConfig->ruleWithConfiguration(RenamePropertyRector::class, [new RenameProperty('Illuminate\\Routing\\UrlGenerator', 'cachedSchema', 'cachedScheme')]);
$rectorConfig->rule(PropertyDeferToDeferrableProviderToRector::class);
};

View File

@ -1,52 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;
use Rector\Arguments\ValueObject\ArgumentAdder;
use Rector\Config\RectorConfig;
use Rector\Core\ValueObject\Visibility;
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\RenameStaticMethod;
use Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector;
use Rector\Visibility\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\Visibility\ValueObject\ChangeMethodVisibility;
# see https://laravel.com/docs/6.x/upgrade
# https://github.com/laravel/docs/pull/5531/files
return static function (RectorConfig $rectorConfig) : void {
# https://github.com/laravel/framework/commit/67a38ba0fa2acfbd1f4af4bf7d462bb4419cc091
$rectorConfig->rule(ParamTypeDeclarationRector::class);
$rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [new MethodCallRename(
'Illuminate\\Auth\\Access\\Gate',
# https://github.com/laravel/framework/commit/69de466ddc25966a0f6551f48acab1afa7bb9424
'access',
'inspect'
), new MethodCallRename(
'Illuminate\\Support\\Facades\\Lang',
# https://github.com/laravel/framework/commit/efbe23c4116f86846ad6edc0d95cd56f4175a446
'trans',
'get'
), new MethodCallRename('Illuminate\\Support\\Facades\\Lang', 'transChoice', 'choice'), new MethodCallRename(
'Illuminate\\Translation\\Translator',
# https://github.com/laravel/framework/commit/697b898a1c89881c91af83ecc4493fa681e2aa38
'getFromJson',
'get'
)]);
$rectorConfig->ruleWithConfiguration(RenameStaticMethodRector::class, [
// https://github.com/laravel/framework/commit/55785d3514a8149d4858acef40c56a31b6b2ccd1
new RenameStaticMethod('Illuminate\\Support\\Facades\\Input', 'get', 'Illuminate\\Support\\Facades\\Request', 'input'),
]);
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, ['Illuminate\\Support\\Facades\\Input' => 'Illuminate\\Support\\Facades\\Request']);
$rectorConfig->ruleWithConfiguration(ChangeMethodVisibilityRector::class, [new ChangeMethodVisibility('Illuminate\\Foundation\\Http\\FormRequest', 'validationData', Visibility::PUBLIC)]);
$rectorConfig->ruleWithConfiguration(ArgumentAdderRector::class, [
// https://github.com/laravel/framework/commit/6c1e014943a508afb2c10869c3175f7783a004e1
new ArgumentAdder('Illuminate\\Database\\Capsule\\Manager', 'table', 1, 'as', null),
new ArgumentAdder('Illuminate\\Database\\Connection', 'table', 1, 'as', null),
new ArgumentAdder('Illuminate\\Database\\ConnectionInterface', 'table', 1, 'as', null),
new ArgumentAdder('Illuminate\\Database\\Query\\Builder', 'from', 1, 'as', null),
]);
};

View File

@ -1,36 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use PHPStan\Type\ObjectType;
use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;
use Rector\Arguments\ValueObject\ArgumentAdder;
use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddParamTypeDeclaration;
# see https://laravel.com/docs/7.x/upgrade
return static function (RectorConfig $rectorConfig) : void {
# https://github.com/laravel/framework/pull/30610/files
$rectorConfig->ruleWithConfiguration(AddParamTypeDeclarationRector::class, [new AddParamTypeDeclaration('Illuminate\\Contracts\\Debug\\ExceptionHandler', 'report', 0, new ObjectType('Throwable')), new AddParamTypeDeclaration('Illuminate\\Contracts\\Debug\\ExceptionHandler', 'shouldReport', 0, new ObjectType('Throwable')), new AddParamTypeDeclaration('Illuminate\\Contracts\\Debug\\ExceptionHandler', 'render', 1, new ObjectType('Throwable')), new AddParamTypeDeclaration('Illuminate\\Contracts\\Debug\\ExceptionHandler', 'renderForConsole', 1, new ObjectType('Throwable'))]);
# https://github.com/laravel/framework/pull/30471/files
$rectorConfig->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdder('Illuminate\\Contracts\\Routing\\UrlRoutable', 'resolveRouteBinding', 1, 'field', null)]);
$rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [
# https://github.com/laravel/framework/commit/aece7d78f3d28b2cdb63185dcc4a9b6092841310
new MethodCallRename('Illuminate\\Support\\Facades\\Blade', 'component', 'aliasComponent'),
# https://github.com/laravel/framework/pull/31463/files
new MethodCallRename('Illuminate\\Database\\Eloquent\\Concerns\\HidesAttributes', 'addHidden', 'makeHidden'),
# https://github.com/laravel/framework/pull/30348/files
new MethodCallRename('Illuminate\\Database\\Eloquent\\Concerns\\HidesAttributes', 'addVisible', 'makeVisible'),
]);
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, [
# https://github.com/laravel/framework/pull/30619/files
'Illuminate\\Http\\Resources\\Json\\Resource' => 'Illuminate\\Http\\Resources\\Json\\JsonResource',
# https://github.com/laravel/framework/pull/31050/files
'Illuminate\\Foundation\\Testing\\TestResponse' => 'Illuminate\\Testing\\TestResponse',
'Illuminate\\Foundation\\Testing\\Assert' => 'Illuminate\\Testing\\Assert',
]);
};

View File

@ -1,54 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use PHPStan\Type\ArrayType;
use PHPStan\Type\MixedType;
use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;
use Rector\Arguments\ValueObject\ArgumentAdder;
use Rector\Config\RectorConfig;
use Rector\Laravel\Rector\ClassMethod\AddArgumentDefaultValueRector;
use Rector\Laravel\Rector\ClassMethod\AddParentRegisterToEventServiceProviderRector;
use Rector\Laravel\ValueObject\AddArgumentDefaultValue;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\PropertyFetch\RenamePropertyRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\RenameProperty;
# see https://laravel.com/docs/8.x/upgrade
return static function (RectorConfig $rectorConfig) : void {
# https://github.com/laravel/framework/commit/4d228d6e9dbcbd4d97c45665980d8b8c685b27e6
$rectorConfig->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdder(
'Illuminate\\Contracts\\Database\\Eloquent\\Castable',
'castUsing',
0,
'arguments',
[],
// TODO: Add argument without default value
new ArrayType(new MixedType(), new MixedType())
)]);
# https://github.com/laravel/framework/commit/46084d946cdcd1ae1f32fc87a4f1cc9e3a5bccf6
$rectorConfig->ruleWithConfiguration(AddArgumentDefaultValueRector::class, [new AddArgumentDefaultValue('Illuminate\\Contracts\\Events\\Dispatcher', 'listen', 1, null)]);
# https://github.com/laravel/framework/commit/f1289515b27e93248c09f04e3011bb7ce21b2737
$rectorConfig->rule(AddParentRegisterToEventServiceProviderRector::class);
$rectorConfig->ruleWithConfiguration(RenamePropertyRector::class, [
# https://github.com/laravel/framework/pull/32092/files
new RenameProperty('Illuminate\\Support\\Manager', 'app', 'container'),
# https://github.com/laravel/framework/commit/4656c2cf012ac62739ab5ea2bce006e1e9fe8f09
new RenameProperty('Illuminate\\Contracts\\Queue\\ShouldQueue', 'retryAfter', 'backoff'),
# https://github.com/laravel/framework/commit/12c35e57c0a6da96f36ad77f88f083e96f927205
new RenameProperty('Illuminate\\Contracts\\Queue\\ShouldQueue', 'timeoutAt', 'retryUntil'),
]);
$rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [
# https://github.com/laravel/framework/pull/32092/files
new MethodCallRename('Illuminate\\Mail\\PendingMail', 'sendNow', 'send'),
# https://github.com/laravel/framework/commit/4656c2cf012ac62739ab5ea2bce006e1e9fe8f09
new MethodCallRename('Illuminate\\Contracts\\Queue\\ShouldQueue', 'retryAfter', 'backoff'),
# https://github.com/laravel/framework/commit/12c35e57c0a6da96f36ad77f88f083e96f927205
new MethodCallRename('Illuminate\\Contracts\\Queue\\ShouldQueue', 'timeoutAt', 'retryUntil'),
# https://github.com/laravel/framework/commit/f9374fa5fb0450721fb2f90e96adef9d409b112c
new MethodCallRename('Illuminate\\Testing\\TestResponse', 'decodeResponseJson', 'json'),
# https://github.com/laravel/framework/commit/fd662d4699776a94e7ead2a42e82c340363fc5a6
new MethodCallRename('Illuminate\\Testing\\TestResponse', 'assertExactJson', 'assertSimilarJson'),
]);
};

View File

@ -1,49 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;
use Rector\Arguments\ValueObject\ArgumentAdder;
use Rector\Config\RectorConfig;
use Rector\Core\ValueObject\Visibility;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Visibility\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\Visibility\ValueObject\ChangeMethodVisibility;
# see https://laravel.com/docs/9.x/upgrade
return static function (RectorConfig $rectorConfig) : void {
// https://github.com/laravel/framework/commit/8f9ddea4481717943ed4ecff96d86b703c81a87d
$rectorConfig->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdder('Illuminate\\Contracts\\Foundation\\Application', 'storagePath', 0, 'path', '')]);
// https://github.com/laravel/framework/commit/e6c8aaea886d35cc55bd3469f1a95ad56d53e474
$rectorConfig->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdder('Illuminate\\Foundation\\Application', 'langPath', 0, 'path', '')]);
// https://github.com/laravel/framework/commit/e095ac0e928b5620f33c9b60816fde5ece867d32
$rectorConfig->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdder('Illuminate\\Database\\Eloquent\\Model', 'touch', 0, 'attribute')]);
// https://github.com/laravel/framework/commit/6daecf43dd931dc503e410645ff4a7d611e3371f
$rectorConfig->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdder('Illuminate\\Queue\\Failed\\FailedJobProviderInterface', 'flush', 0, 'hours')]);
// https://github.com/laravel/framework/commit/8b40e8b7cba2fbf8337dfc05e3c6a62ae457e889
$rectorConfig->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdder('Illuminate\\Foundation\\Http\\FormRequest', 'validated', 0, 'key'), new ArgumentAdder('Illuminate\\Foundation\\Http\\FormRequest', 'validated', 1, 'default')]);
// https://github.com/laravel/framework/commit/84c78b9f5f3dad58f92161069e6482f7267ffdb6
$rectorConfig->ruleWithConfiguration(ChangeMethodVisibilityRector::class, [new ChangeMethodVisibility('Illuminate\\Foundation\\Exceptions\\Handler', 'ignore', Visibility::PUBLIC)]);
$rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [
// https://github.com/laravel/framework/commit/9b4f011fb95c70444812f61d46c8e21fb5b66dd9
new MethodCallRename('Illuminate\\Support\\Enumerable', 'reduceWithKeys', 'reduce'),
// https://github.com/laravel/framework/commit/02365bb5ebafeeaef28b5eb659466c56b2634c65
new MethodCallRename('Illuminate\\Support\\Enumerable', 'reduceMany', 'reduceSpread'),
// https://github.com/laravel/framework/commit/097107ab50ce754c709313fc75a6f1f4a9389bfc
new MethodCallRename('Illuminate\\Mail\\Message', 'getSwiftMessage', 'getSymfonyMessage'),
// https://github.com/laravel/framework/commit/097107ab50ce754c709313fc75a6f1f4a9389bfc
new MethodCallRename('Illuminate\\Mail\\Mailable', 'withSwiftMessage', 'withSymfonyMessage'),
// https://github.com/laravel/framework/commit/097107ab50ce754c709313fc75a6f1f4a9389bfc
new MethodCallRename('Illuminate\\Notifications\\Messages\\MailMessage', 'withSwiftMessage', 'withSymfonyMessage'),
// https://github.com/laravel/framework/commit/097107ab50ce754c709313fc75a6f1f4a9389bfc
new MethodCallRename('Illuminate\\Mail\\Mailer', 'getSwiftMailer', 'getSymfonyTransport'),
// https://github.com/laravel/framework/commit/097107ab50ce754c709313fc75a6f1f4a9389bfc
new MethodCallRename('Illuminate\\Mail\\Mailer', 'setSwiftMailer', 'setSymfonyTransport'),
// https://github.com/laravel/framework/commit/097107ab50ce754c709313fc75a6f1f4a9389bfc
new MethodCallRename('Illuminate\\Mail\\MailManager', 'createTransport', 'createSymfonyTransport'),
// https://github.com/laravel/framework/commit/59ff96c269f691bfd197090675c0235700f750b2
// https://github.com/laravel/framework/commit/9894c2c64dc70f7dfda2ac46dfdaa8769ce4596a
new MethodCallRename('Illuminate\\Testing\\TestResponse', 'assertDeleted', 'assertModelMissing'),
]);
};

View File

@ -1,10 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Laravel\Set\LaravelSetList;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->sets([LaravelSetList::LARAVEL_50, LaravelSetList::LARAVEL_51]);
};

View File

@ -1,11 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Laravel\Set\LaravelLevelSetList;
use Rector\Laravel\Set\LaravelSetList;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->sets([LaravelSetList::LARAVEL_52, LaravelLevelSetList::UP_TO_LARAVEL_51]);
};

View File

@ -1,11 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Laravel\Set\LaravelLevelSetList;
use Rector\Laravel\Set\LaravelSetList;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->sets([LaravelSetList::LARAVEL_53, LaravelLevelSetList::UP_TO_LARAVEL_52]);
};

View File

@ -1,11 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Laravel\Set\LaravelLevelSetList;
use Rector\Laravel\Set\LaravelSetList;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->sets([LaravelSetList::LARAVEL_54, LaravelLevelSetList::UP_TO_LARAVEL_53]);
};

View File

@ -1,11 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Laravel\Set\LaravelLevelSetList;
use Rector\Laravel\Set\LaravelSetList;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->sets([LaravelSetList::LARAVEL_55, LaravelLevelSetList::UP_TO_LARAVEL_54]);
};

View File

@ -1,11 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Laravel\Set\LaravelLevelSetList;
use Rector\Laravel\Set\LaravelSetList;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->sets([LaravelSetList::LARAVEL_56, LaravelLevelSetList::UP_TO_LARAVEL_55]);
};

View File

@ -1,11 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Laravel\Set\LaravelLevelSetList;
use Rector\Laravel\Set\LaravelSetList;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->sets([LaravelSetList::LARAVEL_57, LaravelLevelSetList::UP_TO_LARAVEL_56]);
};

View File

@ -1,11 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Laravel\Set\LaravelLevelSetList;
use Rector\Laravel\Set\LaravelSetList;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->sets([LaravelSetList::LARAVEL_58, LaravelLevelSetList::UP_TO_LARAVEL_57]);
};

View File

@ -1,11 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Laravel\Set\LaravelLevelSetList;
use Rector\Laravel\Set\LaravelSetList;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->sets([LaravelSetList::LARAVEL_60, LaravelLevelSetList::UP_TO_LARAVEL_58]);
};

View File

@ -1,11 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Laravel\Set\LaravelLevelSetList;
use Rector\Laravel\Set\LaravelSetList;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->sets([LaravelSetList::LARAVEL_70, LaravelLevelSetList::UP_TO_LARAVEL_60]);
};

View File

@ -1,11 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Laravel\Set\LaravelLevelSetList;
use Rector\Laravel\Set\LaravelSetList;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->sets([LaravelSetList::LARAVEL_80, LaravelLevelSetList::UP_TO_LARAVEL_70]);
};

View File

@ -1,11 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Laravel\Set\LaravelLevelSetList;
use Rector\Laravel\Set\LaravelSetList;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->sets([LaravelSetList::LARAVEL_90, LaravelLevelSetList::UP_TO_LARAVEL_80]);
};

View File

@ -1,566 +0,0 @@
# 25 Rules Overview
## AddArgumentDefaultValueRector
Adds default value for arguments in defined methods.
:wrench: **configure it!**
- class: [`Rector\Laravel\Rector\ClassMethod\AddArgumentDefaultValueRector`](../src/Rector/ClassMethod/AddArgumentDefaultValueRector.php)
```php
use Rector\Config\RectorConfig;
use Rector\Laravel\Rector\ClassMethod\AddArgumentDefaultValueRector;
use Rector\Laravel\ValueObject\AddArgumentDefaultValue;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(AddArgumentDefaultValueRector::class, [
AddArgumentDefaultValueRector::ADDED_ARGUMENTS => [
new AddArgumentDefaultValue('SomeClass', 'someMethod', 0, false),
],
]);
};
```
```diff
class SomeClass
{
- public function someMethod($value)
+ public function someMethod($value = false)
{
}
}
```
<br>
## AddGenericReturnTypeToRelationsRector
Add generic return type to relations in child of `Illuminate\Database\Eloquent\Model`
- class: [`Rector\Laravel\Rector\ClassMethod\AddGenericReturnTypeToRelationsRector`](../src/Rector/ClassMethod/AddGenericReturnTypeToRelationsRector.php)
```diff
use App\Account;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class User extends Model
{
+ /** @return HasMany<Account> */
public function accounts(): HasMany
{
return $this->hasMany(Account::class);
}
}
```
<br>
## AddGuardToLoginEventRector
Add new `$guard` argument to Illuminate\Auth\Events\Login
- class: [`Rector\Laravel\Rector\New_\AddGuardToLoginEventRector`](../src/Rector/New_/AddGuardToLoginEventRector.php)
```diff
use Illuminate\Auth\Events\Login;
final class SomeClass
{
public function run(): void
{
- $loginEvent = new Login('user', false);
+ $guard = config('auth.defaults.guard');
+ $loginEvent = new Login($guard, 'user', false);
}
}
```
<br>
## AddMockConsoleOutputFalseToConsoleTestsRector
Add "$this->mockConsoleOutput = false"; to console tests that work with output content
- class: [`Rector\Laravel\Rector\Class_\AddMockConsoleOutputFalseToConsoleTestsRector`](../src/Rector/Class_/AddMockConsoleOutputFalseToConsoleTestsRector.php)
```diff
use Illuminate\Support\Facades\Artisan;
use Illuminate\Foundation\Testing\TestCase;
final class SomeTest extends TestCase
{
+ public function setUp(): void
+ {
+ parent::setUp();
+
+ $this->mockConsoleOutput = false;
+ }
+
public function test(): void
{
$this->assertEquals('content', \trim((new Artisan())::output()));
}
}
```
<br>
## AddParentBootToModelClassMethodRector
Add `parent::boot();` call to `boot()` class method in child of `Illuminate\Database\Eloquent\Model`
- class: [`Rector\Laravel\Rector\ClassMethod\AddParentBootToModelClassMethodRector`](../src/Rector/ClassMethod/AddParentBootToModelClassMethodRector.php)
```diff
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
public function boot()
{
+ parent::boot();
}
}
```
<br>
## AddParentRegisterToEventServiceProviderRector
Add `parent::register();` call to `register()` class method in child of `Illuminate\Foundation\Support\Providers\EventServiceProvider`
- class: [`Rector\Laravel\Rector\ClassMethod\AddParentRegisterToEventServiceProviderRector`](../src/Rector/ClassMethod/AddParentRegisterToEventServiceProviderRector.php)
```diff
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
public function register()
{
+ parent::register();
}
}
```
<br>
## AnonymousMigrationsRector
Convert migrations to anonymous classes.
- class: [`Rector\Laravel\Rector\Class_\AnonymousMigrationsRector`](../src/Rector/Class_/AnonymousMigrationsRector.php)
```diff
use Illuminate\Database\Migrations\Migration;
-class CreateUsersTable extends Migration
+return new class extends Migration
{
// ...
-}
+};
```
<br>
## CallOnAppArrayAccessToStandaloneAssignRector
Replace magical call on `$this->app["something"]` to standalone type assign variable
- class: [`Rector\Laravel\Rector\Assign\CallOnAppArrayAccessToStandaloneAssignRector`](../src/Rector/Assign/CallOnAppArrayAccessToStandaloneAssignRector.php)
```diff
class SomeClass
{
/**
* @var \Illuminate\Contracts\Foundation\Application
*/
private $app;
public function run()
{
- $validator = $this->app['validator']->make('...');
+ /** @var \Illuminate\Validation\Factory $validationFactory */
+ $validationFactory = $this->app['validator'];
+ $validator = $validationFactory->make('...');
}
}
```
<br>
## ChangeQueryWhereDateValueWithCarbonRector
Add `parent::boot();` call to `boot()` class method in child of `Illuminate\Database\Eloquent\Model`
- class: [`Rector\Laravel\Rector\MethodCall\ChangeQueryWhereDateValueWithCarbonRector`](../src/Rector/MethodCall/ChangeQueryWhereDateValueWithCarbonRector.php)
```diff
use Illuminate\Database\Query\Builder;
final class SomeClass
{
public function run(Builder $query)
{
- $query->whereDate('created_at', '<', Carbon::now());
+ $dateTime = Carbon::now();
+ $query->whereDate('created_at', '<=', $dateTime);
+ $query->whereTime('created_at', '<=', $dateTime);
}
}
```
<br>
## FactoryApplyingStatesRector
Call the state methods directly instead of specify the name of state.
- class: [`Rector\Laravel\Rector\MethodCall\FactoryApplyingStatesRector`](../src/Rector/MethodCall/FactoryApplyingStatesRector.php)
```diff
-$factory->state('delinquent');
-$factory->states('premium', 'delinquent');
+$factory->delinquent();
+$factory->premium()->delinquent();
```
<br>
## FactoryDefinitionRector
Upgrade legacy factories to support classes.
- class: [`Rector\Laravel\Rector\Namespace_\FactoryDefinitionRector`](../src/Rector/Namespace_/FactoryDefinitionRector.php)
```diff
use Faker\Generator as Faker;
-$factory->define(App\User::class, function (Faker $faker) {
- return [
- 'name' => $faker->name,
- 'email' => $faker->unique()->safeEmail,
- ];
-});
+class UserFactory extends \Illuminate\Database\Eloquent\Factories\Factory
+{
+ protected $model = App\User::class;
+ public function definition()
+ {
+ return [
+ 'name' => $this->faker->name,
+ 'email' => $this->faker->unique()->safeEmail,
+ ];
+ }
+}
```
<br>
## FactoryFuncCallToStaticCallRector
Use the static factory method instead of global factory function.
- class: [`Rector\Laravel\Rector\FuncCall\FactoryFuncCallToStaticCallRector`](../src/Rector/FuncCall/FactoryFuncCallToStaticCallRector.php)
```diff
-factory(User::class);
+User::factory();
```
<br>
## HelperFuncCallToFacadeClassRector
Change `app()` func calls to facade calls
- class: [`Rector\Laravel\Rector\FuncCall\HelperFuncCallToFacadeClassRector`](../src/Rector/FuncCall/HelperFuncCallToFacadeClassRector.php)
```diff
class SomeClass
{
public function run()
{
- return app('translator')->trans('value');
+ return \Illuminate\Support\Facades\App::get('translator')->trans('value');
}
}
```
<br>
## LumenRoutesStringActionToUsesArrayRector
Changes action in rule definitions from string to array notation.
- class: [`Rector\Laravel\Rector\MethodCall\LumenRoutesStringActionToUsesArrayRector`](../src/Rector/MethodCall/LumenRoutesStringActionToUsesArrayRector.php)
```diff
-$router->get('/user', 'UserController@get');
+$router->get('/user', ['uses => 'UserController@get']);
```
<br>
## LumenRoutesStringMiddlewareToArrayRector
Changes middlewares from rule definitions from string to array notation.
- class: [`Rector\Laravel\Rector\MethodCall\LumenRoutesStringMiddlewareToArrayRector`](../src/Rector/MethodCall/LumenRoutesStringMiddlewareToArrayRector.php)
```diff
-$router->get('/user', ['middleware => 'test']);
-$router->post('/user', ['middleware => 'test|authentication']);
+$router->get('/user', ['middleware => ['test']]);
+$router->post('/user', ['middleware => ['test', 'authentication']]);
```
<br>
## MinutesToSecondsInCacheRector
Change minutes argument to seconds in `Illuminate\Contracts\Cache\Store` and Illuminate\Support\Facades\Cache
- class: [`Rector\Laravel\Rector\StaticCall\MinutesToSecondsInCacheRector`](../src/Rector/StaticCall/MinutesToSecondsInCacheRector.php)
```diff
class SomeClass
{
public function run()
{
- Illuminate\Support\Facades\Cache::put('key', 'value', 60);
+ Illuminate\Support\Facades\Cache::put('key', 'value', 60 * 60);
}
}
```
<br>
## OptionalToNullsafeOperatorRector
Convert simple calls to optional helper to use the nullsafe operator
:wrench: **configure it!**
- class: [`Rector\Laravel\Rector\PropertyFetch\OptionalToNullsafeOperatorRector`](../src/Rector/PropertyFetch/OptionalToNullsafeOperatorRector.php)
```php
use Rector\Config\RectorConfig;
use Rector\Laravel\Rector\PropertyFetch\OptionalToNullsafeOperatorRector;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(OptionalToNullsafeOperatorRector::class, [
OptionalToNullsafeOperatorRector::EXCLUDE_METHODS => ['present'],
]);
};
```
```diff
-optional($user)->getKey();
-optional($user)->id;
+$user?->getKey();
+$user?->id;
// macro methods
optional($user)->present()->getKey();
```
<br>
## PropertyDeferToDeferrableProviderToRector
Change deprecated `$defer` = true; to `Illuminate\Contracts\Support\DeferrableProvider` interface
- class: [`Rector\Laravel\Rector\Class_\PropertyDeferToDeferrableProviderToRector`](../src/Rector/Class_/PropertyDeferToDeferrableProviderToRector.php)
```diff
use Illuminate\Support\ServiceProvider;
+use Illuminate\Contracts\Support\DeferrableProvider;
-final class SomeServiceProvider extends ServiceProvider
+final class SomeServiceProvider extends ServiceProvider implements DeferrableProvider
{
- /**
- * @var bool
- */
- protected $defer = true;
}
```
<br>
## Redirect301ToPermanentRedirectRector
Change "redirect" call with 301 to "permanentRedirect"
- class: [`Rector\Laravel\Rector\StaticCall\Redirect301ToPermanentRedirectRector`](../src/Rector/StaticCall/Redirect301ToPermanentRedirectRector.php)
```diff
class SomeClass
{
public function run()
{
- Illuminate\Routing\Route::redirect('/foo', '/bar', 301);
+ Illuminate\Routing\Route::permanentRedirect('/foo', '/bar');
}
}
```
<br>
## RedirectBackToBackHelperRector
Replace `redirect()->back()` and `Redirect::back()` with `back()`
- class: [`Rector\Laravel\Rector\MethodCall\RedirectBackToBackHelperRector`](../src/Rector/MethodCall/RedirectBackToBackHelperRector.php)
```diff
use Illuminate\Support\Facades\Redirect;
class MyController
{
public function store()
{
- return redirect()->back()->with('error', 'Incorrect Details.')
+ return back()->with('error', 'Incorrect Details.')
}
public function update()
{
- return Redirect::back()->with('error', 'Incorrect Details.')
+ return back()->with('error', 'Incorrect Details.')
}
}
```
<br>
## RedirectRouteToToRouteHelperRector
Replace `redirect()->route("home")` and `Redirect::route("home")` with `to_route("home")`
- class: [`Rector\Laravel\Rector\MethodCall\RedirectRouteToToRouteHelperRector`](../src/Rector/MethodCall/RedirectRouteToToRouteHelperRector.php)
```diff
use Illuminate\Support\Facades\Redirect;
class MyController
{
public function store()
{
- return redirect()->route('home')->with('error', 'Incorrect Details.')
+ return to_route('home')->with('error', 'Incorrect Details.')
}
public function update()
{
- return Redirect::route('home')->with('error', 'Incorrect Details.')
+ return to_route('home')->with('error', 'Incorrect Details.')
}
}
```
<br>
## RemoveDumpDataDeadCodeRector
It will removes the dump data just like dd or dump functions from the code.`
- class: [`Rector\Laravel\Rector\FuncCall\RemoveDumpDataDeadCodeRector`](../src/Rector/FuncCall/RemoveDumpDataDeadCodeRector.php)
```diff
class MyController
{
public function store()
{
- dd('test');
return true;
}
public function update()
{
- dump('test');
return true;
}
}
```
<br>
## RequestStaticValidateToInjectRector
Change static `validate()` method to `$request->validate()`
- class: [`Rector\Laravel\Rector\StaticCall\RequestStaticValidateToInjectRector`](../src/Rector/StaticCall/RequestStaticValidateToInjectRector.php)
```diff
use Illuminate\Http\Request;
class SomeClass
{
- public function store()
+ public function store(\Illuminate\Http\Request $request)
{
- $validatedData = Request::validate(['some_attribute' => 'required']);
+ $validatedData = $request->validate(['some_attribute' => 'required']);
}
}
```
<br>
## RouteActionCallableRector
Use PHP callable syntax instead of string syntax for controller route declarations.
:wrench: **configure it!**
- class: [`Rector\Laravel\Rector\StaticCall\RouteActionCallableRector`](../src/Rector/StaticCall/RouteActionCallableRector.php)
```php
use Rector\Config\RectorConfig;
use Rector\Laravel\Rector\StaticCall\RouteActionCallableRector;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(RouteActionCallableRector::class, [
RouteActionCallableRector::NAMESPACE => 'App\Http\Controllers',
]);
};
```
```diff
-Route::get('/users', 'UserController@index');
+Route::get('/users', [\App\Http\Controllers\UserController::class, 'index']);
```
<br>
## UnifyModelDatesWithCastsRector
Unify Model `$dates` property with `$casts`
- class: [`Rector\Laravel\Rector\Class_\UnifyModelDatesWithCastsRector`](../src/Rector/Class_/UnifyModelDatesWithCastsRector.php)
```diff
use Illuminate\Database\Eloquent\Model;
class Person extends Model
{
protected $casts = [
- 'age' => 'integer',
+ 'age' => 'integer', 'birthday' => 'datetime',
];
-
- protected $dates = ['birthday'];
}
```
<br>

View File

@ -1,15 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use RectorPrefix202210\Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use RectorPrefix202210\Symplify\MonorepoBuilder\Release\ReleaseWorker\PushTagReleaseWorker;
use RectorPrefix202210\Symplify\MonorepoBuilder\Release\ReleaseWorker\TagVersionReleaseWorker;
return static function (ContainerConfigurator $containerConfigurator) : void {
$services = $containerConfigurator->services();
$services->defaults()->autowire();
// @see https://github.com/symplify/monorepo-builder#6-release-flow
$services->set(TagVersionReleaseWorker::class);
$services->set(PushTagReleaseWorker::class);
};

View File

@ -1,22 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202210;
use Rector\Config\RectorConfig;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->importNames();
$rectorConfig->paths([__DIR__ . '/src', __DIR__ . '/tests']);
$rectorConfig->skip([
// for tests
'*/Source/*',
'*/Fixture/*',
// skip for handle scoped, like in the rector-src as well
// @see https://github.com/rectorphp/rector-src/blob/7f73cf017214257c170d34db3af7283eaeeab657/rector.php#L71
StringClassNameToClassConstantRector::class,
]);
$rectorConfig->sets([LevelSetList::UP_TO_PHP_81, SetList::DEAD_CODE, SetList::CODE_QUALITY, SetList::NAMING]);
};

View File

@ -1,47 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\NodeAnalyzer;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Identifier;
use PHPStan\Type\ObjectType;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\NodeTypeResolver;
final class LumenRouteRegisteringMethodAnalyzer
{
/**
* @readonly
* @var \Rector\NodeTypeResolver\NodeTypeResolver
*/
private $nodeTypeResolver;
/**
* @readonly
* @var \Rector\NodeNameResolver\NodeNameResolver
*/
private $nodeNameResolver;
public function __construct(NodeTypeResolver $nodeTypeResolver, NodeNameResolver $nodeNameResolver)
{
$this->nodeTypeResolver = $nodeTypeResolver;
$this->nodeNameResolver = $nodeNameResolver;
}
public function isLumenRoutingClass(MethodCall $methodCall) : bool
{
return $this->nodeTypeResolver->isObjectType($methodCall->var, new ObjectType('Laravel\\Lumen\\Routing\\Router'));
}
/**
* @param \PhpParser\Node\Identifier|\PhpParser\Node\Expr $name
*/
public function isRoutesRegisterGroup($name) : bool
{
return $this->nodeNameResolver->isName($name, 'group');
}
/**
* @param \PhpParser\Node\Identifier|\PhpParser\Node\Expr $name
*/
public function isRoutesRegisterRoute($name) : bool
{
return $this->nodeNameResolver->isNames($name, ['delete', 'get', 'options', 'patch', 'post', 'put']);
}
}

View File

@ -1,37 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\NodeAnalyzer;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\StaticCall;
use Rector\NodeNameResolver\NodeNameResolver;
final class StaticCallAnalyzer
{
/**
* @readonly
* @var \Rector\NodeNameResolver\NodeNameResolver
*/
private $nodeNameResolver;
public function __construct(NodeNameResolver $nodeNameResolver)
{
$this->nodeNameResolver = $nodeNameResolver;
}
public function isParentCallNamed(Node $node, string $desiredMethodName) : bool
{
if (!$node instanceof StaticCall) {
return \false;
}
if ($node->class instanceof Expr) {
return \false;
}
if (!$this->nodeNameResolver->isName($node->class, 'parent')) {
return \false;
}
if ($node->name instanceof Expr) {
return \false;
}
return $this->nodeNameResolver->isName($node->name, $desiredMethodName);
}
}

View File

@ -1,41 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\NodeFactory;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Expression;
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\BetterPhpDocParser\ValueObject\Type\FullyQualifiedIdentifierTypeNode;
use Rector\Laravel\ValueObject\ServiceNameTypeAndVariableName;
final class AppAssignFactory
{
/**
* @readonly
* @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory
*/
private $phpDocInfoFactory;
public function __construct(PhpDocInfoFactory $phpDocInfoFactory)
{
$this->phpDocInfoFactory = $phpDocInfoFactory;
}
public function createAssignExpression(ServiceNameTypeAndVariableName $serviceNameTypeAndVariableName, Expr $expr) : Expression
{
$variable = new Variable($serviceNameTypeAndVariableName->getVariableName());
$assign = new Assign($variable, $expr);
$expression = new Expression($assign);
$this->decorateWithVarAnnotation($expression, $serviceNameTypeAndVariableName);
return $expression;
}
private function decorateWithVarAnnotation(Expression $expression, ServiceNameTypeAndVariableName $serviceNameTypeAndVariableName) : void
{
$phpDocInfo = $this->phpDocInfoFactory->createEmpty($expression);
$fullyQualifiedIdentifierTypeNode = new FullyQualifiedIdentifierTypeNode($serviceNameTypeAndVariableName->getType());
$varTagValueNode = new VarTagValueNode($fullyQualifiedIdentifierTypeNode, '$' . $serviceNameTypeAndVariableName->getVariableName(), '');
$phpDocInfo->addTagValueNode($varTagValueNode);
$phpDocInfo->makeSingleLined();
}
}

View File

@ -1,163 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\NodeFactory;
use PhpParser\Builder\Method;
use PhpParser\Builder\Property;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Return_;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor\NameResolver;
use Rector\Core\PhpParser\Node\NodeFactory;
use Rector\Core\PhpParser\Node\Value\ValueResolver;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
final class ModelFactoryNodeFactory
{
/**
* @var string
*/
private const THIS = 'this';
/**
* @readonly
* @var \Rector\NodeNameResolver\NodeNameResolver
*/
private $nodeNameResolver;
/**
* @readonly
* @var \Rector\Core\PhpParser\Node\NodeFactory
*/
private $nodeFactory;
/**
* @readonly
* @var \Rector\Core\PhpParser\Node\Value\ValueResolver
*/
private $valueResolver;
/**
* @readonly
* @var \Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser
*/
private $simpleCallableNodeTraverser;
public function __construct(NodeNameResolver $nodeNameResolver, NodeFactory $nodeFactory, ValueResolver $valueResolver, SimpleCallableNodeTraverser $simpleCallableNodeTraverser)
{
$this->nodeNameResolver = $nodeNameResolver;
$this->nodeFactory = $nodeFactory;
$this->valueResolver = $valueResolver;
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
}
public function createEmptyFactory(string $name, Expr $expr) : Class_
{
$class = new Class_($name . 'Factory');
$class->extends = new FullyQualified('Illuminate\\Database\\Eloquent\\Factories\\Factory');
$propertyBuilder = new Property('model');
$propertyBuilder->makeProtected();
$propertyBuilder->setDefault($expr);
$property = $propertyBuilder->getNode();
$class->stmts[] = $property;
// decorate with namespaced names
$nameResolver = new NameResolver(null, ['replaceNodes' => \false, 'preserveOriginalNames' => \true]);
$nodeTraverser = new NodeTraverser();
$nodeTraverser->addVisitor($nameResolver);
$nodeTraverser->traverse([$class]);
return $class;
}
public function createDefinition(Closure $closure) : ClassMethod
{
if (isset($closure->params[0])) {
$this->fakerVariableToPropertyFetch($closure->stmts, $closure->params[0]);
}
return $this->createPublicMethod('definition', $closure->stmts);
}
public function createStateMethod(MethodCall $methodCall) : ?ClassMethod
{
if (!isset($methodCall->args[2])) {
return null;
}
if (!$methodCall->args[2] instanceof Arg) {
return null;
}
$thirdArgValue = $methodCall->args[2]->value;
// the third argument may be closure or array
if ($thirdArgValue instanceof Closure && isset($thirdArgValue->params[0])) {
$this->fakerVariableToPropertyFetch($thirdArgValue->stmts, $thirdArgValue->params[0]);
unset($thirdArgValue->params[0]);
}
$expr = $this->nodeFactory->createMethodCall(self::THIS, 'state', [$methodCall->args[2]]);
$return = new Return_($expr);
if (!isset($methodCall->args[1])) {
return null;
}
if (!$methodCall->args[1] instanceof Arg) {
return null;
}
$methodName = $this->valueResolver->getValue($methodCall->args[1]->value);
if (!\is_string($methodName)) {
return null;
}
return $this->createPublicMethod($methodName, [$return]);
}
public function createEmptyConfigure() : ClassMethod
{
$return = new Return_(new Variable(self::THIS));
return $this->createPublicMethod('configure', [$return]);
}
public function appendConfigure(ClassMethod $classMethod, string $name, Closure $closure) : void
{
$this->simpleCallableNodeTraverser->traverseNodesWithCallable((array) $classMethod->stmts, function (Node $node) use($closure, $name) : ?Return_ {
if (!$node instanceof Return_) {
return null;
}
if ($node->expr === null) {
return null;
}
if (isset($closure->params[1])) {
$this->fakerVariableToPropertyFetch($closure->stmts, $closure->params[1]);
// remove argument $faker
unset($closure->params[1]);
}
$node->expr = $this->nodeFactory->createMethodCall($node->expr, $name, [$closure]);
return $node;
});
}
/**
* @param Node\Stmt[] $stmts
*/
private function fakerVariableToPropertyFetch(array $stmts, Param $param) : void
{
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($stmts, function (Node $node) use($param) : ?PropertyFetch {
if (!$node instanceof Variable) {
return null;
}
$name = $this->nodeNameResolver->getName($param->var);
if ($name === null) {
return null;
}
if (!$this->nodeNameResolver->isName($node, $name)) {
return null;
}
// use $this->faker instead of $faker
return $this->nodeFactory->createPropertyFetch(self::THIS, 'faker');
});
}
/**
* @param Node\Stmt[] $stmts
*/
private function createPublicMethod(string $name, array $stmts) : ClassMethod
{
$method = new Method($name);
$method->makePublic();
$method->addStmts($stmts);
return $method->getNode();
}
}

View File

@ -1,87 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\NodeFactory;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Identifier;
use PHPStan\Type\ObjectType;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\NodeTypeResolver;
final class RouterRegisterNodeAnalyzer
{
/**
* @readonly
* @var \Rector\NodeNameResolver\NodeNameResolver
*/
private $nodeNameResolver;
/**
* @readonly
* @var \Rector\NodeTypeResolver\NodeTypeResolver
*/
private $nodeTypeResolver;
public function __construct(NodeNameResolver $nodeNameResolver, NodeTypeResolver $nodeTypeResolver)
{
$this->nodeNameResolver = $nodeNameResolver;
$this->nodeTypeResolver = $nodeTypeResolver;
}
/**
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $node
*/
public function isRegisterMethodStaticCall($node) : bool
{
if (!$this->isRegisterName($node->name)) {
return \false;
}
if ($node instanceof MethodCall && $this->nodeTypeResolver->isObjectTypes($node->var, [new ObjectType('Illuminate\\Routing\\Router'), new ObjectType('Illuminate\\Routing\\RouteRegistrar')])) {
return \true;
}
return $node instanceof StaticCall && $this->nodeNameResolver->isName($node->class, 'Illuminate\\Support\\Facades\\Route');
}
/**
* @param \PhpParser\Node\Identifier|\PhpParser\Node\Expr $name
*/
public function isRegisterName($name) : bool
{
if ($this->isRegisterAnyVerb($name)) {
return \true;
}
if ($this->isRegisterMultipleVerbs($name)) {
return \true;
}
if ($this->isRegisterAllVerbs($name)) {
return \true;
}
return $this->isRegisterFallback($name);
}
/**
* @param \PhpParser\Node\Identifier|\PhpParser\Node\Expr $name
*/
public function isRegisterMultipleVerbs($name) : bool
{
return $this->nodeNameResolver->isName($name, 'match');
}
/**
* @param \PhpParser\Node\Identifier|\PhpParser\Node\Expr $name
*/
public function isRegisterAllVerbs($name) : bool
{
return $this->nodeNameResolver->isName($name, 'any');
}
/**
* @param \PhpParser\Node\Identifier|\PhpParser\Node\Expr $name
*/
public function isRegisterAnyVerb($name) : bool
{
return $this->nodeNameResolver->isNames($name, ['delete', 'get', 'options', 'patch', 'post', 'put']);
}
/**
* @param \PhpParser\Node\Identifier|\PhpParser\Node\Expr $name
*/
public function isRegisterFallback($name) : bool
{
return $this->nodeNameResolver->isName($name, 'fallback');
}
}

View File

@ -1,116 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\Assign;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\Laravel\NodeFactory\AppAssignFactory;
use Rector\Laravel\ValueObject\ServiceNameTypeAndVariableName;
use Rector\PostRector\Collector\NodesToAddCollector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Laravel\Tests\Rector\Assign\CallOnAppArrayAccessToStandaloneAssignRector\CallOnAppArrayAccessToStandaloneAssignRectorTest
*/
final class CallOnAppArrayAccessToStandaloneAssignRector extends AbstractRector
{
/**
* @var ServiceNameTypeAndVariableName[]
*/
private $serviceNameTypeAndVariableNames = [];
/**
* @readonly
* @var \Rector\Laravel\NodeFactory\AppAssignFactory
*/
private $appAssignFactory;
/**
* @readonly
* @var \Rector\PostRector\Collector\NodesToAddCollector
*/
private $nodesToAddCollector;
public function __construct(AppAssignFactory $appAssignFactory, NodesToAddCollector $nodesToAddCollector)
{
$this->appAssignFactory = $appAssignFactory;
$this->nodesToAddCollector = $nodesToAddCollector;
$this->serviceNameTypeAndVariableNames[] = new ServiceNameTypeAndVariableName('validator', 'Illuminate\\Validation\\Factory', 'validationFactory');
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [Assign::class];
}
/**
* @param Assign $node
*/
public function refactor(Node $node) : ?Node
{
if (!$node->expr instanceof MethodCall) {
return null;
}
$methodCall = $node->expr;
if (!$methodCall->var instanceof ArrayDimFetch) {
return null;
}
$arrayDimFetch = $methodCall->var;
if (!$this->isObjectType($arrayDimFetch->var, new ObjectType('Illuminate\\Contracts\\Foundation\\Application'))) {
return null;
}
$arrayDimFetchDim = $methodCall->var->dim;
if (!$arrayDimFetchDim instanceof Expr) {
return null;
}
foreach ($this->serviceNameTypeAndVariableNames as $serviceNameTypeAndVariableName) {
if (!$this->valueResolver->isValue($arrayDimFetchDim, $serviceNameTypeAndVariableName->getServiceName())) {
continue;
}
$assignExpression = $this->appAssignFactory->createAssignExpression($serviceNameTypeAndVariableName, $methodCall->var);
$this->nodesToAddCollector->addNodeBeforeNode($assignExpression, $node);
$methodCall->var = new Variable($serviceNameTypeAndVariableName->getVariableName());
return $node;
}
return null;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Replace magical call on $this->app["something"] to standalone type assign variable', [new CodeSample(<<<'CODE_SAMPLE'
class SomeClass
{
/**
* @var \Illuminate\Contracts\Foundation\Application
*/
private $app;
public function run()
{
$validator = $this->app['validator']->make('...');
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
class SomeClass
{
/**
* @var \Illuminate\Contracts\Foundation\Application
*/
private $app;
public function run()
{
/** @var \Illuminate\Validation\Factory $validationFactory */
$validationFactory = $this->app['validator'];
$validator = $validationFactory->make('...');
}
}
CODE_SAMPLE
)]);
}
}

View File

@ -1,90 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\ClassMethod;
use PhpParser\BuilderHelpers;
use PhpParser\Node;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Laravel\ValueObject\AddArgumentDefaultValue;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use RectorPrefix202210\Webmozart\Assert\Assert;
/**
* @see \Rector\Laravel\Tests\Rector\ClassMethod\AddArgumentDefaultValueRector\AddArgumentDefaultValueRectorTest
*/
final class AddArgumentDefaultValueRector extends AbstractRector implements ConfigurableRectorInterface
{
/**
* @var string
*/
public const ADDED_ARGUMENTS = 'added_arguments';
/**
* @var AddArgumentDefaultValue[]
*/
private $addedArguments = [];
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Adds default value for arguments in defined methods.', [new ConfiguredCodeSample(<<<'CODE_SAMPLE'
class SomeClass
{
public function someMethod($value)
{
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
class SomeClass
{
public function someMethod($value = false)
{
}
}
CODE_SAMPLE
, [self::ADDED_ARGUMENTS => [new AddArgumentDefaultValue('SomeClass', 'someMethod', 0, \false)]])]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [ClassMethod::class];
}
/**
* @param ClassMethod $node
*/
public function refactor(Node $node) : ClassMethod
{
foreach ($this->addedArguments as $addedArgument) {
if (!$this->nodeTypeResolver->isObjectType($node, $addedArgument->getObjectType())) {
continue;
}
if (!$this->isName($node->name, $addedArgument->getMethod())) {
continue;
}
if (!isset($node->params[$addedArgument->getPosition()])) {
continue;
}
$position = $addedArgument->getPosition();
$param = $node->params[$position];
if ($param->default !== null) {
continue;
}
$node->params[$position] = new Param($param->var, BuilderHelpers::normalizeValue($addedArgument->getDefaultValue()));
}
return $node;
}
/**
* @param mixed[] $configuration
*/
public function configure(array $configuration) : void
{
$addedArguments = $configuration[self::ADDED_ARGUMENTS] ?? $configuration;
Assert::isArray($addedArguments);
Assert::allIsInstanceOf($addedArguments, AddArgumentDefaultValue::class);
$this->addedArguments = $addedArguments;
}
}

View File

@ -1,148 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Return_;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\Generic\GenericClassStringType;
use PHPStan\Type\ObjectType;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\ValueObject\Type\FullyQualifiedIdentifierTypeNode;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/** @see \Rector\Laravel\Tests\Rector\ClassMethod\AddGenericReturnTypeToRelationsRector\AddGenericReturnTypeToRelationsRectorTest */
class AddGenericReturnTypeToRelationsRector extends AbstractRector
{
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Add generic return type to relations in child of Illuminate\\Database\\Eloquent\\Model', [new CodeSample(<<<'CODE_SAMPLE'
use App\Account;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class User extends Model
{
public function accounts(): HasMany
{
return $this->hasMany(Account::class);
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
use App\Account;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class User extends Model
{
/** @return HasMany<Account> */
public function accounts(): HasMany
{
return $this->hasMany(Account::class);
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [ClassMethod::class];
}
/**
* @param ClassMethod $node
*/
public function refactor(Node $node) : ?Node
{
if ($this->shouldSkipNode($node)) {
return null;
}
$methodReturnType = $node->getReturnType();
if ($methodReturnType === null) {
return null;
}
$methodReturnTypeName = $this->getName($methodReturnType);
if ($methodReturnTypeName === null) {
return null;
}
if (!$this->isObjectType($methodReturnType, new ObjectType('Illuminate\\Database\\Eloquent\\Relations\\Relation'))) {
return null;
}
$phpDocInfo = $this->phpDocInfoFactory->createFromNode($node);
if (!$phpDocInfo instanceof PhpDocInfo) {
return null;
}
// Return, if already has return type
if ($node->getDocComment() !== null && $phpDocInfo->hasByName('return')) {
return null;
}
$returnStatement = $this->betterNodeFinder->findFirstInFunctionLikeScoped($node, function (Node $subNode) : bool {
return $subNode instanceof Return_;
});
if (!$returnStatement instanceof Return_) {
return null;
}
$relationMethodCall = $this->betterNodeFinder->findFirstInstanceOf($returnStatement, MethodCall::class);
if (!$relationMethodCall instanceof MethodCall) {
return null;
}
$relatedClass = $this->getRelatedModelClassFromMethodCall($relationMethodCall);
if ($relatedClass === null) {
return null;
}
$phpDocInfo->addTagValueNode(new ReturnTagValueNode(new GenericTypeNode(new FullyQualifiedIdentifierTypeNode($methodReturnTypeName), [new FullyQualifiedIdentifierTypeNode($relatedClass)]), ''));
return $node;
}
private function getRelatedModelClassFromMethodCall(MethodCall $methodCall) : ?string
{
$methodName = $methodCall->name;
if (!$methodName instanceof Identifier) {
return null;
}
// Called method should be one of the Laravel's relation methods
if (!\in_array($methodName->name, ['hasOne', 'hasOneThrough', 'morphOne', 'belongsTo', 'morphTo', 'hasMany', 'hasManyThrough', 'morphMany', 'belongsToMany', 'morphToMany', 'morphedByMany'], \true)) {
return null;
}
if (\count($methodCall->getArgs()) < 1) {
return null;
}
$argType = $this->getType($methodCall->getArgs()[0]->value);
if ($argType instanceof ConstantStringType) {
return $argType->getValue();
}
if (!$argType instanceof GenericClassStringType) {
return null;
}
$modelType = $argType->getGenericType();
if (!$modelType instanceof ObjectType) {
return null;
}
return $modelType->getClassName();
}
private function shouldSkipNode(ClassMethod $classMethod) : bool
{
if ($classMethod->stmts === null) {
return \true;
}
$classLike = $this->betterNodeFinder->findParentType($classMethod, ClassLike::class);
if (!$classLike instanceof ClassLike) {
return \true;
}
if ($classLike instanceof Class_) {
return !$this->isObjectType($classLike, new ObjectType('Illuminate\\Database\\Eloquent\\Model'));
}
return \false;
}
}

View File

@ -1,103 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\Laravel\NodeAnalyzer\StaticCallAnalyzer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://laracasts.com/discuss/channels/laravel/laravel-57-upgrade-observer-problem
*
* @see \Rector\Laravel\Tests\Rector\ClassMethod\AddParentBootToModelClassMethodRector\AddParentBootToModelClassMethodRectorTest
*/
final class AddParentBootToModelClassMethodRector extends AbstractRector
{
/**
* @var string
*/
private const BOOT = 'boot';
/**
* @readonly
* @var \Rector\Laravel\NodeAnalyzer\StaticCallAnalyzer
*/
private $staticCallAnalyzer;
public function __construct(StaticCallAnalyzer $staticCallAnalyzer)
{
$this->staticCallAnalyzer = $staticCallAnalyzer;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Add parent::boot(); call to boot() class method in child of Illuminate\\Database\\Eloquent\\Model', [new CodeSample(<<<'CODE_SAMPLE'
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
public function boot()
{
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
public function boot()
{
parent::boot();
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [ClassMethod::class];
}
/**
* @param ClassMethod $node
*/
public function refactor(Node $node) : ?Node
{
$classLike = $this->betterNodeFinder->findParentType($node, ClassLike::class);
if (!$classLike instanceof ClassLike) {
return null;
}
if (!$this->isObjectType($classLike, new ObjectType('Illuminate\\Database\\Eloquent\\Model'))) {
return null;
}
if (!$this->isName($node->name, self::BOOT)) {
return null;
}
foreach ((array) $node->stmts as $key => $classMethodStmt) {
if ($classMethodStmt instanceof Expression) {
$classMethodStmt = $classMethodStmt->expr;
}
// is in the 1st position? → only correct place
// @see https://laracasts.com/discuss/channels/laravel/laravel-57-upgrade-observer-problem?page=0#reply=454409
if (!$this->staticCallAnalyzer->isParentCallNamed($classMethodStmt, self::BOOT)) {
continue;
}
if ($key === 0) {
return null;
}
// wrong location → remove it
unset($node->stmts[$key]);
}
// missing, we need to add one
$staticCall = $this->nodeFactory->createStaticCall('parent', self::BOOT);
$parentStaticCallExpression = new Expression($staticCall);
$node->stmts = \array_merge([$parentStaticCallExpression], (array) $node->stmts);
return $node;
}
}

View File

@ -1,99 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\Laravel\NodeAnalyzer\StaticCallAnalyzer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://laravel.com/docs/8.x/upgrade#the-event-service-provider-class
*
* @see \Rector\Laravel\Tests\Rector\ClassMethod\AddParentRegisterToEventServiceProviderRector\AddParentRegisterToEventServiceProviderRectorTest
*/
final class AddParentRegisterToEventServiceProviderRector extends AbstractRector
{
/**
* @var string
*/
private const REGISTER = 'register';
/**
* @readonly
* @var \Rector\Laravel\NodeAnalyzer\StaticCallAnalyzer
*/
private $staticCallAnalyzer;
public function __construct(StaticCallAnalyzer $staticCallAnalyzer)
{
$this->staticCallAnalyzer = $staticCallAnalyzer;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Add parent::register(); call to register() class method in child of Illuminate\\Foundation\\Support\\Providers\\EventServiceProvider', [new CodeSample(<<<'CODE_SAMPLE'
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
public function register()
{
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
public function register()
{
parent::register();
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [ClassMethod::class];
}
/**
* @param ClassMethod $node
*/
public function refactor(Node $node) : ?Node
{
$classLike = $this->betterNodeFinder->findParentType($node, ClassLike::class);
if (!$classLike instanceof ClassLike) {
return null;
}
if (!$this->isObjectType($classLike, new ObjectType('Illuminate\\Foundation\\Support\\Providers\\EventServiceProvider'))) {
return null;
}
if (!$this->isName($node->name, self::REGISTER)) {
return null;
}
foreach ((array) $node->stmts as $key => $classMethodStmt) {
if ($classMethodStmt instanceof Expression) {
$classMethodStmt = $classMethodStmt->expr;
}
if (!$this->staticCallAnalyzer->isParentCallNamed($classMethodStmt, self::REGISTER)) {
continue;
}
if ($key === 0) {
return null;
}
unset($node->stmts[$key]);
}
$staticCall = $this->nodeFactory->createStaticCall('parent', self::REGISTER);
$parentStaticCallExpression = new Expression($staticCall);
$node->stmts = \array_merge([$parentStaticCallExpression], (array) $node->stmts);
return $node;
}
}

View File

@ -1,153 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\Class_;
use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use PHPStan\Type\ObjectType;
use Rector\Core\Enum\ObjectReference;
use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\MethodName;
use Rector\PHPUnit\NodeAnalyzer\SetUpMethodDecorator;
use Rector\Privatization\NodeManipulator\VisibilityManipulator;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://github.com/laravel/framework/issues/26450#issuecomment-449401202
* @changelog https://github.com/laravel/framework/commit/055fe52dbb7169dc51bd5d5deeb05e8da9be0470#diff-76a649cb397ea47f5613459c335f88c1b68e5f93e51d46e9fb5308ec55ded221
*
* @see \Rector\Laravel\Tests\Rector\Class_\AddMockConsoleOutputFalseToConsoleTestsRector\AddMockConsoleOutputFalseToConsoleTestsRectorTest
*/
final class AddMockConsoleOutputFalseToConsoleTestsRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer
*/
private $propertyFetchAnalyzer;
/**
* @readonly
* @var \Rector\PHPUnit\NodeAnalyzer\SetUpMethodDecorator
*/
private $setUpMethodDecorator;
/**
* @readonly
* @var \Rector\Privatization\NodeManipulator\VisibilityManipulator
*/
private $visibilityManipulator;
public function __construct(PropertyFetchAnalyzer $propertyFetchAnalyzer, SetUpMethodDecorator $setUpMethodDecorator, VisibilityManipulator $visibilityManipulator)
{
$this->propertyFetchAnalyzer = $propertyFetchAnalyzer;
$this->setUpMethodDecorator = $setUpMethodDecorator;
$this->visibilityManipulator = $visibilityManipulator;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Add "$this->mockConsoleOutput = false"; to console tests that work with output content', [new CodeSample(<<<'CODE_SAMPLE'
use Illuminate\Support\Facades\Artisan;
use Illuminate\Foundation\Testing\TestCase;
final class SomeTest extends TestCase
{
public function test(): void
{
$this->assertEquals('content', \trim((new Artisan())::output()));
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
use Illuminate\Support\Facades\Artisan;
use Illuminate\Foundation\Testing\TestCase;
final class SomeTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
$this->mockConsoleOutput = false;
}
public function test(): void
{
$this->assertEquals('content', \trim((new Artisan())::output()));
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [Class_::class];
}
/**
* @param Class_ $node
*/
public function refactor(Node $node) : ?Node
{
if (!$this->isObjectType($node, new ObjectType('Illuminate\\Foundation\\Testing\\TestCase'))) {
return null;
}
if (!$this->isTestingConsoleOutput($node)) {
return null;
}
// has setUp with property `$mockConsoleOutput = false`
if ($this->hasMockConsoleOutputFalse($node)) {
return null;
}
$assign = $this->createAssign();
$setUpClassMethod = $node->getMethod(MethodName::SET_UP);
if (!$setUpClassMethod instanceof ClassMethod) {
$setUpClassMethod = new ClassMethod(MethodName::SET_UP);
$setUpClassMethod->stmts = [new Expression(new StaticCall(new Name(ObjectReference::PARENT), MethodName::SET_UP)), new Expression($assign)];
$this->setUpMethodDecorator->decorate($setUpClassMethod);
$this->visibilityManipulator->makeProtected($setUpClassMethod);
$node->stmts = \array_merge([$setUpClassMethod], $node->stmts);
} else {
$setUpClassMethod->stmts = \array_merge((array) $setUpClassMethod->stmts, [new Expression($assign)]);
}
return $node;
}
private function isTestingConsoleOutput(Class_ $class) : bool
{
return (bool) $this->betterNodeFinder->findFirst($class->stmts, function (Node $node) : bool {
if (!$node instanceof StaticCall) {
return \false;
}
$callerType = $this->nodeTypeResolver->getType($node->class);
if (!$callerType->isSuperTypeOf(new ObjectType('Illuminate\\Support\\Facades\\Artisan'))->yes()) {
return \false;
}
return $this->isName($node->name, 'output');
});
}
private function hasMockConsoleOutputFalse(Class_ $class) : bool
{
return (bool) $this->betterNodeFinder->findFirst($class, function (Node $node) : bool {
if ($node instanceof Assign) {
if (!$this->propertyFetchAnalyzer->isLocalPropertyFetchName($node->var, 'mockConsoleOutput')) {
return \false;
}
return $this->valueResolver->isFalse($node->expr);
}
return \false;
});
}
private function createAssign() : Assign
{
$propertyFetch = new PropertyFetch(new Variable('this'), 'mockConsoleOutput');
return new Assign($propertyFetch, $this->nodeFactory->createFalse());
}
}

View File

@ -1,75 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\Class_;
use PhpParser\Node;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Return_;
use PHPStan\Type\ObjectType;
use Rector\Core\NodeAnalyzer\ClassAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://github.com/laravel/framework/pull/36906
* @changelog https://github.com/laravel/framework/pull/37352
*
* @see \Rector\Laravel\Tests\Rector\Class_\AnonymousMigrationsRector\AnonymousMigrationsRectorTest
*/
final class AnonymousMigrationsRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\Core\NodeAnalyzer\ClassAnalyzer
*/
private $classAnalyzer;
public function __construct(ClassAnalyzer $classAnalyzer)
{
$this->classAnalyzer = $classAnalyzer;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Convert migrations to anonymous classes.', [new CodeSample(<<<'CODE_SAMPLE'
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
// ...
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
use Illuminate\Database\Migrations\Migration;
return new class extends Migration
{
// ...
};
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [Class_::class];
}
/**
* @param Class_ $node
*/
public function refactor(Node $node) : ?Node
{
if (!$this->isObjectType($node, new ObjectType('Illuminate\\Database\\Migrations\\Migration'))) {
return null;
}
if ($node->isAbstract()) {
return null;
}
if ($this->classAnalyzer->isAnonymousClass($node)) {
return null;
}
return new Return_(new New_(new Class_(null, ['flags' => $node->flags, 'extends' => $node->extends, 'implements' => $node->implements, 'stmts' => $node->stmts, 'attrGroups' => $node->attrGroups])));
}
}

View File

@ -1,83 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\Class_;
use PhpParser\Node;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Property;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://laravel.com/docs/5.8/upgrade#deferred-service-providers
*
* @see \Rector\Laravel\Tests\Rector\Class_\PropertyDeferToDeferrableProviderToRector\PropertyDeferToDeferrableProviderToRectorTest
*/
final class PropertyDeferToDeferrableProviderToRector extends AbstractRector
{
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Change deprecated $defer = true; to Illuminate\\Contracts\\Support\\DeferrableProvider interface', [new CodeSample(<<<'CODE_SAMPLE'
use Illuminate\Support\ServiceProvider;
final class SomeServiceProvider extends ServiceProvider
{
/**
* @var bool
*/
protected $defer = true;
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\Support\DeferrableProvider;
final class SomeServiceProvider extends ServiceProvider implements DeferrableProvider
{
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [Class_::class];
}
/**
* @param Class_ $node
*/
public function refactor(Node $node) : ?Node
{
if (!$this->isObjectType($node, new ObjectType('Illuminate\\Support\\ServiceProvider'))) {
return null;
}
$deferProperty = $this->matchDeferWithFalseProperty($node);
if (!$deferProperty instanceof Property) {
return null;
}
$this->removeNode($deferProperty);
$node->implements[] = new FullyQualified('Illuminate\\Contracts\\Support\\DeferrableProvider');
return $node;
}
private function matchDeferWithFalseProperty(Class_ $class) : ?Property
{
foreach ($class->getProperties() as $property) {
if (!$this->isName($property, 'defer')) {
continue;
}
$onlyProperty = $property->props[0];
if ($onlyProperty->default === null) {
return null;
}
if ($this->valueResolver->isTrue($onlyProperty->default)) {
return $property;
}
}
return null;
}
}

View File

@ -1,119 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\Class_;
use PhpParser\Node;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Property;
use PHPStan\Type\ObjectType;
use Rector\Core\NodeManipulator\ClassInsertManipulator;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use RectorPrefix202210\Webmozart\Assert\Assert;
/**
* @changelog https://github.com/laravel/framework/pull/32856
*
* @see \Rector\Laravel\Tests\Rector\Class_\UnifyModelDatesWithCastsRector\UnifyModelDatesWithCastsRectorTest
*/
final class UnifyModelDatesWithCastsRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\Core\NodeManipulator\ClassInsertManipulator
*/
private $classInsertManipulator;
public function __construct(ClassInsertManipulator $classInsertManipulator)
{
$this->classInsertManipulator = $classInsertManipulator;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Unify Model $dates property with $casts', [new CodeSample(<<<'CODE_SAMPLE'
use Illuminate\Database\Eloquent\Model;
class Person extends Model
{
protected $casts = [
'age' => 'integer',
];
protected $dates = ['birthday'];
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
use Illuminate\Database\Eloquent\Model;
class Person extends Model
{
protected $casts = [
'age' => 'integer', 'birthday' => 'datetime',
];
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [Class_::class];
}
/**
* @param Class_ $node
*/
public function refactor(Node $node) : ?Node
{
if (!$this->isObjectType($node, new ObjectType('Illuminate\\Database\\Eloquent\\Model'))) {
return null;
}
$datesProperty = $node->getProperty('dates');
if (!$datesProperty instanceof Property) {
return null;
}
$datesPropertyProperty = $datesProperty->props[0];
if (!$datesPropertyProperty->default instanceof Array_) {
return null;
}
$dates = $this->valueResolver->getValue($datesPropertyProperty->default);
if (!\is_array($dates)) {
return null;
}
if ($dates === []) {
return null;
}
$castsProperty = $node->getProperty('casts');
// add property $casts if not exists
if (!$castsProperty instanceof Property) {
$castsProperty = $this->createCastsProperty();
$this->classInsertManipulator->addAsFirstMethod($node, $castsProperty);
}
$castsPropertyProperty = $castsProperty->props[0];
if (!$castsPropertyProperty->default instanceof Array_) {
return null;
}
$casts = $this->valueResolver->getValue($castsPropertyProperty->default);
// exclude attributes added in $casts
$missingDates = \array_diff($dates, \array_keys($casts));
Assert::allString($missingDates);
foreach ($missingDates as $missingDate) {
$castsPropertyProperty->default->items[] = new ArrayItem(new String_('datetime'), new String_($missingDate));
}
$this->nodeRemover->removeNode($datesProperty);
return null;
}
private function createCastsProperty() : Property
{
$propertyBuilder = new \PhpParser\Builder\Property('casts');
$propertyBuilder->makeProtected();
$propertyBuilder->setDefault([]);
$property = $propertyBuilder->getNode();
$this->phpDocInfoFactory->createFromNode($property);
return $property;
}
}

View File

@ -1,69 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\StaticCall;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://laravel.com/docs/7.x/database-testing#creating-models
* @changelog https://laravel.com/docs/8.x/database-testing#instantiating-models
*
* @see \Rector\Laravel\Tests\Rector\FuncCall\FactoryFuncCallToStaticCallRector\FactoryFuncCallToStaticCallRectorTest
*/
final class FactoryFuncCallToStaticCallRector extends AbstractRector
{
/**
* @var string
*/
private const FACTORY = 'factory';
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Use the static factory method instead of global factory function.', [new CodeSample(<<<'CODE_SAMPLE'
factory(User::class);
CODE_SAMPLE
, <<<'CODE_SAMPLE'
User::factory();
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [FuncCall::class];
}
/**
* @param Node\Expr\FuncCall $node
*/
public function refactor(Node $node) : ?Node
{
if (!$this->isName($node->name, self::FACTORY)) {
return null;
}
if (!isset($node->args[0])) {
return null;
}
if (!$node->args[0] instanceof Arg) {
return null;
}
$firstArgValue = $node->args[0]->value;
if (!$firstArgValue instanceof ClassConstFetch) {
return null;
}
$model = $firstArgValue->class;
// create model
if (!isset($node->args[1])) {
return new StaticCall($model, self::FACTORY);
}
// create models of a given type
return new StaticCall($model, self::FACTORY, [$node->args[1]]);
}
}

View File

@ -1,61 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://laravel.com/docs/8.x/helpers#method-app
* @changelog https://github.com/laravel/framework/blob/8.x/src/Illuminate/Foundation/helpers.php
*
* @see \Rector\Laravel\Tests\Rector\FuncCall\HelperFuncCallToFacadeClassRector\HelperFuncCallToFacadeClassRectorTest
*/
final class HelperFuncCallToFacadeClassRector extends AbstractRector
{
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Change app() func calls to facade calls', [new CodeSample(<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
{
return app('translator')->trans('value');
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
class SomeClass
{
public function run()
{
return \Illuminate\Support\Facades\App::get('translator')->trans('value');
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [FuncCall::class];
}
/**
* @param FuncCall $node
*/
public function refactor(Node $node) : ?Node
{
if (!$this->isName($node->name, 'app')) {
return null;
}
if (\count($node->args) !== 1) {
return null;
}
return $this->nodeFactory->createStaticCall('Illuminate\\Support\\Facades\\App', 'get', $node->args);
}
}

View File

@ -1,74 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Stmt\Expression;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Laravel\Tests\Rector\FuncCall\RemoveDumpDataDeadCodeRector\RemoveDumpDataDeadCodeRectorTest
*/
final class RemoveDumpDataDeadCodeRector extends AbstractRector
{
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('It will removes the dump data just like dd or dump functions from the code.`', [new CodeSample(<<<'CODE_SAMPLE'
class MyController
{
public function store()
{
dd('test');
return true;
}
public function update()
{
dump('test');
return true;
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
class MyController
{
public function store()
{
return true;
}
public function update()
{
return true;
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [FuncCall::class];
}
/**
* @param FuncCall $node
*/
public function refactor(Node $node) : ?Node
{
if (!$this->isNames($node->name, ['dd', 'dump'])) {
return null;
}
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
if (!$parentNode instanceof Expression) {
return null;
}
$this->removeNode($node);
return null;
}
}

View File

@ -1,170 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\String_;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\PostRector\Collector\NodesToAddCollector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://github.com/laravel/framework/pull/25315
* @changelog https://laracasts.com/discuss/channels/eloquent/laravel-eloquent-where-date-is-equal-or-smaller-than-datetime
*
* @see \Rector\Laravel\Tests\Rector\MethodCall\ChangeQueryWhereDateValueWithCarbonRector\ChangeQueryWhereDateValueWithCarbonRectorTest
*/
final class ChangeQueryWhereDateValueWithCarbonRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\PostRector\Collector\NodesToAddCollector
*/
private $nodesToAddCollector;
public function __construct(NodesToAddCollector $nodesToAddCollector)
{
$this->nodesToAddCollector = $nodesToAddCollector;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Add parent::boot(); call to boot() class method in child of Illuminate\\Database\\Eloquent\\Model', [new CodeSample(<<<'CODE_SAMPLE'
use Illuminate\Database\Query\Builder;
final class SomeClass
{
public function run(Builder $query)
{
$query->whereDate('created_at', '<', Carbon::now());
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
use Illuminate\Database\Query\Builder;
final class SomeClass
{
public function run(Builder $query)
{
$dateTime = Carbon::now();
$query->whereDate('created_at', '<=', $dateTime);
$query->whereTime('created_at', '<=', $dateTime);
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [MethodCall::class];
}
/**
* @param MethodCall $node
*/
public function refactor(Node $node) : ?Node
{
$expr = $this->matchWhereDateThirdArgValue($node);
if (!$expr instanceof Expr) {
return null;
}
// is just made with static call?
if ($expr instanceof StaticCall || $expr instanceof MethodCall) {
// now!
// 1. extract assign
$dateTimeVariable = new Variable('dateTime');
$assign = new Assign($dateTimeVariable, $expr);
$this->nodesToAddCollector->addNodeBeforeNode($assign, $node);
if (!$node->args[2] instanceof Arg) {
return null;
}
$node->args[2]->value = $dateTimeVariable;
if (!$node->args[1] instanceof Arg) {
return null;
}
// update assign ">" → ">="
$this->changeCompareSignExpr($node->args[1]);
// 2. add "whereTime()" time call
$whereTimeMethodCall = $this->createWhereTimeMethodCall($node, $dateTimeVariable);
$this->nodesToAddCollector->addNodeAfterNode($whereTimeMethodCall, $node);
return $node;
}
if ($expr instanceof Variable && $node->args[1] instanceof Arg) {
$dateTimeVariable = $expr;
$this->changeCompareSignExpr($node->args[1]);
// 2. add "whereTime()" time call
$whereTimeMethodCall = $this->createWhereTimeMethodCall($node, $dateTimeVariable);
$this->nodesToAddCollector->addNodeAfterNode($whereTimeMethodCall, $node);
}
return null;
}
private function matchWhereDateThirdArgValue(MethodCall $methodCall) : ?Expr
{
if (!$this->isObjectType($methodCall->var, new ObjectType('Illuminate\\Database\\Query\\Builder'))) {
return null;
}
if (!$this->isName($methodCall->name, 'whereDate')) {
return null;
}
if (!isset($methodCall->args[2])) {
return null;
}
if (!$methodCall->args[2] instanceof Arg) {
return null;
}
$argValue = $methodCall->args[2]->value;
if (!$this->isObjectType($argValue, new ObjectType('DateTimeInterface'))) {
return null;
}
// nothing to change
if ($this->isCarbonTodayStaticCall($argValue)) {
return null;
}
if (!$methodCall->args[1] instanceof Arg) {
return null;
}
if ($this->valueResolver->isValues($methodCall->args[1]->value, ['>=', '<='])) {
return null;
}
return $argValue;
}
private function changeCompareSignExpr(Arg $arg) : void
{
if (!$arg->value instanceof String_) {
return;
}
$string = $arg->value;
if ($string->value === '<') {
$string->value = '<=';
}
if ($string->value === '>') {
$string->value = '>=';
}
}
private function createWhereTimeMethodCall(MethodCall $methodCall, Variable $dateTimeVariable) : MethodCall
{
$whereTimeArgs = [$methodCall->args[0], $methodCall->args[1], new Arg($dateTimeVariable)];
return new MethodCall($methodCall->var, 'whereTime', $whereTimeArgs);
}
private function isCarbonTodayStaticCall(Expr $expr) : bool
{
if (!$expr instanceof StaticCall) {
return \false;
}
$carbonObjectType = new ObjectType('Carbon\\Carbon');
$callerType = $this->nodeTypeResolver->getType($expr->class);
if (!$carbonObjectType->isSuperTypeOf($callerType)->yes()) {
return \false;
}
return $this->isName($expr->name, 'today');
}
}

View File

@ -1,75 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\VariadicPlaceholder;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use RectorPrefix202210\Webmozart\Assert\Assert;
/**
* @changelog https://laravel.com/docs/7.x/database-testing#creating-models
* @changelog https://laravel.com/docs/8.x/database-testing#applying-states
*
* @see \Rector\Laravel\Tests\Rector\MethodCall\FactoryApplyingStatesRector\FactoryApplyingStatesRectorTest
*/
final class FactoryApplyingStatesRector extends AbstractRector
{
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Call the state methods directly instead of specify the name of state.', [new CodeSample(<<<'CODE_SAMPLE'
$factory->state('delinquent');
$factory->states('premium', 'delinquent');
CODE_SAMPLE
, <<<'CODE_SAMPLE'
$factory->delinquent();
$factory->premium()->delinquent();
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Expr>>
*/
public function getNodeTypes() : array
{
return [MethodCall::class];
}
/**
* @param MethodCall $node
*/
public function refactor(Node $node) : ?Node
{
if (!$this->isNames($node->name, ['state', 'states'])) {
return null;
}
if (!$this->isObjectType($node->var, new ObjectType('Illuminate\\Database\\Eloquent\\FactoryBuilder'))) {
return null;
}
$var = $node->var;
$states = $this->getStatesFromArgs($node->args);
Assert::allString($states);
foreach ($states as $state) {
$var = $this->nodeFactory->createMethodCall($var, $state);
}
return $var;
}
/**
* @param array<Arg|VariadicPlaceholder> $args
* @return mixed[]
*/
private function getStatesFromArgs(array $args) : array
{
if (\count($args) === 1 && isset($args[0]) && $args[0] instanceof Arg) {
return (array) $this->valueResolver->getValue($args[0]->value);
}
return \array_map(function ($arg) {
return $arg instanceof Arg ? $this->valueResolver->getValue($arg->value) : null;
}, $args);
}
}

View File

@ -1,65 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Scalar\String_;
use Rector\Core\Rector\AbstractRector;
use Rector\Laravel\NodeAnalyzer\LumenRouteRegisteringMethodAnalyzer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Laravel\Tests\Rector\MethodCall\LumenRoutesStringActionToUsesArrayRector\LumenRoutesStringActionToUsesArrayRectorTest
*/
final class LumenRoutesStringActionToUsesArrayRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\Laravel\NodeAnalyzer\LumenRouteRegisteringMethodAnalyzer
*/
private $lumenRouteRegisteringMethodAnalyzer;
public function __construct(LumenRouteRegisteringMethodAnalyzer $lumenRouteRegisteringMethodAnalyzer)
{
$this->lumenRouteRegisteringMethodAnalyzer = $lumenRouteRegisteringMethodAnalyzer;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Changes action in rule definitions from string to array notation.', [new CodeSample(<<<'CODE_SAMPLE'
$router->get('/user', 'UserController@get');
CODE_SAMPLE
, <<<'CODE_SAMPLE'
$router->get('/user', ['uses => 'UserController@get']);
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [MethodCall::class];
}
public function refactor(Node $node) : ?Node
{
if (!$node instanceof MethodCall) {
return null;
}
if (!$this->lumenRouteRegisteringMethodAnalyzer->isLumenRoutingClass($node)) {
return null;
}
if (!$this->lumenRouteRegisteringMethodAnalyzer->isRoutesRegisterRoute($node->name)) {
return null;
}
$string = $node->getArgs()[1]->value;
if (!$string instanceof String_) {
return null;
}
$node->args[1] = new Arg(new Array_([new ArrayItem($string, new String_('uses'))]));
return $node;
}
}

View File

@ -1,131 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Scalar\String_;
use Rector\Core\NodeManipulator\ArrayManipulator;
use Rector\Core\Rector\AbstractRector;
use Rector\Laravel\NodeAnalyzer\LumenRouteRegisteringMethodAnalyzer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Laravel\Tests\Rector\MethodCall\LumenRoutesStringMiddlewareToArrayRector\LumenRoutesStringMiddlewareToArrayRectorTest
*/
final class LumenRoutesStringMiddlewareToArrayRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\Core\NodeManipulator\ArrayManipulator
*/
private $arrayManipulator;
/**
* @readonly
* @var \Rector\Laravel\NodeAnalyzer\LumenRouteRegisteringMethodAnalyzer
*/
private $lumenRouteRegisteringMethodAnalyzer;
public function __construct(ArrayManipulator $arrayManipulator, LumenRouteRegisteringMethodAnalyzer $lumenRouteRegisteringMethodAnalyzer)
{
$this->arrayManipulator = $arrayManipulator;
$this->lumenRouteRegisteringMethodAnalyzer = $lumenRouteRegisteringMethodAnalyzer;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Changes middlewares from rule definitions from string to array notation.', [new CodeSample(<<<'CODE_SAMPLE'
$router->get('/user', ['middleware => 'test']);
$router->post('/user', ['middleware => 'test|authentication']);
CODE_SAMPLE
, <<<'CODE_SAMPLE'
$router->get('/user', ['middleware => ['test']]);
$router->post('/user', ['middleware => ['test', 'authentication']]);
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [MethodCall::class];
}
public function refactor(Node $node) : ?Node
{
if (!$node instanceof MethodCall) {
return null;
}
if (!$this->lumenRouteRegisteringMethodAnalyzer->isLumenRoutingClass($node)) {
return null;
}
$array = $this->getRouterMethodAttributes($node);
if (!$array instanceof Array_) {
return null;
}
$arrayItem = $this->findItemInArrayByKey($array, 'middleware');
if (!$arrayItem instanceof ArrayItem) {
return null;
}
$middlewareValue = $arrayItem->value;
if (!$middlewareValue instanceof String_) {
return null;
}
/** @var string $middlewareString */
$middlewareString = $middlewareValue->value;
$splitMiddleware = \explode('|', $middlewareString);
$newMiddlewareArray = new Array_([]);
foreach ($splitMiddleware as $singleSplitMiddleware) {
$newMiddlewareArray->items[] = new ArrayItem(new String_($singleSplitMiddleware));
}
$this->replaceItemInArrayByKey($array, new ArrayItem($newMiddlewareArray, new String_('middleware')), 'middleware');
return $node;
}
private function getRouterMethodAttributes(MethodCall $methodCall) : ?Array_
{
$attributes = null;
if ($this->lumenRouteRegisteringMethodAnalyzer->isRoutesRegisterGroup($methodCall->name)) {
$attributes = $methodCall->getArgs()[0]->value;
}
if ($this->lumenRouteRegisteringMethodAnalyzer->isRoutesRegisterRoute($methodCall->name)) {
$attributes = $methodCall->getArgs()[1]->value;
}
if (!$attributes instanceof Array_) {
return null;
}
return $attributes;
}
private function findItemInArrayByKey(Array_ $array, string $keyName) : ?ArrayItem
{
foreach ($array->items as $i => $item) {
if ($item === null) {
continue;
}
if (!$this->arrayManipulator->hasKeyName($item, $keyName)) {
continue;
}
$foundArrayItem = $array->items[$i];
if (!$foundArrayItem instanceof ArrayItem) {
continue;
}
return $item;
}
return null;
}
private function replaceItemInArrayByKey(Array_ $array, ArrayItem $arrayItem, string $keyName) : void
{
foreach ($array->items as $i => $item) {
if ($item === null) {
continue;
}
if (!$this->arrayManipulator->hasKeyName($item, $keyName)) {
continue;
}
if (!$array->items[$i] instanceof ArrayItem) {
continue;
}
$array->items[$i] = $arrayItem;
}
}
}

View File

@ -1,116 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Name;
use Rector\Core\Rector\AbstractRector;
use Rector\Defluent\NodeAnalyzer\FluentChainMethodCallNodeAnalyzer;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Laravel\Tests\Rector\MethodCall\RedirectBackToBackHelperRector\RedirectBackToBackHelperRectorTest
*/
final class RedirectBackToBackHelperRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\Defluent\NodeAnalyzer\FluentChainMethodCallNodeAnalyzer
*/
private $fluentChainMethodCallNodeAnalyzer;
public function __construct(FluentChainMethodCallNodeAnalyzer $fluentChainMethodCallNodeAnalyzer)
{
$this->fluentChainMethodCallNodeAnalyzer = $fluentChainMethodCallNodeAnalyzer;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Replace `redirect()->back()` and `Redirect::back()` with `back()`', [new CodeSample(<<<'CODE_SAMPLE'
use Illuminate\Support\Facades\Redirect;
class MyController
{
public function store()
{
return redirect()->back()->with('error', 'Incorrect Details.')
}
public function update()
{
return Redirect::back()->with('error', 'Incorrect Details.')
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
use Illuminate\Support\Facades\Redirect;
class MyController
{
public function store()
{
return back()->with('error', 'Incorrect Details.')
}
public function update()
{
return back()->with('error', 'Incorrect Details.')
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [MethodCall::class, StaticCall::class];
}
/**
* @param MethodCall|StaticCall $node
*/
public function refactor(Node $node) : ?Node
{
if ($node instanceof MethodCall) {
return $this->updateRedirectHelperCall($node);
}
return $this->updateRedirectStaticCall($node);
}
private function updateRedirectHelperCall(MethodCall $methodCall) : ?MethodCall
{
if (!$this->isName($methodCall->name, 'back')) {
return null;
}
$rootExpr = $this->fluentChainMethodCallNodeAnalyzer->resolveRootExpr($methodCall);
$parentNode = $rootExpr->getAttribute(AttributeKey::PARENT_NODE);
if (!$parentNode instanceof MethodCall) {
return null;
}
if (!$parentNode->var instanceof FuncCall) {
return null;
}
if ($parentNode->var->getArgs() !== []) {
return null;
}
if (!$this->isName($parentNode->var->name, 'redirect')) {
return null;
}
$this->removeNode($methodCall);
$parentNode->var->name = new Name('back');
return $parentNode;
}
private function updateRedirectStaticCall(StaticCall $staticCall) : ?FuncCall
{
if (!$this->isName($staticCall->class, 'Illuminate\\Support\\Facades\\Redirect')) {
return null;
}
if (!$this->isName($staticCall->name, 'back')) {
return null;
}
return new FuncCall(new Name('back'), $staticCall->args);
}
}

View File

@ -1,117 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Name;
use Rector\Core\Rector\AbstractRector;
use Rector\Defluent\NodeAnalyzer\FluentChainMethodCallNodeAnalyzer;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Laravel\Tests\Rector\MethodCall\RedirectRouteToToRouteHelperRector\RedirectRouteToToRouteHelperRectorTest
*/
final class RedirectRouteToToRouteHelperRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\Defluent\NodeAnalyzer\FluentChainMethodCallNodeAnalyzer
*/
private $fluentChainMethodCallNodeAnalyzer;
public function __construct(FluentChainMethodCallNodeAnalyzer $fluentChainMethodCallNodeAnalyzer)
{
$this->fluentChainMethodCallNodeAnalyzer = $fluentChainMethodCallNodeAnalyzer;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Replace `redirect()->route("home")` and `Redirect::route("home")` with `to_route("home")`', [new CodeSample(<<<'CODE_SAMPLE'
use Illuminate\Support\Facades\Redirect;
class MyController
{
public function store()
{
return redirect()->route('home')->with('error', 'Incorrect Details.')
}
public function update()
{
return Redirect::route('home')->with('error', 'Incorrect Details.')
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
use Illuminate\Support\Facades\Redirect;
class MyController
{
public function store()
{
return to_route('home')->with('error', 'Incorrect Details.')
}
public function update()
{
return to_route('home')->with('error', 'Incorrect Details.')
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [MethodCall::class, StaticCall::class];
}
/**
* @param MethodCall|StaticCall $node
*/
public function refactor(Node $node) : ?Node
{
if ($node instanceof MethodCall) {
return $this->updateRedirectHelperCall($node);
}
return $this->updateRedirectStaticCall($node);
}
private function updateRedirectHelperCall(MethodCall $methodCall) : ?MethodCall
{
if (!$this->isName($methodCall->name, 'route')) {
return null;
}
$rootExpr = $this->fluentChainMethodCallNodeAnalyzer->resolveRootExpr($methodCall);
$parentNode = $rootExpr->getAttribute(AttributeKey::PARENT_NODE);
if (!$parentNode instanceof MethodCall) {
return null;
}
if (!$parentNode->var instanceof FuncCall) {
return null;
}
if ($parentNode->var->getArgs() !== []) {
return null;
}
if (!$this->isName($parentNode->var->name, 'redirect')) {
return null;
}
$this->removeNode($methodCall);
$parentNode->var->name = new Name('to_route');
$parentNode->var->args = $methodCall->getArgs();
return $parentNode;
}
private function updateRedirectStaticCall(StaticCall $staticCall) : ?FuncCall
{
if (!$this->isName($staticCall->class, 'Illuminate\\Support\\Facades\\Redirect')) {
return null;
}
if (!$this->isName($staticCall->name, 'route')) {
return null;
}
return new FuncCall(new Name('to_route'), $staticCall->args);
}
}

View File

@ -1,209 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\Namespace_;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Namespace_;
use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace;
use Rector\Core\Rector\AbstractRector;
use Rector\Laravel\NodeFactory\ModelFactoryNodeFactory;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://laravel.com/docs/7.x/database-testing#writing-factories
* @changelog https://laravel.com/docs/8.x/database-testing#defining-model-factories
*
* @see \Rector\Laravel\Tests\Rector\Namespace_\FactoryDefinitionRector\FactoryDefinitionRectorTest
*/
final class FactoryDefinitionRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\Laravel\NodeFactory\ModelFactoryNodeFactory
*/
private $modelFactoryNodeFactory;
public function __construct(ModelFactoryNodeFactory $modelFactoryNodeFactory)
{
$this->modelFactoryNodeFactory = $modelFactoryNodeFactory;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Upgrade legacy factories to support classes.', [new CodeSample(<<<'CODE_SAMPLE'
use Faker\Generator as Faker;
$factory->define(App\User::class, function (Faker $faker) {
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
];
});
CODE_SAMPLE
, <<<'CODE_SAMPLE'
use Faker\Generator as Faker;
class UserFactory extends \Illuminate\Database\Eloquent\Factories\Factory
{
protected $model = App\User::class;
public function definition()
{
return [
'name' => $this->faker->name,
'email' => $this->faker->unique()->safeEmail,
];
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [Namespace_::class, FileWithoutNamespace::class];
}
/**
* @param Namespace_|FileWithoutNamespace $node
*/
public function refactor(Node $node) : ?Node
{
$factories = [];
foreach ($node->stmts as $key => $stmt) {
if (!$stmt instanceof Expression) {
continue;
}
// do not refactor if factory variable changed
if ($this->isReAssignFactoryVariable($stmt->expr)) {
return null;
}
if (!$stmt->expr instanceof MethodCall) {
continue;
}
if ($this->shouldSkipExpression($stmt->expr)) {
continue;
}
/** @var Arg $firstArg */
$firstArg = $stmt->expr->args[0];
$name = $this->getNameFromClassConstFetch($firstArg->value);
if (!$name instanceof Name) {
continue;
}
if (!isset($factories[$name->toString()])) {
$factories[$name->toString()] = $this->createFactory($name->getLast(), $firstArg->value);
}
$this->processFactoryConfiguration($factories[$name->toString()], $stmt->expr);
unset($node->stmts[$key]);
}
if ($factories === []) {
return null;
}
$node->stmts = \array_merge($node->stmts, $factories);
return $node;
}
private function isReAssignFactoryVariable(Expr $expr) : bool
{
if (!$expr instanceof Assign) {
return \false;
}
return $this->isName($expr->var, 'factory');
}
private function shouldSkipExpression(MethodCall $methodCall) : bool
{
if (!isset($methodCall->args[0])) {
return \true;
}
if (!$methodCall->args[0] instanceof Arg) {
return \true;
}
if (!$methodCall->args[0]->value instanceof ClassConstFetch) {
return \true;
}
return !$this->isNames($methodCall->name, ['define', 'state', 'afterMaking', 'afterCreating']);
}
private function getNameFromClassConstFetch(Expr $expr) : ?Name
{
if (!$expr instanceof ClassConstFetch) {
return null;
}
if ($expr->class instanceof Expr) {
return null;
}
return $expr->class;
}
private function createFactory(string $name, Expr $expr) : Class_
{
return $this->modelFactoryNodeFactory->createEmptyFactory($name, $expr);
}
private function processFactoryConfiguration(Class_ $class, MethodCall $methodCall) : void
{
if (!$this->isName($methodCall->var, 'factory')) {
return;
}
if ($this->isName($methodCall->name, 'define')) {
$this->addDefinition($class, $methodCall);
}
if ($this->isName($methodCall->name, 'state')) {
$this->addState($class, $methodCall);
}
if (!$this->isNames($methodCall->name, ['afterMaking', 'afterCreating'])) {
return;
}
$name = $this->getName($methodCall->name);
if ($name === null) {
return;
}
$this->appendAfterCalling($class, $methodCall, $name);
}
private function addDefinition(Class_ $class, MethodCall $methodCall) : void
{
if (!isset($methodCall->args[1])) {
return;
}
if (!$methodCall->args[1] instanceof Arg) {
return;
}
$callback = $methodCall->args[1]->value;
if (!$callback instanceof Closure) {
return;
}
$class->stmts[] = $this->modelFactoryNodeFactory->createDefinition($callback);
}
private function addState(Class_ $class, MethodCall $methodCall) : void
{
$classMethod = $this->modelFactoryNodeFactory->createStateMethod($methodCall);
if (!$classMethod instanceof ClassMethod) {
return;
}
$class->stmts[] = $classMethod;
}
private function appendAfterCalling(Class_ $class, MethodCall $methodCall, string $name) : void
{
if (!isset($methodCall->args[1])) {
return;
}
if (!$methodCall->args[1] instanceof Arg) {
return;
}
$closure = $methodCall->args[1]->value;
if (!$closure instanceof Closure) {
return;
}
$method = $class->getMethod('configure');
if (!$method instanceof ClassMethod) {
$method = $this->modelFactoryNodeFactory->createEmptyConfigure();
$class->stmts[] = $method;
}
$this->modelFactoryNodeFactory->appendConfigure($method, $name, $closure);
}
}

View File

@ -1,89 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\New_;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\String_;
use Rector\Core\Rector\AbstractRector;
use Rector\PostRector\Collector\NodesToAddCollector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://github.com/laravel/framework/commit/f5d8c0a673aa9fc6cd94aa4858a0027fe550a22e#diff-162a49c054acde9f386ec735607b95bc4a1c0c765a6f46da8de9a8a4ef5199d3
* @changelog https://github.com/laravel/framework/pull/25261
*
* @see \Rector\Laravel\Tests\Rector\New_\AddGuardToLoginEventRector\AddGuardToLoginEventRectorTest
*/
final class AddGuardToLoginEventRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\PostRector\Collector\NodesToAddCollector
*/
private $nodesToAddCollector;
public function __construct(NodesToAddCollector $nodesToAddCollector)
{
$this->nodesToAddCollector = $nodesToAddCollector;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Add new $guard argument to Illuminate\\Auth\\Events\\Login', [new CodeSample(<<<'CODE_SAMPLE'
use Illuminate\Auth\Events\Login;
final class SomeClass
{
public function run(): void
{
$loginEvent = new Login('user', false);
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
use Illuminate\Auth\Events\Login;
final class SomeClass
{
public function run(): void
{
$guard = config('auth.defaults.guard');
$loginEvent = new Login($guard, 'user', false);
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [New_::class];
}
/**
* @param New_ $node
*/
public function refactor(Node $node) : ?Node
{
if (!$this->isName($node->class, 'Illuminate\\Auth\\Events\\Login')) {
return null;
}
if (\count($node->args) === 3) {
return null;
}
$guardVariable = new Variable('guard');
$assign = $this->createGuardAssign($guardVariable);
$this->nodesToAddCollector->addNodeBeforeNode($assign, $node);
$node->args = \array_merge([new Arg($guardVariable)], $node->args);
return $node;
}
private function createGuardAssign(Variable $guardVariable) : Assign
{
$string = new String_('auth.defaults.guard');
return new Assign($guardVariable, $this->nodeFactory->createFuncCall('config', [$string]));
}
}

View File

@ -1,137 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\PropertyFetch;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\NullsafeMethodCall;
use PhpParser\Node\Expr\NullsafePropertyFetch;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Scalar;
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Util\MultiInstanceofChecker;
use Rector\Core\ValueObject\PhpVersion;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use RectorPrefix202210\Webmozart\Assert\Assert;
/**
* @changelog https://github.com/laravel/laravel/pull/5670
* @changelog https://github.com/laravel/framework/pull/38868
* @changelog https://wiki.php.net/rfc/nullsafe_operator
*
* @see \Rector\Laravel\Tests\Rector\PropertyFetch\OptionalToNullsafeOperatorRector\OptionalToNullsafeOperatorRectorTest
*/
final class OptionalToNullsafeOperatorRector extends AbstractRector implements MinPhpVersionInterface, AllowEmptyConfigurableRectorInterface
{
/**
* @var string
*/
public const EXCLUDE_METHODS = 'exclude_methods';
/**
* @var array<class-string<Expr>>
*/
private const SKIP_VALUE_TYPES = [ConstFetch::class, Scalar::class, Array_::class, ClassConstFetch::class];
/**
* @var string[]
*/
private $excludeMethods = [];
/**
* @readonly
* @var \Rector\Core\Util\MultiInstanceofChecker
*/
private $multiInstanceofChecker;
/**
* @readonly
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(MultiInstanceofChecker $multiInstanceofChecker, ArgsAnalyzer $argsAnalyzer)
{
$this->multiInstanceofChecker = $multiInstanceofChecker;
$this->argsAnalyzer = $argsAnalyzer;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Convert simple calls to optional helper to use the nullsafe operator', [new ConfiguredCodeSample(<<<'CODE_SAMPLE'
optional($user)->getKey();
optional($user)->id;
// macro methods
optional($user)->present()->getKey();
CODE_SAMPLE
, <<<'CODE_SAMPLE'
$user?->getKey();
$user?->id;
// macro methods
optional($user)->present()->getKey();
CODE_SAMPLE
, [self::EXCLUDE_METHODS => ['present']])]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [PropertyFetch::class, MethodCall::class];
}
/**
* @param MethodCall|PropertyFetch $node
*/
public function refactor(Node $node) : ?Node
{
if (!$node->var instanceof FuncCall) {
return null;
}
if (!$this->isName($node->var->name, 'optional')) {
return null;
}
// exclude macro methods
if ($node instanceof MethodCall && $this->isNames($node->name, $this->excludeMethods)) {
return null;
}
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($node->var->args, 0)) {
return null;
}
// skip if the second arg exists and not null
if ($this->hasCallback($node->var)) {
return null;
}
/** @var Arg $firstArg */
$firstArg = $node->var->args[0];
// skip if the first arg cannot be used as variable directly
if ($this->multiInstanceofChecker->isInstanceOf($firstArg->value, self::SKIP_VALUE_TYPES)) {
return null;
}
if ($node instanceof PropertyFetch) {
return new NullsafePropertyFetch($firstArg->value, $node->name);
}
return new NullsafeMethodCall($firstArg->value, $node->name, $node->args);
}
public function provideMinPhpVersion() : int
{
return PhpVersion::PHP_80;
}
/**
* @param mixed[] $configuration
*/
public function configure(array $configuration) : void
{
$excludeMethods = $configuration[self::EXCLUDE_METHODS] ?? $configuration;
Assert::isArray($excludeMethods);
Assert::allString($excludeMethods);
$this->excludeMethods = $excludeMethods;
}
private function hasCallback(FuncCall $funcCall) : bool
{
return isset($funcCall->args[1]) && $funcCall->args[1] instanceof Arg && !$this->valueResolver->isNull($funcCall->args[1]->value);
}
}

View File

@ -1,114 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\StaticCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\Mul;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Scalar\LNumber;
use Rector\Core\Rector\AbstractRector;
use Rector\Laravel\ValueObject\TypeToTimeMethodAndPosition;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://github.com/laravel/framework/pull/27276
* @changelog https://laravel.com/docs/5.8/upgrade#cache-ttl-in-seconds
*
* @see \Rector\Laravel\Tests\Rector\StaticCall\MinutesToSecondsInCacheRector\MinutesToSecondsInCacheRectorTest
*/
final class MinutesToSecondsInCacheRector extends AbstractRector
{
/**
* @var string
*/
private const PUT = 'put';
/**
* @var string
*/
private const ADD = 'add';
/**
* @var string
*/
private const REMEMBER = 'remember';
/**
* @var TypeToTimeMethodAndPosition[]
*/
private $typeToTimeMethodsAndPositions = [];
public function __construct()
{
$this->typeToTimeMethodsAndPositions = [new TypeToTimeMethodAndPosition('Illuminate\\Support\\Facades\\Cache', self::PUT, 2), new TypeToTimeMethodAndPosition('Illuminate\\Contracts\\Cache\\Repository', self::PUT, 2), new TypeToTimeMethodAndPosition('Illuminate\\Contracts\\Cache\\Store', self::PUT, 2), new TypeToTimeMethodAndPosition('Illuminate\\Contracts\\Cache\\Repository', self::ADD, 2), new TypeToTimeMethodAndPosition('Illuminate\\Contracts\\Cache\\Store', self::ADD, 2), new TypeToTimeMethodAndPosition('Illuminate\\Support\\Facades\\Cache', self::ADD, 2), new TypeToTimeMethodAndPosition('Illuminate\\Contracts\\Cache\\Repository', self::REMEMBER, 2), new TypeToTimeMethodAndPosition('Illuminate\\Support\\Facades\\Cache', self::REMEMBER, 2), new TypeToTimeMethodAndPosition('Illuminate\\Contracts\\Cache\\Store', self::REMEMBER, 2), new TypeToTimeMethodAndPosition('Illuminate\\Contracts\\Cache\\Store', 'putMany', 1)];
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Change minutes argument to seconds in Illuminate\\Contracts\\Cache\\Store and Illuminate\\Support\\Facades\\Cache', [new CodeSample(<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
{
Illuminate\Support\Facades\Cache::put('key', 'value', 60);
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
class SomeClass
{
public function run()
{
Illuminate\Support\Facades\Cache::put('key', 'value', 60 * 60);
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [StaticCall::class, MethodCall::class];
}
/**
* @param StaticCall|MethodCall $node
*/
public function refactor(Node $node) : ?Node
{
foreach ($this->typeToTimeMethodsAndPositions as $typeToTimeMethodAndPosition) {
if (!$this->isObjectType($node instanceof MethodCall ? $node->var : $node->class, $typeToTimeMethodAndPosition->getObjectType())) {
continue;
}
if (!$this->isName($node->name, $typeToTimeMethodAndPosition->getMethodName())) {
continue;
}
if (!isset($node->args[$typeToTimeMethodAndPosition->getPosition()])) {
continue;
}
if (!$node->args[$typeToTimeMethodAndPosition->getPosition()] instanceof Arg) {
continue;
}
$argValue = $node->args[$typeToTimeMethodAndPosition->getPosition()]->value;
return $this->processArgumentOnPosition($node, $argValue, $typeToTimeMethodAndPosition->getPosition());
}
return $node;
}
/**
* @param \PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\MethodCall $node
* @return \PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\MethodCall|null
*/
private function processArgumentOnPosition($node, Expr $argExpr, int $argumentPosition)
{
if (!$this->nodeTypeResolver->isNumberType($argExpr)) {
return null;
}
// already multiplied
if ($argExpr instanceof Mul) {
return null;
}
$mul = new Mul($argExpr, new LNumber(60));
$node->args[$argumentPosition] = new Arg($mul);
return $node;
}
}

View File

@ -1,79 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\StaticCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Identifier;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://laravel.com/docs/5.7/upgrade
* @see \Rector\Laravel\Tests\Rector\StaticCall\Redirect301ToPermanentRedirectRector\Redirect301ToPermanentRedirectRectorTest
*/
final class Redirect301ToPermanentRedirectRector extends AbstractRector
{
/**
* @var ObjectType[]
*/
private $routerObjectTypes = [];
public function __construct()
{
$this->routerObjectTypes = [new ObjectType('Illuminate\\Support\\Facades\\Route'), new ObjectType('Illuminate\\Routing\\Route')];
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Change "redirect" call with 301 to "permanentRedirect"', [new CodeSample(<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
{
Illuminate\Routing\Route::redirect('/foo', '/bar', 301);
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
class SomeClass
{
public function run()
{
Illuminate\Routing\Route::permanentRedirect('/foo', '/bar');
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [StaticCall::class];
}
/**
* @param StaticCall $node
*/
public function refactor(Node $node) : ?Node
{
if (!$this->nodeTypeResolver->isObjectTypes($node->class, $this->routerObjectTypes)) {
return null;
}
if (!isset($node->args[2])) {
return null;
}
if (!$node->args[2] instanceof Arg) {
return null;
}
$is301 = $this->valueResolver->isValue($node->args[2]->value, 301);
if (!$is301) {
return null;
}
unset($node->args[2]);
$node->name = new Identifier('permanentRedirect');
return $node;
}
}

View File

@ -1,107 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\StaticCall;
use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\Class_;
use PHPStan\Type\ObjectType;
use Rector\Core\NodeManipulator\ClassMethodManipulator;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://github.com/laravel/framework/pull/27276
* @see \Rector\Laravel\Tests\Rector\StaticCall\RequestStaticValidateToInjectRector\RequestStaticValidateToInjectRectorTest
*/
final class RequestStaticValidateToInjectRector extends AbstractRector
{
/**
* @var ObjectType[]
*/
private $requestObjectTypes = [];
/**
* @readonly
* @var \Rector\Core\NodeManipulator\ClassMethodManipulator
*/
private $classMethodManipulator;
public function __construct(ClassMethodManipulator $classMethodManipulator)
{
$this->classMethodManipulator = $classMethodManipulator;
$this->requestObjectTypes = [new ObjectType('Illuminate\\Http\\Request'), new ObjectType('Request')];
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Change static validate() method to $request->validate()', [new CodeSample(<<<'CODE_SAMPLE'
use Illuminate\Http\Request;
class SomeClass
{
public function store()
{
$validatedData = Request::validate(['some_attribute' => 'required']);
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
use Illuminate\Http\Request;
class SomeClass
{
public function store(\Illuminate\Http\Request $request)
{
$validatedData = $request->validate(['some_attribute' => 'required']);
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [StaticCall::class, FuncCall::class];
}
/**
* @param StaticCall|FuncCall $node
*/
public function refactor(Node $node) : ?Node
{
if ($this->shouldSkip($node)) {
return null;
}
$requestName = $this->classMethodManipulator->addMethodParameterIfMissing($node, new ObjectType('Illuminate\\Http\\Request'), ['request', 'httpRequest']);
$variable = new Variable($requestName);
$methodName = $this->getName($node->name);
if ($methodName === null) {
return null;
}
if ($node instanceof FuncCall) {
if ($node->args === []) {
return $variable;
}
$methodName = 'input';
}
return new MethodCall($variable, new Identifier($methodName), $node->args);
}
/**
* @param \PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\FuncCall $node
*/
private function shouldSkip($node) : bool
{
if ($node instanceof StaticCall) {
return !$this->nodeTypeResolver->isObjectTypes($node->class, $this->requestObjectTypes);
}
$class = $this->betterNodeFinder->findParentType($node, Class_::class);
if (!$class instanceof Class_) {
return \true;
}
return !$this->isName($node, 'request');
}
}

View File

@ -1,184 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Rector\StaticCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Identifier;
use PhpParser\Node\Scalar\String_;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\Php\PhpMethodReflection;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\Laravel\NodeFactory\RouterRegisterNodeAnalyzer;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use RectorPrefix202210\Webmozart\Assert\Assert;
/**
* @changelog https://laravel.com/docs/8.x/upgrade#automatic-controller-namespace-prefixing
*
* @see \Rector\Laravel\Tests\Rector\StaticCall\RouteActionCallableRector\RouteActionCallableRectorTest
*/
final class RouteActionCallableRector extends AbstractRector implements ConfigurableRectorInterface
{
/**
* @var string
*/
public const ROUTES = 'routes';
/**
* @var string
*/
public const NAMESPACE = 'namespace';
/**
* @var string
*/
private const DEFAULT_NAMESPACE = 'App\\Http\\Controllers';
/**
* @var string
*/
private $namespace = self::DEFAULT_NAMESPACE;
/**
* @var array<string, string>
*/
private $routes = [];
/**
* @readonly
* @var \Rector\Core\Reflection\ReflectionResolver
*/
private $reflectionResolver;
/**
* @readonly
* @var \Rector\Laravel\NodeFactory\RouterRegisterNodeAnalyzer
*/
private $routerRegisterNodeAnalyzer;
public function __construct(ReflectionResolver $reflectionResolver, RouterRegisterNodeAnalyzer $routerRegisterNodeAnalyzer)
{
$this->reflectionResolver = $reflectionResolver;
$this->routerRegisterNodeAnalyzer = $routerRegisterNodeAnalyzer;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Use PHP callable syntax instead of string syntax for controller route declarations.', [new ConfiguredCodeSample(<<<'CODE_SAMPLE'
Route::get('/users', 'UserController@index');
CODE_SAMPLE
, <<<'CODE_SAMPLE'
Route::get('/users', [\App\Http\Controllers\UserController::class, 'index']);
CODE_SAMPLE
, [self::NAMESPACE => 'App\\Http\\Controllers'])]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [MethodCall::class, StaticCall::class];
}
/**
* @param Node\Expr\MethodCall|StaticCall $node
*/
public function refactor(Node $node) : ?Node
{
if (!$this->routerRegisterNodeAnalyzer->isRegisterMethodStaticCall($node)) {
return null;
}
$position = $this->getActionPosition($node->name);
if (!isset($node->args[$position])) {
return null;
}
if (!$node->args[$position] instanceof Arg) {
return null;
}
$arg = $node->args[$position];
$argValue = $this->valueResolver->getValue($arg->value);
$segments = $this->resolveControllerFromAction($argValue);
if ($segments === null) {
return null;
}
$scope = $node->getAttribute(AttributeKey::SCOPE);
if (!$scope instanceof Scope) {
return null;
}
$phpMethodReflection = $this->reflectionResolver->resolveMethodReflection($segments[0], $segments[1], $scope);
if (!$phpMethodReflection instanceof PhpMethodReflection) {
return null;
}
$node->args[$position]->value = $this->nodeFactory->createArray([$this->nodeFactory->createClassConstReference($segments[0]), $segments[1]]);
if (\is_array($argValue)) {
return new MethodCall($node, 'name', [new Arg(new String_($argValue['as']))]);
}
return $node;
}
/**
* @param mixed[] $configuration
*/
public function configure(array $configuration) : void
{
$routes = $configuration[self::ROUTES] ?? [];
Assert::isArray($routes);
Assert::allString(\array_keys($routes));
Assert::allString($routes);
$this->routes = $routes;
$namespace = $configuration[self::NAMESPACE] ?? self::DEFAULT_NAMESPACE;
Assert::string($namespace);
$this->namespace = $namespace;
}
/**
* @return array{string, string}|null
* @param mixed $action
*/
private function resolveControllerFromAction($action) : ?array
{
if (!$this->isActionString($action)) {
return null;
}
/** @var string|array<string, string> $action */
$segments = \is_string($action) ? \explode('@', $action) : \explode('@', $action['uses']);
if (\count($segments) !== 2) {
return null;
}
[$controller, $method] = $segments;
$namespace = $this->getNamespace($this->file->getFilePath());
if (\strncmp($controller, '\\', \strlen('\\')) !== 0) {
$controller = $namespace . '\\' . $controller;
}
return [$controller, $method];
}
/**
* @param \PhpParser\Node\Identifier|\PhpParser\Node\Expr $name
*/
private function getActionPosition($name) : int
{
if ($this->routerRegisterNodeAnalyzer->isRegisterFallback($name)) {
return 0;
}
if ($this->routerRegisterNodeAnalyzer->isRegisterMultipleVerbs($name)) {
return 2;
}
return 1;
}
/**
* @param mixed $action
*/
private function isActionString($action) : bool
{
if (!\is_string($action)) {
if (!\is_array($action)) {
return \false;
}
$keys = \array_keys($action);
\sort($keys);
return $keys === ['as', 'uses'];
}
return \strpos($action, '@') !== \false;
}
private function getNamespace(string $filePath) : string
{
return $this->routes[$filePath] ?? $this->namespace;
}
}

View File

@ -1,57 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Set;
use Rector\Set\Contract\SetListInterface;
final class LaravelLevelSetList implements SetListInterface
{
/**
* @var string
*/
public const UP_TO_LARAVEL_51 = __DIR__ . '/../../config/sets/level/up-to-laravel-51.php';
/**
* @var string
*/
public const UP_TO_LARAVEL_52 = __DIR__ . '/../../config/sets/level/up-to-laravel-52.php';
/**
* @var string
*/
public const UP_TO_LARAVEL_53 = __DIR__ . '/../../config/sets/level/up-to-laravel-53.php';
/**
* @var string
*/
public const UP_TO_LARAVEL_54 = __DIR__ . '/../../config/sets/level/up-to-laravel-54.php';
/**
* @var string
*/
public const UP_TO_LARAVEL_55 = __DIR__ . '/../../config/sets/level/up-to-laravel-55.php';
/**
* @var string
*/
public const UP_TO_LARAVEL_56 = __DIR__ . '/../../config/sets/level/up-to-laravel-56.php';
/**
* @var string
*/
public const UP_TO_LARAVEL_57 = __DIR__ . '/../../config/sets/level/up-to-laravel-57.php';
/**
* @var string
*/
public const UP_TO_LARAVEL_58 = __DIR__ . '/../../config/sets/level/up-to-laravel-58.php';
/**
* @var string
*/
public const UP_TO_LARAVEL_60 = __DIR__ . '/../../config/sets/level/up-to-laravel-60.php';
/**
* @var string
*/
public const UP_TO_LARAVEL_70 = __DIR__ . '/../../config/sets/level/up-to-laravel-70.php';
/**
* @var string
*/
public const UP_TO_LARAVEL_80 = __DIR__ . '/../../config/sets/level/up-to-laravel-80.php';
/**
* @var string
*/
public const UP_TO_LARAVEL_90 = __DIR__ . '/../../config/sets/level/up-to-laravel-90.php';
}

View File

@ -1,81 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\Set;
use Rector\Set\Contract\SetListInterface;
final class LaravelSetList implements SetListInterface
{
/**
* @var string
*/
public const ARRAY_STR_FUNCTIONS_TO_STATIC_CALL = __DIR__ . '/../../config/sets/laravel-array-str-functions-to-static-call.php';
/**
* @var string
*/
public const LARAVEL_50 = __DIR__ . '/../../config/sets/laravel50.php';
/**
* @var string
*/
public const LARAVEL_51 = __DIR__ . '/../../config/sets/laravel51.php';
/**
* @var string
*/
public const LARAVEL_52 = __DIR__ . '/../../config/sets/laravel52.php';
/**
* @var string
*/
public const LARAVEL_53 = __DIR__ . '/../../config/sets/laravel53.php';
/**
* @var string
*/
public const LARAVEL_54 = __DIR__ . '/../../config/sets/laravel54.php';
/**
* @var string
*/
public const LARAVEL_55 = __DIR__ . '/../../config/sets/laravel55.php';
/**
* @var string
*/
public const LARAVEL_56 = __DIR__ . '/../../config/sets/laravel56.php';
/**
* @var string
*/
public const LARAVEL_57 = __DIR__ . '/../../config/sets/laravel57.php';
/**
* @var string
*/
public const LARAVEL_58 = __DIR__ . '/../../config/sets/laravel58.php';
/**
* @var string
*/
public const LARAVEL_60 = __DIR__ . '/../../config/sets/laravel60.php';
/**
* @var string
*/
public const LARAVEL_70 = __DIR__ . '/../../config/sets/laravel70.php';
/**
* @var string
*/
public const LARAVEL_80 = __DIR__ . '/../../config/sets/laravel80.php';
/**
* @var string
*/
public const LARAVEL_90 = __DIR__ . '/../../config/sets/laravel90.php';
/**
* @var string
*/
public const LARAVEL_STATIC_TO_INJECTION = __DIR__ . '/../../config/sets/laravel-static-to-injection.php';
/**
* @var string
*/
public const LARAVEL_CODE_QUALITY = __DIR__ . '/../../config/sets/laravel-code-quality.php';
/**
* @var string
*/
public const LARAVEL_ARRAY_STR_FUNCTION_TO_STATIC_CALL = __DIR__ . '/../../config/sets/laravel-array-str-functions-to-static-call.php';
/**
* @var string
*/
public const LARAVEL_LEGACY_FACTORIES_TO_CLASSES = __DIR__ . '/../../config/sets/laravel-legacy-factories-to-classes.php';
}

View File

@ -1,58 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\ValueObject;
use PHPStan\Type\ObjectType;
final class AddArgumentDefaultValue
{
/**
* @readonly
* @var string
*/
private $class;
/**
* @readonly
* @var string
*/
private $method;
/**
* @readonly
* @var int
*/
private $position;
/**
* @readonly
* @var mixed
*/
private $defaultValue;
/**
* @param mixed $defaultValue
*/
public function __construct(string $class, string $method, int $position, $defaultValue)
{
$this->class = $class;
$this->method = $method;
$this->position = $position;
$this->defaultValue = $defaultValue;
}
public function getObjectType() : ObjectType
{
return new ObjectType($this->class);
}
public function getMethod() : string
{
return $this->method;
}
public function getPosition() : int
{
return $this->position;
}
/**
* @return mixed
*/
public function getDefaultValue()
{
return $this->defaultValue;
}
}

View File

@ -1,41 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\ValueObject;
final class ServiceNameTypeAndVariableName
{
/**
* @readonly
* @var string
*/
private $serviceName;
/**
* @readonly
* @var string
*/
private $type;
/**
* @readonly
* @var string
*/
private $variableName;
public function __construct(string $serviceName, string $type, string $variableName)
{
$this->serviceName = $serviceName;
$this->type = $type;
$this->variableName = $variableName;
}
public function getServiceName() : string
{
return $this->serviceName;
}
public function getType() : string
{
return $this->type;
}
public function getVariableName() : string
{
return $this->variableName;
}
}

View File

@ -1,42 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Laravel\ValueObject;
use PHPStan\Type\ObjectType;
final class TypeToTimeMethodAndPosition
{
/**
* @readonly
* @var string
*/
private $type;
/**
* @readonly
* @var string
*/
private $methodName;
/**
* @readonly
* @var int
*/
private $position;
public function __construct(string $type, string $methodName, int $position)
{
$this->type = $type;
$this->methodName = $methodName;
$this->position = $position;
}
public function getObjectType() : ObjectType
{
return new ObjectType($this->type);
}
public function getMethodName() : string
{
return $this->methodName;
}
public function getPosition() : int
{
return $this->position;
}
}