Closed peterfox closed 4 months ago
Adds a new ReplaceServiceContainerCallArgRector rule Adds a ReplaceServiceContainerCallArg value object Adds tests Updates the docs
A neat little rule here which can be used in a set in the future to remove uses of string alias' to the service container.
-app('encrypter')->encrypt('...'); -\Illuminate\Support\Facades\Application::make('encrypter')->encrypt('...'); +app(Illuminate\Contracts\Encryption\Encrypter::class)->encrypt('...'); +\Illuminate\Support\Facades\Application::make(Illuminate\Contracts\Encryption\Encrypter::class)->encrypt('...');
Configuration of the rule is as simple as:
new ReplaceServiceContainerCallArg( 'encrypter', new ClassConstFetch( new FullyQualified('Illuminate\Contracts\Encryption\Encrypter'), 'class' ), ),
You can also do it the other way around if you for some reason want to swap a Class const for a string.
This is great. Thanks @peterfox Feel free to merge when ready 🚀
Changes
Adds a new ReplaceServiceContainerCallArgRector rule Adds a ReplaceServiceContainerCallArg value object Adds tests Updates the docs
Why
A neat little rule here which can be used in a set in the future to remove uses of string alias' to the service container.
Configuration of the rule is as simple as:
You can also do it the other way around if you for some reason want to swap a Class const for a string.