PHPStan 'No files found to analyse' is considered a problem, even though it may be valid for certain extensions

Created on 17 April 2023, over 1 year ago
Updated 6 May 2024, 7 months ago

Problem/Motivation

When some module don't has a php code to review, this error happens:

/usr/bin/php81
/var/www/html/vendor/bin/phpstan analyse
--memory-limit=1500M --error-format=json
--configuration=/tmp/upgrade_status/deprecation_testing.neon
/var/www/html/web/modules/custom/my_module_name

Empty.

! [NOTE] No files found to analyse. [WARNING]
This will cause a non-zero exit code in PHPStan 2.0.

This issue happens on mglaman/phpstan-drupal however this use this phar vendor/phpstan/phpstan/phpstan.phar

So, I think we can add the exception a this module.

🐛 Bug report
Status

Fixed

Version

4.0

Component

Code

Created by

🇧🇴Bolivia vacho Cochabamba

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @vacho
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    7 pass
  • 🇮🇳India Sana.Neyazi

    I also observed the same issue.

  • 🇺🇸United States henokmikre

    A workaround is to just add a blank .module file in the module.

  • 🇺🇸United States alison

    @henokmikre Thanks for the workaround tip! I'm getting this "error" on Features modules that don't have any custom module code, they only have features code/config.

    (Full disclosure: I also looked at / commented on 🐛 PHPStan started to fire warnings if no file was scanned, so tests need to contain some empty mock files Fixed .)

    I was imagining that it would be nice for modules without any PHP to be skipped by PHPStan, idk what kind of a lift that is. But I don't *think* that's the proposed solution here, or? (If it's not a huge hassle, could someone explain the solution proposed here in slightly plainer language?)

  • Status changed to Needs work over 1 year ago
  • 🇬🇧United Kingdom andrewmacpherson

    This affects profiles and themes too, in addition to modules. Basically, if happens whenever an extension has no PHP files.

    You can build a very elaborate theme with lots of JS/CSS libraries and Twig templates, yet without using any PHP in a .theme file. Such a theme will run into the PHPStan problem here, with no files to analyze.

    Quick review of the MR so far (as of comment #2):

    I think the right place to check for the "No files found to analyse" situation would be in DeprecationAnalyzer::analyze(). Perhaps by examining $process->getErrorOutput(),

    I found an intriguing issue in the upstream PHPStan project: https://github.com/phpstan/phpstan/issues/9410.

    The bleeding edge PHPStan now has a "zeroFiles" configuration option, to ignore the situation where there are no files to analyze. This option was only added a couple of days ago, so it's not ready to use yet. If it becomes stable, perhaps the Upgrade Status could inject this option when it runs?

  • First commit to issue fork.
  • Pipeline finished with Success
    7 months ago
    Total: 292s
    #151108
  • 🇨🇦Canada mandclu

    I encountered this problem also, even after updating to 4.2.0. The patch didn't seem to resolve the errors either.

  • 🇭🇺Hungary Gábor Hojtsy Hungary

    I'm a bit torn on this. First, it is completely valid that no PHP code may be found in an extension. It may be only configuration and composer files shipped in an extension for example. At the same time if there were no PHP files found but they should have been, then that is an error we should report.

    That said, it is probably safer to not display this as an error or at least turn it into a warning that integrates well into the UI rather than an error dump like it is now.

    For that to happen, we do need to post-process the results, so I think that is a logical direction. However that parsing should not happen on the Drush command level like in the MR but rather where the phpstan error results are stored or processed for being stored.

  • Status changed to Needs review 7 months ago
  • 🇭🇺Hungary Gábor Hojtsy Hungary

    Proposed a solution that processes this at the IMHO right place.

  • 🇭🇺Hungary Gábor Hojtsy Hungary

    Test coverage for this is easy because we had 7 empty PHP files to work around this in the tests :D

    Re the suggestion above to not run PHPStan if there were no files, I think unless its expensive to run it, I would not avoid it. Otherwise we would need to maintain yet another list of possible PHP extensions to process in Upgrade Status, that is already built into phpstan-drupal. So I think this is fine to recognize it at the end of the result.

  • Pipeline finished with Skipped
    7 months ago
    #153613
  • Status changed to Fixed 7 months ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024