Skip to content

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

Closed
janedbal wants to merge 2 commits into
phpstan:2.3.xfrom
janedbal:error-format-dic-parameter
Closed

janedbal wants to merge 2 commits into
phpstan:2.3.xfrom
janedbal:error-format-dic-parameter

Conversation

@janedbal

@janedbal janedbal commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

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.

@janedbal
janedbal changed the base branch from 2.2.x to 2.1.x March 4, 2026 12:22
@phpstan-bot

Copy link
Copy Markdown
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
Copy Markdown
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

janedbal commented Mar 4, 2026

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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?

@janedbal

janedbal commented Mar 5, 2026

Copy link
Copy Markdown
Contributor Author

Could you instead do the expensive work inside the special "fixing" error formatter altogether?

Not really or very hardly. The concrete usecase is full removal neverRead property - not just definition, but all remaining writes to be deleted. So during main DCD analysis, I need to collect those and send them thru error.metadata to the formatter.

@janedbal

janedbal commented Mar 5, 2026

Copy link
Copy Markdown
Contributor Author

So it's not really okay to inject it into rules and collectors because the result cache might become stale

The same issue is already there for all parameters not invalidating result cache. The only problem with this one is that it may not hold actual value so it is unreliable.

@ondrejmirtes
ondrejmirtes force-pushed the error-format-dic-parameter branch from bbf6649 to 97ff54e Compare October 31, 2026 13:19
@ondrejmirtes
ondrejmirtes changed the base branch from 2.1.x to 2.3.x October 31, 2026 13:19
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.
@ondrejmirtes
ondrejmirtes force-pushed the error-format-dic-parameter branch from 97ff54e to edf4e22 Compare October 31, 2026 13:26
@ondrejmirtes

Copy link
Copy Markdown
Member

I feel like we should find another solution for this problem.

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