We’re trying to integrate report from PHPStan into Sonarqube. I added into my repo file “sonar-project.properties” and there I defined “sonar.php.phpstan.reportPaths=report.json”. In sonarqube GUI I see error: “No issue will be imported from this report. The content of the file probably does not have the expected format”
I tried both format. There is an example of json output, but I still getting error: “Failed to resolve 220 file path(s) in PHPStan gl-code-quality-report__3_.json report. No issues imported related to file(s): /var/www/html/legacy/admin/core.php;/var/www/html/legacy/admin/index.php”
Do you have any idea, why SonarQube cannot resolve these path?
I also tried that report you sent, but still getting error: “Failed to resolve 1 file path(s) in PHPStan phpstan2.json report. No issues imported related to file(s): src/Greeter.php”
I can reproduce the same issue. By changing the filepath in the report to start from the directory the scanner executes I can get the issues to import successfully… but I don’t think you should have to do that. I’ve raised a point internally.
Based on the filename of your PHPStan report (gl-code-quality-report__3_.json) I assume you are running this in the context of a GitLab CI job – is that correct? Can you share your gitlab-ci.yml?
Thank you for your detailed explanation and cooperation. The problem seems to be the mismatch of the fully qualified paths, as you have already noted. This circumstance comes from the GitLab build environments. Unfortunately, only fully qualified paths are specified in the JSON output of PHPStan. We decided to add a mechanism that matches and adjusts paths from external reports and SonarQube internal paths, similar to what you described with “path correction”.
To address the problem I have created the ticket SONARPHP-1282.