Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds ReplaceServiceContainerCallArgRector #189

Merged
merged 2 commits into from
Feb 29, 2024

Conversation

peterfox
Copy link
Collaborator

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.

-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.

@peterfox peterfox self-assigned this Feb 29, 2024
@driftingly
Copy link
Owner

This is great. Thanks @peterfox
Feel free to merge when ready 🚀

@peterfox peterfox merged commit d6da062 into main Feb 29, 2024
5 checks passed
@peterfox peterfox deleted the feature/service-container-call-parameter-change branch February 29, 2024 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants