Skip to content

fix: larastan unable to recognize macro#30

Open
calebdw wants to merge 1 commit intoIntervention:developfrom
calebdw:calebdw/push-xmswyryxpnmx
Open

fix: larastan unable to recognize macro#30
calebdw wants to merge 1 commit intoIntervention:developfrom
calebdw:calebdw/push-xmswyryxpnmx

Conversation

@calebdw
Copy link
Contributor

@calebdw calebdw commented Mar 22, 2026

Hello!

Every time I run PHPStan I'm getting this false positive:

image

Larastan recognizes macros because it boots the application and checks if this exists. However, it's not going to recognize it if the macro is never registered when running in console.

Registering a macro is very lightweight (literally just an array key assignment) so there's no performance implications to this.

Thanks!

@olivervogel
Copy link
Member

Thanks. As far as I can remember, #18 was the issue that led to the change.

Which is actually only a workaround for a single edge case where no application key is available. In hindsight, one might consider reverting this.

@calebdw
Copy link
Contributor Author

calebdw commented Mar 22, 2026

Ah, I know why that happens, I ran into this myself.

When you use the facade in a service provider (e.g., Response::macro()), then this does resolve the binding from the container and can cause heavy init logic or the exceptions reported if env varsity are missing.

The solution is to use $this->app->afterResolving(ResponseFactory::class, $closure) which ONLY executes the closure if the binding is ACTUALLY resolved from the container. Requests or commands that don't use it will not actual cause it to be registered. There's a shortcut to use on the facade though, Repsonse::resolved($closure) will do the same thing.

I'll go through and clean up and usages which should solve both his issue and mine.

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