Skip to content

Conversation

@calebdw
Copy link
Contributor

@calebdw calebdw commented Nov 27, 2025

Hello!

resolve() is just an alias of app(), so this renames all instances to app() which also slightly increases performance

Thanks!

@calebdw calebdw force-pushed the calebdw/push-wnooomnsvxzu branch from 5320e3f to af1b6e8 Compare November 27, 2025 14:07
@peterfox
Copy link
Collaborator

I'm not sure I agree on this being a code quality choice. In part because people might use resolve() for better IDE type hinting while app() does additional magic. If anything I'd more be inclinded to make a rule that determines when it's better to use resolve() over app() when applicable.

@calebdw
Copy link
Contributor Author

calebdw commented Nov 29, 2025

app() has the same function phpdocs that resolve() does so it will work equally as well. The only additional thing that app() does is return the container when there's no arguments provided which is also handled by the phpdocs.

What heuristics would you use to determine when to rename? I can't think of any... Also, there's other rules that replaced aliased methods with the actual method, so I don't really see this as any different

@peterfox
Copy link
Collaborator

What heuristics would you use to determine when to rename? I can't think of any... Also, there's other rules that replaced aliased methods with the actual method, so I don't really see this as any different

Can you supply some examples? Note ones where the soft signature of the methods aren't the same.

app() has the same function phpdocs that resolve() does so it will work equally as well. The only additional thing that app() does is return the container when there's no arguments provided which is also handled by the phpdocs.

While it does use app() the soft signatures are quite different:

    /**
     * Resolve a service from the container.
     *
     * @template TClass of object
     *
     * @param  string|class-string<TClass>  $name
     * @return ($name is class-string<TClass> ? TClass : mixed)
     */
    function resolve($name, array $parameters = [])
    /**
     * Get the available container instance.
     *
     * @template TClass of object
     *
     * @param  string|class-string<TClass>|null  $abstract
     * @return ($abstract is class-string<TClass> ? TClass : ($abstract is null ? \Illuminate\Foundation\Application : mixed))
     */
    function app($abstract = null, array $parameters = [])
    {
        if (is_null($abstract)) {
            return Container::getInstance();
        }

        return Container::getInstance()->make($abstract, $parameters);
    }

I personally would use resolve over app more often than not.

e.g.

resolve(Foo::class)
// is a lot clearer than
app(Foo::class)
// because app() is more ambiguous, if I use app() to resolve something I usually would use:
app()->make(Foo::class) 

@calebdw
Copy link
Contributor Author

calebdw commented Nov 29, 2025

Hmm, I can write a rule to go from app(Foo::class) to resolve(Foo::class), there should be some consistency one way or another

@peterfox
Copy link
Collaborator

I agree and that would be a useful rule to have.

@calebdw calebdw closed this Nov 29, 2025
@calebdw calebdw deleted the calebdw/push-wnooomnsvxzu branch November 29, 2025 16:13
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