[Laravel] Decouple to own package (#5904)

This commit is contained in:
Tomas Votruba 2021-03-19 02:09:51 +01:00 committed by GitHub
parent 47a3c7fe12
commit 3aa1f86778
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
76 changed files with 51 additions and 3809 deletions

View File

@ -43,6 +43,7 @@
"phpstan/phpstan-phpunit": "^0.12.18",
"rector/rector-symfony": "dev-main",
"rector/rector-nette": "dev-main",
"rector/rector-laravel": "dev-main",
"sebastian/diff": "^4.0.4",
"symfony/console": "^4.4.8|^5.1",
"symfony/dependency-injection": "^5.1",

View File

@ -14,15 +14,16 @@ return static function (ContainerConfigurator $containerConfigurator): void {
// rector root
$containerConfigurator->import(__DIR__ . '/../vendor/rector/rector-symfony/config/config.php', null, 'not_found');
$containerConfigurator->import(__DIR__ . '/../vendor/rector/rector-nette/config/config.php', null, 'not_found');
$containerConfigurator->import(__DIR__ . '/../vendor/rector/rector-laravel/config/config.php', null, 'not_found');
// rector sub-package
$containerConfigurator->import(__DIR__ . '/../../rector-symfony/config/config.php', null, 'not_found');
$containerConfigurator->import(__DIR__ . '/../../rector-nette/config/config.php', null, 'not_found');
$containerConfigurator->import(__DIR__ . '/../../rector-laravel/config/config.php', null, 'not_found');
// require only in dev
$containerConfigurator->import(__DIR__ . '/../utils/compiler/config/config.php', null, 'not_found');
// to override extension-loaded config
$parameters = $containerConfigurator->parameters();
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, getcwd() . '/phpstan-for-rector.neon');
};

View File

@ -9,7 +9,6 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigura
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
// paths and extensions
$parameters->set(Option::PATHS, []);
$parameters->set(Option::FILE_EXTENSIONS, ['php']);

View File

@ -1,63 +0,0 @@
<?php
declare(strict_types=1);
use Rector\Transform\Rector\FuncCall\FuncCallToStaticCallRector;
use Rector\Transform\ValueObject\FuncCallToStaticCall;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
// @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 (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(FuncCallToStaticCallRector::class)
->call('configure', [[
FuncCallToStaticCallRector::FUNC_CALLS_TO_STATIC_CALLS => ValueObjectInliner::inline([
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,12 +0,0 @@
<?php
declare(strict_types=1);
use Rector\Laravel\Rector\Assign\CallOnAppArrayAccessToStandaloneAssignRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(CallOnAppArrayAccessToStandaloneAssignRector::class);
};

View File

@ -1,279 +0,0 @@
<?php
declare(strict_types=1);
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;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
/**
* @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 (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(__DIR__ . '/laravel-array-str-functions-to-static-call.php');
$services = $containerConfigurator->services();
$services->set(StaticCallToMethodCallRector::class)
->call('configure', [[
StaticCallToMethodCallRector::STATIC_CALLS_TO_METHOD_CALLS => ValueObjectInliner::inline([
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', '*'),
]),
]]);
$services->set(RequestStaticValidateToInjectRector::class);
// @see https://github.com/laravel/framework/blob/78828bc779e410e03cc6465f002b834eadf160d2/src/Illuminate/Foundation/helpers.php#L959
// @see https://gist.github.com/barryvdh/bb6ffc5d11e0a75dba67
$services->set(ArgumentFuncCallToMethodCallRector::class)
->call('configure', [[
ArgumentFuncCallToMethodCallRector::FUNCTIONS_TO_METHOD_CALLS => ValueObjectInliner::inline([
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', 'back'),
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'),
]),
ArgumentFuncCallToMethodCallRector::ARRAY_FUNCTIONS_TO_METHOD_CALLS => ValueObjectInliner::inline([
new ArrayFuncCallToMethodCall('config', 'Illuminate\Contracts\Config\Repository', 'set', 'get'),
new ArrayFuncCallToMethodCall('session', 'Illuminate\Session\SessionManager', 'put', 'get'),
]),
]]);
$services->set(FuncCallToNewRector::class)
->call('configure', [[
FuncCallToNewRector::FUNCTIONS_TO_NEWS => [
'collect' => 'Illuminate\Support\Collection',
],
]]);
$services->set(HelperFuncCallToFacadeClassRector::class);
$services->set(RenameClassRector::class)
->call('configure', [[
RenameClassRector::OLD_TO_NEW_CLASSES => [
'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,36 +0,0 @@
<?php
declare(strict_types=1);
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
# see: https://laravel.com/docs/5.0/upgrade
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
# https://stackoverflow.com/a/24949656/1348344
$services->set(RenameClassRector::class)
->call('configure', [[
RenameClassRector::OLD_TO_NEW_CLASSES => [
'Illuminate\Cache\CacheManager' => 'Illuminate\Contracts\Cache\Repository',
'Illuminate\Database\Eloquent\SoftDeletingTrait' => 'Illuminate\Database\Eloquent\SoftDeletes',
],
]]);
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::METHOD_CALL_RENAMES => ValueObjectInliner::inline([
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,18 +0,0 @@
<?php
declare(strict_types=1);
use Rector\Renaming\Rector\Name\RenameClassRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
# see: https://laravel.com/docs/5.1/upgrade
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(RenameClassRector::class)
->call('configure', [[
RenameClassRector::OLD_TO_NEW_CLASSES => [
'Illuminate\Validation\Validator' => 'Illuminate\Contracts\Validation\Validator',
],
]]);
};

View File

@ -1,56 +0,0 @@
<?php
declare(strict_types=1);
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Transform\Rector\String_\StringToClassConstantRector;
use Rector\Transform\ValueObject\StringToClassConstant;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
# see: https://laravel.com/docs/5.2/upgrade
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(RenameClassRector::class)
->call('configure', [[
RenameClassRector::OLD_TO_NEW_CLASSES => [
'Illuminate\Auth\Access\UnauthorizedException' => 'Illuminate\Auth\Access\AuthorizationException',
'Illuminate\Http\Exception\HttpResponseException' => 'Illuminate\Foundation\Validation\ValidationException',
'Illuminate\Foundation\Composer' => 'Illuminate\Support\Composer',
],
]]);
$services->set(StringToClassConstantRector::class)
->call('configure', [[
StringToClassConstantRector::STRINGS_TO_CLASS_CONSTANTS => ValueObjectInliner::inline([
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,18 +0,0 @@
<?php
declare(strict_types=1);
use Rector\Removing\Rector\Class_\RemoveTraitRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(RemoveTraitRector::class)
->call('configure', [[
RemoveTraitRector::TRAITS_TO_REMOVE => [
# see https://laravel.com/docs/5.3/upgrade
'Illuminate\Foundation\Auth\Access\AuthorizesResources',
],
]]);
};

View File

@ -1,70 +0,0 @@
<?php
declare(strict_types=1);
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;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
# see: https://laravel.com/docs/5.4/upgrade
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(StringToClassConstantRector::class)
->call('configure', [[
StringToClassConstantRector::STRINGS_TO_CLASS_CONSTANTS => ValueObjectInliner::inline([
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'),
]),
]]);
$services->set(RenameClassRector::class)
->call('configure', [[
RenameClassRector::OLD_TO_NEW_CLASSES => [
'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',
],
]]);
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::METHOD_CALL_RENAMES => ValueObjectInliner::inline([
new MethodCallRename('Illuminate\Support\Collection', 'every', 'nth'),
new MethodCallRename(
'Illuminate\Database\Eloquent\Relations\BelongsToMany',
'setJoin',
'performJoin'
),
new MethodCallRename(
'Illuminate\Database\Eloquent\Relations\BelongsToMany',
'getRelatedIds',
'allRelatedIds'
),
new MethodCallRename('Illuminate\Routing\Router', 'middleware', 'aliasMiddleware'),
new MethodCallRename('Illuminate\Routing\Route', 'getPath', 'uri'),
new MethodCallRename('Illuminate\Routing\Route', 'getUri', 'uri'),
new MethodCallRename('Illuminate\Routing\Route', 'getMethods', 'methods'),
new MethodCallRename('Illuminate\Routing\Route', 'getParameter', 'parameter'),
new MethodCallRename('Illuminate\Contracts\Session\Session', 'set', 'put'),
new MethodCallRename('Illuminate\Contracts\Session\Session', 'getToken', 'token'),
new MethodCallRename('Illuminate\Support\Facades\Request', 'setSession', 'setLaravelSession'),
new MethodCallRename('Illuminate\Http\Request', 'setSession', 'setLaravelSession'),
new MethodCallRename('Illuminate\Routing\UrlGenerator', 'forceSchema', 'forceScheme'),
new MethodCallRename('Illuminate\Validation\Validator', 'addError', 'addFailure'),
new MethodCallRename('Illuminate\Validation\Validator', 'doReplacements', 'makeReplacements'),
]),
]]);
};

View File

@ -1,39 +0,0 @@
<?php
declare(strict_types=1);
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;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
# see: https://laravel.com/docs/5.5/upgrade
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::METHOD_CALL_RENAMES => ValueObjectInliner::inline([
new MethodCallRename('Illuminate\Console\Command', 'fire', 'handle'),
]),
]]);
$services->set(RenamePropertyRector::class)
->call('configure', [[
RenamePropertyRector::RENAMED_PROPERTIES => ValueObjectInliner::inline([
new RenameProperty('Illuminate\Database\Eloquent\Concerns\HasEvents', 'events', 'dispatchesEvents'),
new RenameProperty('Illuminate\Database\Eloquent\Relations\Pivot', 'parent', 'pivotParent'),
]),
]]);
$services->set(RenameClassRector::class)
->call('configure', [[
RenameClassRector::OLD_TO_NEW_CLASSES => [
'Illuminate\Translation\LoaderInterface' => 'Illuminate\Contracts\Translation\Loader',
],
]]);
};

View File

@ -1,42 +0,0 @@
<?php
declare(strict_types=1);
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;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
# see: https://laravel.com/docs/5.6/upgrade
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::METHOD_CALL_RENAMES => ValueObjectInliner::inline([
new MethodCallRename(
'Illuminate\Validation\ValidatesWhenResolvedTrait',
'validate',
'validateResolved'
),
new MethodCallRename(
'Illuminate\Contracts\Validation\ValidatesWhenResolved',
'validate',
'validateResolved'
),
]),
]]);
$services->set(ChangeMethodVisibilityRector::class)
->call('configure', [[
ChangeMethodVisibilityRector::METHOD_VISIBILITIES => ValueObjectInliner::inline([
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,67 +0,0 @@
<?php
declare(strict_types=1);
use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;
use Rector\Arguments\ValueObject\ArgumentAdder;
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;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
# see: https://laravel.com/docs/5.7/upgrade
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(ChangeMethodVisibilityRector::class)
->call('configure', [[
ChangeMethodVisibilityRector::METHOD_VISIBILITIES => ValueObjectInliner::inline([
new ChangeMethodVisibility('Illuminate\Routing\Router', 'addRoute', Visibility::PUBLIC),
new ChangeMethodVisibility('Illuminate\Contracts\Auth\Access\Gate', 'raw', Visibility::PUBLIC),
]),
]]);
$services->set(ArgumentAdderRector::class)
->call('configure', [[
ArgumentAdderRector::ADDED_ARGUMENTS => ValueObjectInliner::inline([
new ArgumentAdder('Illuminate\Auth\Middleware\Authenticate', 'authenticate', 0, 'request'),
new ArgumentAdder(
'Illuminate\Foundation\Auth\ResetsPasswords',
'sendResetResponse',
0,
'request',
null,
'Illuminate\Http\Illuminate\Http'
),
new ArgumentAdder(
'Illuminate\Foundation\Auth\SendsPasswordResetEmails',
'sendResetLinkResponse',
0,
'request',
null,
'Illuminate\Http\Illuminate\Http'
),
new ArgumentAdder('Illuminate\Database\ConnectionInterface', 'select', 2, 'useReadPdo', true),
new ArgumentAdder('Illuminate\Database\ConnectionInterface', 'selectOne', 2, 'useReadPdo', true),
]),
]]);
$services->set(Redirect301ToPermanentRedirectRector::class);
$services->set(ArgumentRemoverRector::class)
->call('configure', [[
ArgumentRemoverRector::REMOVED_ARGUMENTS => ValueObjectInliner::inline([
new ArgumentRemover('Illuminate\Foundation\Application', 'register', 1, [
'name' => 'options',
]),
]),
]]);
$services->set(AddParentBootToModelClassMethodRector::class);
$services->set(ChangeQueryWhereDateValueWithCarbonRector::class);
$services->set(AddMockConsoleOutputFalseToConsoleTestsRector::class);
$services->set(AddGuardToLoginEventRector::class);
};

View File

@ -1,41 +0,0 @@
<?php
declare(strict_types=1);
use PHPStan\Type\BooleanType;
use Rector\Laravel\Rector\Class_\PropertyDeferToDeferrableProviderToRector;
use Rector\Laravel\Rector\New_\MakeTaggedPassedToParameterIterableTypeRector;
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;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
# 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 (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(__DIR__ . '/laravel-array-str-functions-to-static-call.php');
$services = $containerConfigurator->services();
$services->set(MinutesToSecondsInCacheRector::class);
$services->set(AddReturnTypeDeclarationRector::class)
->call('configure', [[
AddReturnTypeDeclarationRector::METHOD_RETURN_TYPES => ValueObjectInliner::inline([
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()),
]),
]]);
$services->set(RenamePropertyRector::class)
->call('configure', [[
RenamePropertyRector::RENAMED_PROPERTIES => ValueObjectInliner::inline([
new RenameProperty('Illuminate\Routing\UrlGenerator', 'cachedSchema', 'cachedScheme'),
]),
]]);
$services->set(PropertyDeferToDeferrableProviderToRector::class);
$services->set(MakeTaggedPassedToParameterIterableTypeRector::class);
};

View File

@ -1,105 +0,0 @@
<?php
declare(strict_types=1);
use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;
use Rector\Arguments\ValueObject\ArgumentAdder;
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\Transform\Rector\Expression\MethodCallToReturnRector;
use Rector\Transform\ValueObject\MethodCallToReturn;
use Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector;
use Rector\Visibility\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\Visibility\ValueObject\ChangeMethodVisibility;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
# see https://laravel.com/docs/6.x/upgrade
# https://github.com/laravel/docs/pull/5531/files
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(MethodCallToReturnRector::class)
->call('configure', [[
MethodCallToReturnRector::METHOD_CALL_WRAPS => ValueObjectInliner::inline([
new MethodCallToReturn('Illuminate\Auth\Access\HandlesAuthorization', 'deny'),
]),
]]);
# https://github.com/laravel/framework/commit/67a38ba0fa2acfbd1f4af4bf7d462bb4419cc091
$services->set(ParamTypeDeclarationRector::class);
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::METHOD_CALL_RENAMES => ValueObjectInliner::inline([
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'
),
]),
]]);
$configuration = [
# https://github.com/laravel/framework/commit/55785d3514a8149d4858acef40c56a31b6b2ccd1
new RenameStaticMethod(
'Illuminate\Support\Facades\Input',
'get',
'Illuminate\Support\Facades\Request',
'input'
),
];
$services->set(RenameStaticMethodRector::class)
->call('configure', [[
RenameStaticMethodRector::OLD_TO_NEW_METHODS_BY_CLASSES => ValueObjectInliner::inline($configuration),
]]);
$services->set(RenameClassRector::class)
->call('configure', [[
RenameClassRector::OLD_TO_NEW_CLASSES => [
'Illuminate\Support\Facades\Input' => 'Illuminate\Support\Facades\Request',
],
]]);
$services->set(ChangeMethodVisibilityRector::class)
->call('configure', [[
ChangeMethodVisibilityRector::METHOD_VISIBILITIES => ValueObjectInliner::inline([
new ChangeMethodVisibility(
'Illuminate\Foundation\Http\FormRequest',
'validationData',
Visibility::PUBLIC
),
]),
]]);
$services->set(ArgumentAdderRector::class)
->call('configure', [[
ArgumentAdderRector::ADDED_ARGUMENTS => ValueObjectInliner::inline([
// 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

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Rector\Set\ValueObject;
use Rector\Laravel\Set\LaravelSetList;
use Rector\Set\Contract\SetListInterface;
use Rector\Set\NetteSetList;
use Rector\Set\SymfonySetList;
@ -20,11 +21,6 @@ final class SetList implements SetListInterface
*/
public const ACTION_INJECTION_TO_CONSTRUCTOR_INJECTION = __DIR__ . '/../../../config/set/action-injection-to-constructor-injection.php';
/**
* @var string
*/
public const ARRAY_STR_FUNCTIONS_TO_STATIC_CALL = __DIR__ . '/../../../config/set/laravel-array-str-functions-to-static-call.php';
/**
* @var string
*/
@ -181,69 +177,102 @@ final class SetList implements SetListInterface
public const KDYBY_TRANSLATOR_TO_CONTRIBUTTE_TRANSLATION = __DIR__ . '/../../../config/set/kdyby-translator-to-contributte-translation.php';
/**
* For BC layer
* @deprecated Use LaravelSetList from rector/rector-laravel instead
* @var string
*/
public const LARAVEL_50 = __DIR__ . '/../../../config/set/laravel50.php';
public const ARRAY_STR_FUNCTIONS_TO_STATIC_CALL = LaravelSetList::ARRAY_STR_FUNCTIONS_TO_STATIC_CALL;
/**
* For BC layer
* @deprecated Use LaravelSetList from rector/rector-laravel instead
* @var string
*/
public const LARAVEL_51 = __DIR__ . '/../../../config/set/laravel51.php';
public const LARAVEL_50 = LaravelSetList::LARAVEL_50;
/**
* For BC layer
* @deprecated Use LaravelSetList from rector/rector-laravel instead
* @var string
*/
public const LARAVEL_52 = __DIR__ . '/../../../config/set/laravel52.php';
public const LARAVEL_51 = LaravelSetList::LARAVEL_51;
/**
* For BC layer
* @deprecated Use LaravelSetList from rector/rector-laravel instead
* @var string
*/
public const LARAVEL_53 = __DIR__ . '/../../../config/set/laravel53.php';
public const LARAVEL_52 = LaravelSetList::LARAVEL_52;
/**
* For BC layer
* @deprecated Use LaravelSetList from rector/rector-laravel instead
* @var string
*/
public const LARAVEL_54 = __DIR__ . '/../../../config/set/laravel54.php';
public const LARAVEL_53 = LaravelSetList::LARAVEL_53;
/**
* For BC layer
* @deprecated Use LaravelSetList from rector/rector-laravel instead
* @var string
*/
public const LARAVEL_55 = __DIR__ . '/../../../config/set/laravel55.php';
public const LARAVEL_54 = LaravelSetList::LARAVEL_54;
/**
* For BC layer
* @deprecated Use LaravelSetList from rector/rector-laravel instead
* @var string
*/
public const LARAVEL_56 = __DIR__ . '/../../../config/set/laravel56.php';
public const LARAVEL_55 = LaravelSetList::LARAVEL_55;
/**
* For BC layer
* @deprecated Use LaravelSetList from rector/rector-laravel instead
* @var string
*/
public const LARAVEL_57 = __DIR__ . '/../../../config/set/laravel57.php';
public const LARAVEL_56 = LaravelSetList::LARAVEL_56;
/**
* For BC layer
* @deprecated Use LaravelSetList from rector/rector-laravel instead
* @var string
*/
public const LARAVEL_58 = __DIR__ . '/../../../config/set/laravel58.php';
public const LARAVEL_57 = LaravelSetList::LARAVEL_57;
/**
* For BC layer
* @deprecated Use LaravelSetList from rector/rector-laravel instead
* @var string
*/
public const LARAVEL_60 = __DIR__ . '/../../../config/set/laravel60.php';
public const LARAVEL_58 = LaravelSetList::LARAVEL_58;
/**
* For BC layer
* @deprecated Use LaravelSetList from rector/rector-laravel instead
* @var string
*/
public const LARAVEL_STATIC_TO_INJECTION = __DIR__ . '/../../../config/set/laravel-static-to-injection.php';
public const LARAVEL_60 = LaravelSetList::LARAVEL_60;
/**
* For BC layer
* @deprecated Use LaravelSetList from rector/rector-laravel instead
* @var string
*/
public const LARAVEL_CODE_QUALITY = __DIR__ . '/../../../config/set/laravel-code-quality.php';
public const LARAVEL_STATIC_TO_INJECTION = LaravelSetList::LARAVEL_STATIC_TO_INJECTION;
/**
* For BC layer
* @deprecated Use LaravelSetList from rector/rector-laravel instead
* @var string
*/
public const LARAVEL_ARRAY_STR_FUNCTION_TO_STATIC_CALL = __DIR__ . '/../../../config/set/laravel-array-str-functions-to-static-call.php';
public const LARAVEL_CODE_QUALITY = LaravelSetList::LARAVEL_CODE_QUALITY;
/**
* For BC layer
* @deprecated Use LaravelSetList from rector/rector-laravel instead
* @var string
*/
public const LARAVEL_ARRAY_STR_FUNCTION_TO_STATIC_CALL = LaravelSetList::ARRAY_STR_FUNCTIONS_TO_STATIC_CALL;
/**
* @var string

View File

@ -1,34 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Tests\Laravel\Rector\Assign\CallOnAppArrayAccessToStandaloneAssignRector;
use Iterator;
use Rector\Laravel\Rector\Assign\CallOnAppArrayAccessToStandaloneAssignRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class CallOnAppArrayAccessToStandaloneAssignRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
/**
* @return Iterator<SmartFileInfo>
*/
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
protected function getRectorClass(): string
{
return CallOnAppArrayAccessToStandaloneAssignRector::class;
}
}

View File

@ -1,43 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Tests\Laravel\Rector\Assign\CallOnAppArrayAccessToStandaloneAssignRector\Fixture;
class SomeFixture
{
/**
* @var \Illuminate\Contracts\Foundation\Application
*/
protected $app;
public function run()
{
$validator = $this->app['validator']->make('...');
}
}
?>
-----
<?php
declare(strict_types=1);
namespace Rector\Tests\Laravel\Rector\Assign\CallOnAppArrayAccessToStandaloneAssignRector\Fixture;
class SomeFixture
{
/**
* @var \Illuminate\Contracts\Foundation\Application
*/
protected $app;
public function run()
{
/** @var \Illuminate\Validation\Factory $validationFactory */
$validationFactory = $this->app['validator'];
$validator = $validationFactory->make('...');
}
}
?>

View File

@ -1,34 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Tests\Laravel\Rector\ClassMethod\AddParentBootToModelClassMethodRector;
use Iterator;
use Rector\Laravel\Rector\ClassMethod\AddParentBootToModelClassMethodRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class AddParentBootToModelClassMethodRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
/**
* @return Iterator<SmartFileInfo>
*/
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
protected function getRectorClass(): string
{
return AddParentBootToModelClassMethodRector::class;
}
}

View File

@ -1,30 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\ClassMethod\AddParentBootToModelClassMethodRector\Fixture;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
public function boot()
{
}
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\ClassMethod\AddParentBootToModelClassMethodRector\Fixture;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
public function boot()
{
parent::boot();
}
}
?>

View File

@ -1,33 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\ClassMethod\AddParentBootToModelClassMethodRector\Fixture;
use Illuminate\Database\Eloquent\Model;
class OnTheLastLine extends Model
{
public function boot()
{
$value = 1000;
parent::boot();
}
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\ClassMethod\AddParentBootToModelClassMethodRector\Fixture;
use Illuminate\Database\Eloquent\Model;
class OnTheLastLine extends Model
{
public function boot()
{
parent::boot();
$value = 1000;
}
}
?>

View File

@ -1,34 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Tests\Laravel\Rector\Class_\AddMockConsoleOutputFalseToConsoleTestsRector;
use Iterator;
use Rector\Laravel\Rector\Class_\AddMockConsoleOutputFalseToConsoleTestsRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class AddMockConsoleOutputFalseToConsoleTestsRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
/**
* @return Iterator<SmartFileInfo>
*/
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
protected function getRectorClass(): string
{
return AddMockConsoleOutputFalseToConsoleTestsRector::class;
}
}

View File

@ -1,44 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\Class_\AddMockConsoleOutputFalseToConsoleTestsRector\Fixture;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Foundation\Testing\TestCase;
final class ExistingSetUp extends TestCase
{
protected function setUp()
{
$value = 1000;
}
public function test(): void
{
$this->assertEquals('content', \trim(Artisan::output()));
}
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\Class_\AddMockConsoleOutputFalseToConsoleTestsRector\Fixture;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Foundation\Testing\TestCase;
final class ExistingSetUp extends TestCase
{
protected function setUp()
{
$value = 1000;
$this->mockConsoleOutput = false;
}
public function test(): void
{
$this->assertEquals('content', \trim(Artisan::output()));
}
}
?>

View File

@ -1,38 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\Class_\AddMockConsoleOutputFalseToConsoleTestsRector\Fixture;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Foundation\Testing\TestCase;
final class SomeTest extends TestCase
{
public function test(): void
{
$this->assertEquals('content', \trim(Artisan::output()));
}
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\Class_\AddMockConsoleOutputFalseToConsoleTestsRector\Fixture;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Foundation\Testing\TestCase;
final class SomeTest extends TestCase
{
protected function setUp()
{
parent::setUp();
$this->mockConsoleOutput = false;
}
public function test(): void
{
$this->assertEquals('content', \trim(Artisan::output()));
}
}
?>

View File

@ -1,38 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\Class_\AddMockConsoleOutputFalseToConsoleTestsRector\Fixture;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Foundation\Testing\TestCase;
final class NewArtisan extends TestCase
{
public function test(): void
{
$this->assertEquals('content', \trim((new Artisan())::output()));
}
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\Class_\AddMockConsoleOutputFalseToConsoleTestsRector\Fixture;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Foundation\Testing\TestCase;
final class NewArtisan extends TestCase
{
protected function setUp()
{
parent::setUp();
$this->mockConsoleOutput = false;
}
public function test(): void
{
$this->assertEquals('content', \trim((new Artisan())::output()));
}
}
?>

View File

@ -1,20 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\Class_\AddMockConsoleOutputFalseToConsoleTestsRector\Fixture;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Foundation\Testing\TestCase;
final class SkipAlreadySet extends TestCase
{
protected function setUp()
{
parent::setUp();
$this->mockConsoleOutput = false;
}
public function test(): void
{
$this->assertEquals('content', \trim(Artisan::output()));
}
}

View File

@ -1,27 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\Class_\PropertyDeferToDeferrableProviderToRector\Fixture;
use Illuminate\Support\ServiceProvider;
final class SomeServiceProvider extends ServiceProvider
{
/**
* @var bool
*/
protected $defer = true;
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\Class_\PropertyDeferToDeferrableProviderToRector\Fixture;
use Illuminate\Support\ServiceProvider;
final class SomeServiceProvider extends ServiceProvider implements \Illuminate\Contracts\Support\DeferrableProvider
{
}
?>

View File

@ -1,13 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\Class_\PropertyDeferToDeferrableProviderToRector\Fixture;
use Illuminate\Support\ServiceProvider;
final class SkipFalseDefer extends ServiceProvider
{
/**
* @var bool
*/
protected $defer = false;
}

View File

@ -1,34 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Tests\Laravel\Rector\Class_\PropertyDeferToDeferrableProviderToRector;
use Iterator;
use Rector\Laravel\Rector\Class_\PropertyDeferToDeferrableProviderToRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class PropertyDeferToDeferrableProviderToRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
/**
* @return Iterator<SmartFileInfo>
*/
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
protected function getRectorClass(): string
{
return PropertyDeferToDeferrableProviderToRector::class;
}
}

View File

@ -1,27 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\FuncCall\HelperFuncCallToFacadeClassRector\Fixture;
class Fixture
{
public function run()
{
return app('translator')->trans('value');
}
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\FuncCall\HelperFuncCallToFacadeClassRector\Fixture;
class Fixture
{
public function run()
{
return \Illuminate\Support\Facades\App::get('translator')->trans('value');
}
}
?>

View File

@ -1,11 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\FuncCall\HelperFuncCallToFacadeClassRector\Fixture;
class SkipWithArgs
{
public function run()
{
return app('translator', 'some');
}
}

View File

@ -1,34 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Tests\Laravel\Rector\FuncCall\HelperFuncCallToFacadeClassRector;
use Iterator;
use Rector\Laravel\Rector\FuncCall\HelperFuncCallToFacadeClassRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class HelperFuncCallToFacadeClassRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
/**
* @return Iterator<SmartFileInfo>
*/
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
protected function getRectorClass(): string
{
return HelperFuncCallToFacadeClassRector::class;
}
}

View File

@ -1,34 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Tests\Laravel\Rector\MethodCall\ChangeQueryWhereDateValueWithCarbonRector;
use Iterator;
use Rector\Laravel\Rector\MethodCall\ChangeQueryWhereDateValueWithCarbonRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class ChangeQueryWhereDateValueWithCarbonRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
/**
* @return Iterator<SmartFileInfo>
*/
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
protected function getRectorClass(): string
{
return ChangeQueryWhereDateValueWithCarbonRector::class;
}
}

View File

@ -1,35 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\MethodCall\ChangeQueryWhereDateValueWithCarbonRector\Fixture;
use Carbon\Carbon;
use Illuminate\Database\Query\Builder;
class BiggerThan
{
public function run(Builder $query)
{
$query->whereDate('created_at', '>', Carbon::now());
}
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\MethodCall\ChangeQueryWhereDateValueWithCarbonRector\Fixture;
use Carbon\Carbon;
use Illuminate\Database\Query\Builder;
class BiggerThan
{
public function run(Builder $query)
{
$dateTime = Carbon::now();
$query->whereDate('created_at', '>=', $dateTime);
$query->whereTime('created_at', '>=', $dateTime);
}
}
?>

View File

@ -1,35 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\MethodCall\ChangeQueryWhereDateValueWithCarbonRector\Fixture;
use Carbon\Carbon;
use Illuminate\Database\Query\Builder;
final class CarbonNowWithCall
{
public function run(Builder $query)
{
$query->whereDate('created_at', '>', Carbon::now()->subDays(10000));
}
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\MethodCall\ChangeQueryWhereDateValueWithCarbonRector\Fixture;
use Carbon\Carbon;
use Illuminate\Database\Query\Builder;
final class CarbonNowWithCall
{
public function run(Builder $query)
{
$dateTime = Carbon::now()->subDays(10000);
$query->whereDate('created_at', '>=', $dateTime);
$query->whereTime('created_at', '>=', $dateTime);
}
}
?>

View File

@ -1,32 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\MethodCall\ChangeQueryWhereDateValueWithCarbonRector\Fixture;
use Illuminate\Database\Query\Builder;
class DateTimeOnly
{
public function run(Builder $query, \DateTimeInterface $dateTime)
{
$query->whereDate('created_at', '>', $dateTime);
}
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\MethodCall\ChangeQueryWhereDateValueWithCarbonRector\Fixture;
use Illuminate\Database\Query\Builder;
class DateTimeOnly
{
public function run(Builder $query, \DateTimeInterface $dateTime)
{
$query->whereDate('created_at', '>=', $dateTime);
$query->whereTime('created_at', '>=', $dateTime);
}
}
?>

View File

@ -1,35 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\MethodCall\ChangeQueryWhereDateValueWithCarbonRector\Fixture;
use Carbon\Carbon;
use Illuminate\Database\Query\Builder;
class SomeClass
{
public function run(Builder $query)
{
$query->whereDate('created_at', '<', Carbon::now());
}
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\MethodCall\ChangeQueryWhereDateValueWithCarbonRector\Fixture;
use Carbon\Carbon;
use Illuminate\Database\Query\Builder;
class SomeClass
{
public function run(Builder $query)
{
$dateTime = Carbon::now();
$query->whereDate('created_at', '<=', $dateTime);
$query->whereTime('created_at', '<=', $dateTime);
}
}
?>

View File

@ -1,15 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\MethodCall\ChangeQueryWhereDateValueWithCarbonRector\Fixture;
use Carbon\Carbon;
use Illuminate\Database\Query\Builder;
class SkipAlreadyEqual
{
public function run(Builder $query)
{
$dateTime = Carbon::now();
$query->whereDate('created_at', '<=', $dateTime);
}
}

View File

@ -1,14 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\MethodCall\ChangeQueryWhereDateValueWithCarbonRector\Fixture;
use Carbon\Carbon;
use Illuminate\Database\Query\Builder;
class SkipCarbonToday
{
public function run(Builder $query)
{
$query->whereDate('created_at', '>', Carbon::today());
}
}

View File

@ -1,14 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\MethodCall\ChangeQueryWhereDateValueWithCarbonRector\Fixture;
use Carbon\Carbon;
use Illuminate\Database\Query\Builder;
class SkipTwoArgsOnly
{
public function run(Builder $query)
{
$query->whereDate('created_at', Carbon::now());
}
}

View File

@ -1,36 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\MethodCall\ChangeQueryWhereDateValueWithCarbonRector\Fixture;
use Carbon\Carbon;
use Illuminate\Database\Query\Builder;
class VariableDateTime
{
public function run(Builder $query)
{
$dateTime = Carbon::now();
$query->whereDate('created_at', '<', $dateTime);
}
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\MethodCall\ChangeQueryWhereDateValueWithCarbonRector\Fixture;
use Carbon\Carbon;
use Illuminate\Database\Query\Builder;
class VariableDateTime
{
public function run(Builder $query)
{
$dateTime = Carbon::now();
$query->whereDate('created_at', '<=', $dateTime);
$query->whereTime('created_at', '<=', $dateTime);
}
}
?>

View File

@ -1,34 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Tests\Laravel\Rector\New_\AddGuardToLoginEventRector;
use Iterator;
use Rector\Laravel\Rector\New_\AddGuardToLoginEventRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class AddGuardToLoginEventRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
/**
* @return Iterator<SmartFileInfo>
*/
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
protected function getRectorClass(): string
{
return AddGuardToLoginEventRector::class;
}
}

View File

@ -1,32 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\New_\AddGuardToLoginEventRector\Fixture;
use Illuminate\Auth\Events\Login;
final class SomeClass
{
public function run(): void
{
$loginEvent = new Login('user', false);
}
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\New_\AddGuardToLoginEventRector\Fixture;
use Illuminate\Auth\Events\Login;
final class SomeClass
{
public function run(): void
{
$guard = config('auth.defaults.guard');
$loginEvent = new Login($guard, 'user', false);
}
}
?>

View File

@ -1,13 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\New_\AddGuardToLoginEventRector\Fixture;
use Illuminate\Auth\Events\Login;
final class SkipAlready
{
public function run($guard): void
{
$loginEvent = new Login($guard, 'user', false);
}
}

View File

@ -1,53 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\New_\MakeTaggedPassedToParameterIterableTypeRector\Fixture;
class AnotherClass
{
/**
* @var \Illuminate\Contracts\Foundation\Application
*/
private $app;
public function create()
{
$tagged = $this->app->tagged('some_tagged');
return new SomeClass($tagged);
}
}
class SomeClass
{
public function __construct(array $items)
{
}
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\New_\MakeTaggedPassedToParameterIterableTypeRector\Fixture;
class AnotherClass
{
/**
* @var \Illuminate\Contracts\Foundation\Application
*/
private $app;
public function create()
{
$tagged = $this->app->tagged('some_tagged');
return new SomeClass($tagged);
}
}
class SomeClass
{
public function __construct(iterable $items)
{
}
}
?>

View File

@ -1,34 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Tests\Laravel\Rector\New_\MakeTaggedPassedToParameterIterableTypeRector;
use Iterator;
use Rector\Laravel\Rector\New_\MakeTaggedPassedToParameterIterableTypeRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class MakeTaggedPassedToParameterIterableTypeRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
/**
* @return Iterator<SmartFileInfo>
*/
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
protected function getRectorClass(): string
{
return MakeTaggedPassedToParameterIterableTypeRector::class;
}
}

View File

@ -1,27 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\StaticCall\MinutesToSecondsInCacheRector\Fixture;
class CacheStaticCall
{
public function run()
{
\Illuminate\Support\Facades\Cache::remember('key', 'value', 60);
}
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\StaticCall\MinutesToSecondsInCacheRector\Fixture;
class CacheStaticCall
{
public function run()
{
\Illuminate\Support\Facades\Cache::remember('key', 'value', 60 * 60);
}
}
?>

View File

@ -1,41 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\StaticCall\MinutesToSecondsInCacheRector\Fixture;
use Illuminate\Contracts\Cache\Repository;
final class ConstReference
{
/**
* @var int
*/
private const TIME = 60;
public function run(Repository $repository)
{
$repository->remember('key', 'value', self::TIME);
}
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\StaticCall\MinutesToSecondsInCacheRector\Fixture;
use Illuminate\Contracts\Cache\Repository;
final class ConstReference
{
/**
* @var int
*/
private const TIME = 60 * 60;
public function run(Repository $repository)
{
$repository->remember('key', 'value', self::TIME);
}
}
?>

View File

@ -1,61 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\StaticCall\MinutesToSecondsInCacheRector\Fixture;
use Illuminate\Contracts\Cache\Store;
class SomeClass
{
/**
* @var Store
*/
private $arrayStore;
public function __construct(Store $arrayStore)
{
$this->arrayStore = $arrayStore;
}
public function run()
{
\Illuminate\Support\Facades\Cache::put('key', 'value', 60);
$this->arrayStore->put('key', 'value', 60);
$seconds = 60;
$this->arrayStore->putMany(['key' => 'value'], $seconds);
}
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\StaticCall\MinutesToSecondsInCacheRector\Fixture;
use Illuminate\Contracts\Cache\Store;
class SomeClass
{
/**
* @var Store
*/
private $arrayStore;
public function __construct(Store $arrayStore)
{
$this->arrayStore = $arrayStore;
}
public function run()
{
\Illuminate\Support\Facades\Cache::put('key', 'value', 60 * 60);
$this->arrayStore->put('key', 'value', 60 * 60);
$seconds = 60;
$this->arrayStore->putMany(['key' => 'value'], $seconds * 60);
}
}
?>

View File

@ -1,43 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\StaticCall\MinutesToSecondsInCacheRector\Fixture;
use Illuminate\Contracts\Cache\Repository;
final class MultipleUsedConstReference
{
/**
* @var int
*/
private const TIME = 60;
public function run(Repository $repository)
{
$repository->remember('key', 'value', self::TIME);
$repository->remember('key', 'value', self::TIME);
}
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\StaticCall\MinutesToSecondsInCacheRector\Fixture;
use Illuminate\Contracts\Cache\Repository;
final class MultipleUsedConstReference
{
/**
* @var int
*/
private const TIME = 60 * 60;
public function run(Repository $repository)
{
$repository->remember('key', 'value', self::TIME);
$repository->remember('key', 'value', self::TIME);
}
}
?>

View File

@ -1,27 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\StaticCall\MinutesToSecondsInCacheRector\Fixture;
class OnlyOne
{
public function run()
{
\Illuminate\Support\Facades\Cache::put('key', 'value', 1);
}
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\StaticCall\MinutesToSecondsInCacheRector\Fixture;
class OnlyOne
{
public function run()
{
\Illuminate\Support\Facades\Cache::put('key', 'value', 60);
}
}
?>

View File

@ -1,31 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\StaticCall\MinutesToSecondsInCacheRector\Fixture;
use Illuminate\Contracts\Cache\Repository;
final class RememberCache
{
public function run(Repository $repository)
{
$repository->remember('key', 'value', 60);
}
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\StaticCall\MinutesToSecondsInCacheRector\Fixture;
use Illuminate\Contracts\Cache\Repository;
final class RememberCache
{
public function run(Repository $repository)
{
$repository->remember('key', 'value', 60 * 60);
}
}
?>

View File

@ -1,13 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\StaticCall\MinutesToSecondsInCacheRector\Fixture;
use DateTime;
class SkipCall
{
public function run()
{
\Illuminate\Support\Facades\Cache::put('key', 'value', new DateTime());
}
}

View File

@ -1,34 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Tests\Laravel\Rector\StaticCall\MinutesToSecondsInCacheRector;
use Iterator;
use Rector\Laravel\Rector\StaticCall\MinutesToSecondsInCacheRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class MinutesToSecondsInCacheRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
/**
* @return Iterator<SmartFileInfo>
*/
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
protected function getRectorClass(): string
{
return MinutesToSecondsInCacheRector::class;
}
}

View File

@ -1,27 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\StaticCall\Redirect301ToPermanentRedirectRector\Fixture;
class Fixture
{
public function run()
{
\Illuminate\Routing\Route::redirect('/foo', '/bar', 301);
}
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\StaticCall\Redirect301ToPermanentRedirectRector\Fixture;
class Fixture
{
public function run()
{
\Illuminate\Routing\Route::permanentRedirect('/foo', '/bar');
}
}
?>

View File

@ -1,34 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Tests\Laravel\Rector\StaticCall\Redirect301ToPermanentRedirectRector;
use Iterator;
use Rector\Laravel\Rector\StaticCall\Redirect301ToPermanentRedirectRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class Redirect301ToPermanentRedirectRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
/**
* @return Iterator<SmartFileInfo>
*/
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
protected function getRectorClass(): string
{
return Redirect301ToPermanentRedirectRector::class;
}
}

View File

@ -1,31 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\StaticCall\RequestStaticValidateToInjectRector\Fixture;
use Illuminate\Http\Request;
class SomeClass
{
public function store()
{
$validatedData = Request::validate(['some_attribute' => 'required']);
}
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\StaticCall\RequestStaticValidateToInjectRector\Fixture;
use Illuminate\Http\Request;
class SomeClass
{
public function store(\Illuminate\Http\Request $request)
{
$validatedData = $request->validate(['some_attribute' => 'required']);
}
}
?>

View File

@ -1,31 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\StaticCall\RequestStaticValidateToInjectRector\Fixture;
use Request;
class SomeClassAlias
{
public function store()
{
$validatedData = Request::validate(['some_attribute' => 'required']);
}
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\StaticCall\RequestStaticValidateToInjectRector\Fixture;
use Request;
class SomeClassAlias
{
public function store(\Illuminate\Http\Request $request)
{
$validatedData = $request->validate(['some_attribute' => 'required']);
}
}
?>

View File

@ -1,27 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\StaticCall\RequestStaticValidateToInjectRector\Fixture;
class SomeFunction
{
public function store()
{
$validatedData = request()->get('foo');
}
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\StaticCall\RequestStaticValidateToInjectRector\Fixture;
class SomeFunction
{
public function store(\Illuminate\Http\Request $request)
{
$validatedData = $request->get('foo');
}
}
?>

View File

@ -1,27 +0,0 @@
<?php
namespace Rector\Tests\Laravel\Rector\StaticCall\RequestStaticValidateToInjectRector\Fixture;
class Function2
{
public function store()
{
$validatedData = request('foo');
}
}
?>
-----
<?php
namespace Rector\Tests\Laravel\Rector\StaticCall\RequestStaticValidateToInjectRector\Fixture;
class Function2
{
public function store(\Illuminate\Http\Request $request)
{
$validatedData = $request->input('foo');
}
}
?>

View File

@ -1,34 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Tests\Laravel\Rector\StaticCall\RequestStaticValidateToInjectRector;
use Iterator;
use Rector\Laravel\Rector\StaticCall\RequestStaticValidateToInjectRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class RequestStaticValidateToInjectRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
/**
* @return Iterator<SmartFileInfo>
*/
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
protected function getRectorClass(): string
{
return RequestStaticValidateToInjectRector::class;
}
}

View File

@ -1,59 +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\AttributeAwarePhpDoc\Ast\Type\FullyQualifiedIdentifierTypeNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Laravel\ValueObject\ServiceNameTypeAndVariableName;
final class AppAssignFactory
{
/**
* @var 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,137 +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 Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\Laravel\Rector\Assign\CallOnAppArrayAccessToStandaloneAssignRector\CallOnAppArrayAccessToStandaloneAssignRectorTest
*/
final class CallOnAppArrayAccessToStandaloneAssignRector extends AbstractRector
{
/**
* @var ServiceNameTypeAndVariableName[]
*/
private $serviceNameTypeAndVariableNames = [];
/**
* @var AppAssignFactory
*/
private $appAssignFactory;
public function __construct(AppAssignFactory $appAssignFactory)
{
$this->serviceNameTypeAndVariableNames[] = new ServiceNameTypeAndVariableName(
'validator',
'Illuminate\Validation\Factory',
'validationFactory'
);
$this->appAssignFactory = $appAssignFactory;
}
/**
* @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->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,127 +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\Nette\NodeAnalyzer\StaticCallAnalyzer;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see https://laracasts.com/discuss/channels/laravel/laravel-57-upgrade-observer-problem
*
* @see \Rector\Tests\Laravel\Rector\ClassMethod\AddParentBootToModelClassMethodRector\AddParentBootToModelClassMethodRectorTest
*/
final class AddParentBootToModelClassMethodRector extends AbstractRector
{
/**
* @var string
*/
private const BOOT = 'boot';
/**
* @var 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 = $node->getAttribute(AttributeKey::CLASS_NODE);
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,147 +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\Variable;
use PhpParser\Node\Stmt\Class_;
use PHPStan\Type\ObjectType;
use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\PHPUnit\NodeManipulator\SetUpClassMethodNodeManipulator;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see https://github.com/laravel/framework/issues/26450#issuecomment-449401202
* @see https://github.com/laravel/framework/commit/055fe52dbb7169dc51bd5d5deeb05e8da9be0470#diff-76a649cb397ea47f5613459c335f88c1b68e5f93e51d46e9fb5308ec55ded221
*
* @see \Rector\Tests\Laravel\Rector\Class_\AddMockConsoleOutputFalseToConsoleTestsRector\AddMockConsoleOutputFalseToConsoleTestsRectorTest
*/
final class AddMockConsoleOutputFalseToConsoleTestsRector extends AbstractRector
{
/**
* @var PropertyFetchAnalyzer
*/
private $propertyFetchAnalyzer;
/**
* @var SetUpClassMethodNodeManipulator
*/
private $setUpClassMethodNodeManipulator;
public function __construct(
PropertyFetchAnalyzer $propertyFetchAnalyzer,
SetUpClassMethodNodeManipulator $setUpClassMethodNodeManipulator
) {
$this->propertyFetchAnalyzer = $propertyFetchAnalyzer;
$this->setUpClassMethodNodeManipulator = $setUpClassMethodNodeManipulator;
}
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();
$this->setUpClassMethodNodeManipulator->decorateOrCreate($node, [$assign]);
return $node;
}
private function isTestingConsoleOutput(Class_ $class): bool
{
return (bool) $this->betterNodeFinder->findFirst($class->stmts, function (Node $node): bool {
return $this->nodeNameResolver->isStaticCallNamed($node, 'Illuminate\Support\Facades\Artisan', '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,101 +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;
/**
* @see https://laravel.com/docs/5.8/upgrade#deferred-service-providers
*
* @see \Rector\Tests\Laravel\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,72 +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;
/**
* @see https://laravel.com/docs/8.x/helpers#method-app
* @see https://github.com/laravel/framework/blob/8.x/src/Illuminate/Foundation/helpers.php
*
* @see \Rector\Tests\Laravel\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,169 +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 Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see https://github.com/laravel/framework/pull/25315
* @see https://laracasts.com/discuss/channels/eloquent/laravel-eloquent-where-date-is-equal-or-smaller-than-datetime
*
* @see \Rector\Tests\Laravel\Rector\MethodCall\ChangeQueryWhereDateValueWithCarbonRector\ChangeQueryWhereDateValueWithCarbonRectorTest
*/
final class ChangeQueryWhereDateValueWithCarbonRector extends AbstractRector
{
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
{
$argValue = $this->matchWhereDateThirdArgValue($node);
if (! $argValue instanceof Expr) {
return null;
}
// is just made with static call?
if ($argValue instanceof StaticCall || $argValue instanceof MethodCall) {
// now!
// 1. extract assign
$dateTimeVariable = new Variable('dateTime');
$assign = new Assign($dateTimeVariable, $argValue);
$this->addNodeBeforeNode($assign, $node);
$node->args[2]->value = $dateTimeVariable;
// update assign ">" → ">="
$this->changeCompareSignExpr($node->args[1]);
// 2. add "whereTime()" time call
$whereTimeMethodCall = $this->createWhereTimeMethodCall($node, $dateTimeVariable);
$this->addNodeAfterNode($whereTimeMethodCall, $node);
return $node;
}
if ($argValue instanceof Variable) {
$dateTimeVariable = $argValue;
$this->changeCompareSignExpr($node->args[1]);
// 2. add "whereTime()" time call
$whereTimeMethodCall = $this->createWhereTimeMethodCall($node, $dateTimeVariable);
$this->addNodeAfterNode($whereTimeMethodCall, $node);
}
return null;
}
private function matchWhereDateThirdArgValue(MethodCall $methodCall): ?Expr
{
if (! $this->isOnClassMethodCall(
$methodCall,
new ObjectType('Illuminate\Database\Query\Builder'),
'whereDate'
)) {
return null;
}
if (! isset($methodCall->args[2])) {
return null;
}
$argValue = $methodCall->args[2]->value;
if (! $this->isObjectType($argValue, new ObjectType('DateTimeInterface'))) {
return null;
}
// nothing to change
if ($this->nodeNameResolver->isStaticCallNamed($argValue, 'Carbon\Carbon', 'today')) {
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);
}
}

View File

@ -1,95 +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 Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see https://github.com/laravel/framework/commit/f5d8c0a673aa9fc6cd94aa4858a0027fe550a22e#diff-162a49c054acde9f386ec735607b95bc4a1c0c765a6f46da8de9a8a4ef5199d3
* @see https://github.com/laravel/framework/pull/25261
*
* @see \Rector\Tests\Laravel\Rector\New_\AddGuardToLoginEventRector\AddGuardToLoginEventRectorTest
*/
final class AddGuardToLoginEventRector extends AbstractRector
{
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->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,130 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Laravel\Rector\New_;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\MethodName;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see https://laravel.com/docs/5.8/upgrade#container-generators
*
* @see \Rector\Tests\Laravel\Rector\New_\MakeTaggedPassedToParameterIterableTypeRector\MakeTaggedPassedToParameterIterableTypeRectorTest
*/
final class MakeTaggedPassedToParameterIterableTypeRector extends AbstractRector
{
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Change param type to iterable, if passed one', [
new CodeSample(
<<<'CODE_SAMPLE'
class AnotherClass
{
/**
* @var \Illuminate\Contracts\Foundation\Application
*/
private $app;
public function create()
{
$tagged = $this->app->tagged('some_tagged');
return new SomeClass($tagged);
}
}
class SomeClass
{
public function __construct(array $items)
{
}
}
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
class AnotherClass
{
/**
* @var \Illuminate\Contracts\Foundation\Application
*/
private $app;
public function create()
{
$tagged = $this->app->tagged('some_tagged');
return new SomeClass($tagged);
}
}
class SomeClass
{
public function __construct(iterable $items)
{
}
}
CODE_SAMPLE
),
]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes(): array
{
return [New_::class];
}
/**
* @param New_ $node
*/
public function refactor(Node $node): ?Node
{
$className = $this->getName($node->class);
if ($className === null) {
return null;
}
$class = $this->nodeRepository->findClass($className);
if (! $class instanceof Class_) {
return null;
}
foreach ($node->args as $arg) {
$this->refactorClassWithArgType($class, $arg);
}
return null;
}
private function refactorClassWithArgType(Class_ $class, Arg $arg): void
{
$argValueType = $this->getStaticType($arg->value);
$constructClassMethod = $class->getMethod(MethodName::CONSTRUCT);
$argumentPosition = (int) $arg->getAttribute(AttributeKey::ARGUMENT_POSITION);
if (! $constructClassMethod instanceof ClassMethod) {
return;
}
$param = $constructClassMethod->params[$argumentPosition] ?? null;
if (! $param instanceof Param) {
return;
}
$argTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($argValueType);
$param->type = $argTypeNode;
}
}

View File

@ -1,187 +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\ClassConstFetch;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Stmt\ClassConst;
use Rector\Core\Rector\AbstractRector;
use Rector\Laravel\ValueObject\TypeToTimeMethodAndPosition;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see https://github.com/laravel/framework/pull/27276
* @see https://laravel.com/docs/5.8/upgrade#cache-ttl-in-seconds
*
* @see \Rector\Tests\Laravel\Rector\StaticCall\MinutesToSecondsInCacheRector\MinutesToSecondsInCacheRectorTest
*/
final class MinutesToSecondsInCacheRector extends AbstractRector
{
/**
* @var string
*/
private const ATTRIBUTE_KEY_ALREADY_MULTIPLIED = 'already_multiplied';
/**
* @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;
}
$argValue = $node->args[$typeToTimeMethodAndPosition->getPosition()]->value;
return $this->processArgumentOnPosition($node, $argValue, $typeToTimeMethodAndPosition->getPosition());
}
return $node;
}
/**
* @param StaticCall|MethodCall $node
* @return StaticCall|MethodCall|null
*/
private function processArgumentOnPosition(Node $node, Expr $argExpr, int $argumentPosition): ?Expr
{
if ($argExpr instanceof ClassConstFetch) {
$this->refactorClassConstFetch($argExpr);
return null;
}
if (! $this->nodeTypeResolver->isNumberType($argExpr)) {
return null;
}
$mul = $this->mulByNumber($argExpr, 60);
$node->args[$argumentPosition] = new Arg($mul);
return $node;
}
private function refactorClassConstFetch(ClassConstFetch $classConstFetch): void
{
$classConst = $this->nodeRepository->findClassConstByClassConstFetch($classConstFetch);
if (! $classConst instanceof ClassConst) {
return;
}
$onlyConst = $classConst->consts[0];
$alreadyMultiplied = (bool) $onlyConst->getAttribute(self::ATTRIBUTE_KEY_ALREADY_MULTIPLIED);
if ($alreadyMultiplied) {
return;
}
$onlyConst->value = $this->mulByNumber($onlyConst->value, 60);
$onlyConst->setAttribute(self::ATTRIBUTE_KEY_ALREADY_MULTIPLIED, true);
}
private function mulByNumber(Expr $argExpr, int $value): Expr
{
if ($this->valueResolver->isValue($argExpr, 1)) {
return new LNumber($value);
}
return new Mul($argExpr, new LNumber($value));
}
}

View File

@ -1,95 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Laravel\Rector\StaticCall;
use PhpParser\Node;
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;
/**
* @see https://laravel.com/docs/5.7/upgrade
* @see \Rector\Tests\Laravel\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;
}
$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,133 +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 Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see https://github.com/laravel/framework/pull/27276
* @see \Rector\Tests\Laravel\Rector\StaticCall\RequestStaticValidateToInjectRector\RequestStaticValidateToInjectRectorTest
*/
final class RequestStaticValidateToInjectRector extends AbstractRector
{
/**
* @var ClassMethodManipulator
*/
private $classMethodManipulator;
/**
* @var ObjectType[]
*/
private $requestObjectTypes = [];
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 StaticCall|FuncCall $node
*/
private function shouldSkip(Node $node): bool
{
if ($node instanceof StaticCall) {
return ! $this->nodeTypeResolver->isObjectTypes($node->class, $this->requestObjectTypes);
}
$classLike = $node->getAttribute(AttributeKey::CLASS_NODE);
if (! $classLike instanceof Class_) {
return true;
}
return ! $this->isName($node, 'request');
}
}

View File

@ -1,45 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Laravel\ValueObject;
final class ServiceNameTypeAndVariableName
{
/**
* @var string
*/
private $serviceName;
/**
* @var string
*/
private $type;
/**
* @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,47 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Laravel\ValueObject;
use PHPStan\Type\ObjectType;
final class TypeToTimeMethodAndPosition
{
/**
* @var string
*/
private $type;
/**
* @var string
*/
private $methodName;
/**
* @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;
}
}