diff --git a/config/sets/laravel-container-string-to-fully-qualified-name.php b/config/sets/laravel-container-string-to-fully-qualified-name.php new file mode 100644 index 00000000..d493002d --- /dev/null +++ b/config/sets/laravel-container-string-to-fully-qualified-name.php @@ -0,0 +1,81 @@ +import(__DIR__ . '/../config.php'); + + $servicesMap = [ + 'events' => 'Illuminate\Contracts\Events\Dispatcher', + 'log' => 'Psr\Log\LoggerInterface', + 'router' => 'Illuminate\Routing\Router', + 'url' => 'Illuminate\Contracts\Routing\UrlGenerator', + 'redirect' => 'Illuminate\Routing\Redirector', + 'auth' => 'Illuminate\Contracts\Auth\Factory', + 'auth.driver' => 'Illuminate\Auth\SessionGuard', + 'cookie' => 'Illuminate\Cookie\CookieJar', + 'db.factory' => 'Illuminate\Database\Connectors\ConnectionFactory', + 'db' => 'Illuminate\Database\ConnectionResolverInterface', + 'db.connection' => 'Illuminate\Database\ConnectionInterface', + 'db.schema' => 'Illuminate\Database\Schema\SQLiteBuilder', + 'db.transactions' => 'Illuminate\Database\DatabaseTransactionsManager', + 'encrypter' => 'Illuminate\Encryption\Encrypter', + 'files' => 'Illuminate\Filesystem\Filesystem', + 'filesystem' => 'Illuminate\Contracts\Filesystem\Factory', + 'session' => 'Illuminate\Session\SessionManager', + 'session.store' => 'Illuminate\Contracts\Session\Session', + 'view' => 'Illuminate\Contracts\View\Factory', + 'view.finder' => 'Illuminate\View\ViewFinderInterface', + 'blade.compiler' => 'Illuminate\View\Compilers\CompilerInterface', + 'view.engine.resolver' => 'Illuminate\View\Engines\EngineResolver', + 'flare.logger' => 'Monolog\Logger', + 'cache' => 'Illuminate\Contracts\Cache\Factory', + 'cache.store' => 'Illuminate\Cache\Repository', + 'memcached.connector' => 'Illuminate\Cache\MemcachedConnector', + 'queue' => 'Illuminate\Queue\QueueManager', + 'queue.connection' => 'Illuminate\Contracts\Queue\Queue', + 'queue.worker' => 'Illuminate\Queue\Worker', + 'queue.listener' => 'Illuminate\Queue\Listener', + 'queue.failer' => 'Illuminate\Queue\Failed\DatabaseUuidFailedJobProvider', + 'migration.repository' => 'Illuminate\Database\Migrations\MigrationRepositoryInterface', + 'migrator' => 'Illuminate\Database\Migrations\Migrator', + 'migration.creator' => 'Illuminate\Database\Migrations\MigrationCreator', + 'composer' => 'Illuminate\Support\Composer', + 'hash' => 'Illuminate\Contracts\Hashing\Hasher', + 'hash.driver' => 'Illuminate\Contracts\Hashing\Hasher', + 'mail.manager' => 'Illuminate\Contracts\Mail\Factory', + 'mailer' => 'Illuminate\Mail\Mailer', + 'auth.password' => 'Illuminate\Contracts\Auth\PasswordBrokerFactory', + 'auth.password.broker' => 'Illuminate\Contracts\Auth\PasswordBroker', + 'pipeline' => 'Illuminate\Contracts\Pipeline\Pipeline', + 'redis' => 'Illuminate\Contracts\Redis\Factory', + 'translation.loader' => 'Illuminate\Contracts\Translation\Loader', + 'translator' => 'Illuminate\Contracts\Translation\Translator', + 'validation.presence' => 'Illuminate\Validation\DatabasePresenceVerifier', + 'validator' => 'Illuminate\Contracts\Validation\Factory', + 'command.tinker' => 'Laravel\Tinker\Console\TinkerCommand', + ]; + + $ruleConfig = array_map( + fn (string $service, string $interface) => new ReplaceServiceContainerCallArg( + $service, + new ClassConstFetch( + new FullyQualified($interface), + 'class' + ) + ), + array_keys($servicesMap), + $servicesMap, + ); + + $rectorConfig->ruleWithConfiguration( + ReplaceServiceContainerCallArgRector::class, + $ruleConfig + ); +}; diff --git a/tests/Sets/ContainerStringToFullyQualifiedName/ContainerStringToFullyQualifiedNameTest.php b/tests/Sets/ContainerStringToFullyQualifiedName/ContainerStringToFullyQualifiedNameTest.php new file mode 100644 index 00000000..5ac97f77 --- /dev/null +++ b/tests/Sets/ContainerStringToFullyQualifiedName/ContainerStringToFullyQualifiedNameTest.php @@ -0,0 +1,31 @@ +doTestFile($filePath); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Sets/ContainerStringToFullyQualifiedName/Fixture/fixture.php.inc b/tests/Sets/ContainerStringToFullyQualifiedName/Fixture/fixture.php.inc new file mode 100644 index 00000000..389ab0ff --- /dev/null +++ b/tests/Sets/ContainerStringToFullyQualifiedName/Fixture/fixture.php.inc @@ -0,0 +1,59 @@ + +----- + diff --git a/tests/Sets/ContainerStringToFullyQualifiedName/config/configured_rule.php b/tests/Sets/ContainerStringToFullyQualifiedName/config/configured_rule.php new file mode 100644 index 00000000..d0c72059 --- /dev/null +++ b/tests/Sets/ContainerStringToFullyQualifiedName/config/configured_rule.php @@ -0,0 +1,9 @@ +import(__DIR__ . '/../../../../config/sets/laravel-container-string-to-fully-qualified-name.php'); +};