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

Cannot get stats when output format is not console #9789

Open
AndreyMZ opened this issue May 14, 2023 · 2 comments
Open

Cannot get stats when output format is not console #9789

AndreyMZ opened this issue May 14, 2023 · 2 comments

Comments

@AndreyMZ
Copy link

Problem description

Psalm can output some interesting statistics like:

Checks took 1.02 seconds and used 54.968MB of memory
Psalm was able to infer types for 100% of the codebase

and even more statistics with the options --stats and/or --debug-performance.

But:

  1. It can output it only when --output-format is console or phpstorm.
  2. It can output it only to stdout.

So, in the case when one needs to have the report in other format (e.g. --output-format=json), he/she cannot get the statistics.

Root cause

if (in_array(
$project_analyzer->stdout_report_options->format,
[Report::TYPE_CONSOLE, Report::TYPE_PHP_STORM],
)) {

Workaround

Run with the options --report=report.json --output-format=console and save both the report file and the stdout.

Cons:

  1. Code issues printed to stdout are redundant.
  2. Psalm needs write access to the file system to write the report into a separate file instead of stdout. This may create problems, for example if you run Psalm in a Docker container.

Possible solution

Write the statistics to stderr instead of stdout regardless of the --output-format. The stdout should be a place for code issue only (whether human-readable or machine-readable). The stderr may be a place for log, progress, statistics, etc.

@psalm-github-bot
Copy link

Hey @AndreyMZ, can you reproduce the issue on https://psalm.dev ?

@AndreyMZ
Copy link
Author

AndreyMZ commented May 14, 2023

No, I cannot. Stupid bot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants