Skip to content

Pass CLI --error-format option into the DIC container parameter#5131

Open
janedbal wants to merge 2 commits intophpstan:2.1.xfrom
janedbal:error-format-dic-parameter
Open

Pass CLI --error-format option into the DIC container parameter#5131
janedbal wants to merge 2 commits intophpstan:2.1.xfrom
janedbal:error-format-dic-parameter

Conversation

@janedbal
Copy link
Contributor

@janedbal janedbal commented Mar 4, 2026

The errorFormat DIC parameter was not updated when the --error-format CLI option was used - it always held the config file value (default null). This meant reading the parameter from the container would not reflect the actually-used value.

The errorFormat DIC parameter was not updated when the --error-format
CLI option was used - it always held the config file value (default null).
This meant reading the parameter from the container would not reflect
the actually-used value.

Thread the CLI error format through CommandHelper::begin() and
ContainerFactory::create() as a dynamic parameter, so it properly
overrides the config file value. Simplify the resolution in
AnalyseCommand to just read from the container.
@janedbal janedbal changed the base branch from 2.2.x to 2.1.x March 4, 2026 12:22
@phpstan-bot
Copy link
Collaborator

You've opened the pull request against the latest branch 2.2.x. PHPStan 2.2 is not going to be released for months. If your code is relevant on 2.1.x and you want it to be released sooner, please rebase your pull request and change its target to 2.1.x.

@staabm staabm requested a review from ondrejmirtes March 4, 2026 12:57
@ondrejmirtes
Copy link
Member

If you want to have a non-default error formatter and you don't want to execute PHPStan each time with the CLI option, you can use the configuration parameter.

The configuration parameter was never meant to be used to query the current error formatter. What is your usecase, why are you interested in it?

@janedbal
Copy link
Contributor Author

janedbal commented Mar 4, 2026

What is your usecase, why are you interested in it?

I want to be able to detect used formatter from within DCD. I need to enable some memory-intensive tracking for autoremoval of dead code - and that does not make sense to do for regular executions. Thus, my idea was to check if errorFormat matches ours and we can perform some extra work.

@ondrejmirtes
Copy link
Member

I'm skeptical about this. For one, errorFormat is included in the list of parameters not invalidating result cache.

So it's not really okay to inject it into rules and collectors because the result cache might become stale (except for CollectedDataNode rule but it's brittle and hard to control).

Could you instead do the expensive work inside the special "fixing" error formatter altogether? Maybe somehow mark the output of rules and collectors with "hey, this needs some extra work" which could the error formatter pick up and finish before removing dead code?

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.

3 participants