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

Errors are not shown with baseline file and output-format=compact #10875

Open
andrey-tech opened this issue Apr 2, 2024 · 3 comments
Open

Errors are not shown with baseline file and output-format=compact #10875

andrey-tech opened this issue Apr 2, 2024 · 3 comments

Comments

@andrey-tech
Copy link

Hi!

I have a problem with Psalm v5.23.1 and PHP 8.1: new errors are NOT SHOWN in the console if I use baseline file and output-format=compact (other output formats - OK). Please check and fix!

Description

  1. Example with option --output-format=compact — new errors are NOT SHOWN in the console, but Psalm exit code is 2:
vendor/bin/psalm --config=psalm.xml.dist --output-format=compact --use-baseline=psalm-baseline.xml src/Kernel.php

Target PHP version: 8.1 (set by config file) Enabled extensions: dom, mongodb, pdo, simplexml, soap (unsupported extensions: fileinfo, zend-opcache).          
Scanning files...
Analyzing files...

░
FILE: src/Kernel.php
  1. Example without option --output-format all new errors are SHOWN in the console and Psalm exit code is 2:
vendor/bin/psalm --config=psalm.xml.dist --use-baseline=psalm-baseline.xml src/Kernel.php         

Target PHP version: 8.1 (set by config file) Enabled extensions: dom, mongodb, pdo, simplexml, soap (unsupported extensions: fileinfo, zend-opcache).
Scanning files...
Analyzing files...

░

To whom it may concern: Psalm cannot detect unused classes, methods and properties
when analyzing individual files and folders. Run on the full project to enable
complete unused code detection.

ERROR: InvalidReturnType - src/Kernel.php:43:36 - The declared return type 'int' for App\Kernel::getCacheDir is incorrect, got 'non-falsy-string' (see https://psalm.dev/011)
    public function getCacheDir(): int


ERROR: InvalidReturnStatement - src/Kernel.php:45:16 - The inferred type 'non-falsy-string' does not match the declared return type 'int' for App\Kernel::getCacheDir (see https://psalm.dev/128)
        return '/tmp/cache/' . $this->environment;

------------------------------
2 errors found
------------------------------
10 other issues found.
You can display them with --show-info=true
------------------------------
Psalm can automatically fix 1 of these issues.
Run Psalm again with
--alter --issues=InvalidReturnType --dry-run
to see what it can fix.
------------------------------

Checks took 2.58 seconds and used 227.321MB of memory
Psalm was able to infer types for 90.6667% of the codebase
Copy link

Hey @andrey-tech, can you reproduce the issue on https://psalm.dev? These will be used as phpunit tests when implementing the feature or fixing this bug.

@andrey-tech
Copy link
Author

Hey @psalm-github-bot, I can't reproduce the issue on psalm.dev, because this is a console options issue.

@andrey-tech
Copy link
Author

The problem in class \Psalm\Report\CompactReport:

76            // If we're at the end of the issue sets, then wrap up the last table and render it out.
77            if ($i === count($this->issues_data) - 1) {
78                $table->render();
79                $output[] = $buffer->fetch();
80            }

The condition inside this if will never be true if array $this->issues_data has non-sequential integer keys, so $table->render() will not be executed.

For example, if baseline file is used, then $this->issues_data is:

Array
(
    [9] => Psalm\Internal\Analyzer\IssueData Object(...)
    [10] => Psalm\Internal\Analyzer\IssueData Object(...)
)

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

No branches or pull requests

1 participant