phpstan-bodyscan icon indicating copy to clipboard operation
phpstan-bodyscan copied to clipboard

vendor/tomasvotruba/phpstan-bodyscan/bin/phpstan-bodyscan.php fail to locate Composer autoloader

Open steinmb opened this issue 9 months ago • 2 comments

Testing out this tool for a talk/presentation but out of the box it fails. Not sure if this is a bug or due to config.

  • New project
  • PHP 8.4
  • PSR-4 autoload
  • PHPStan 2.0 runs as expected.
  • phpstand-bodyscan: 9a9c1c93ee09495ce0d9c94d78e3da79670c3553
./vendor/bin/phpstan-bodyscan


PHP Warning:  require_once(/Users/me/sites/talk/2025/phpbergen_202502-phpstan/vendor/tomasvotruba/phpstan-bodyscan/bin/../vendor/autoload.php): Failed to open stream: No such file or directory in /Users/me/sites/talk/2025/phpbergen_202502-phpstan/vendor/tomasvotruba/phpstan-bodyscan/bin/phpstan-bodyscan.php on line 15

Warning: require_once(/Users/me/sites/talk/2025/phpbergen_202502-phpstan/vendor/tomasvotruba/phpstan-bodyscan/bin/../vendor/autoload.php): Failed to open stream: No such file or directory in /Users/me/sites/talk/2025/phpbergen_202502-phpstan/vendor/tomasvotruba/phpstan-bodyscan/bin/phpstan-bodyscan.php on line 15
PHP Fatal error:  Uncaught Error: Failed opening required '/Users/me/sites/talk/2025/phpbergen_202502-phpstan/vendor/tomasvotruba/phpstan-bodyscan/bin/../vendor/autoload.php' (include_path='.:/opt/homebrew/Cellar/php/8.4.3/share/php/pear') in /Users/me/sites/talk/2025/phpbergen_202502-phpstan/vendor/tomasvotruba/phpstan-bodyscan/bin/phpstan-bodyscan.php:15
Stack trace:
#0 /Users/me/sites/talk/2025/phpbergen_202502-phpstan/vendor/tomasvotruba/phpstan-bodyscan/bin/phpstan-bodyscan(4): require()
#1 /Users/me/sites/talk/2025/phpbergen_202502-phpstan/vendor/bin/phpstan-bodyscan(119): include('/Users/me/...')
#2 {main}
  thrown in /Users/me/sites/talk/2025/phpbergen_202502-phpstan/vendor/tomasvotruba/phpstan-bodyscan/bin/phpstan-bodyscan.php on line 15

Fatal error: Uncaught Error: Failed opening required '/Users/me/sites/talk/2025/phpbergen_202502-phpstan/vendor/tomasvotruba/phpstan-bodyscan/bin/../vendor/autoload.php' (include_path='.:/opt/homebrew/Cellar/php/8.4.3/share/php/pear') in /Users/me/sites/talk/2025/phpbergen_202502-phpstan/vendor/tomasvotruba/phpstan-bodyscan/bin/phpstan-bodyscan.php:15
Stack trace:
#0 /Users/me/sites/talk/2025/phpbergen_202502-phpstan/vendor/tomasvotruba/phpstan-bodyscan/bin/phpstan-bodyscan(4): require()
#1 /Users/me/sites/talk/2025/phpbergen_202502-phpstan/vendor/bin/phpstan-bodyscan(119): include('/Users/me/...')
#2 {main}
  thrown in /Users/me/sites/talk/2025/phpbergen_202502-phpstan/vendor/tomasvotruba/phpstan-bodyscan/bin/phpstan-bodyscan.php on line 15
if (file_exists(__DIR__ . '/../vendor/scoper-autoload.php')) {
    // A. build downgraded package
    require_once __DIR__ . '/../vendor/scoper-autoload.php';
} else {
    // B. local repository
    require_once __DIR__ . '/../vendor/autoload.php';
}

This confuses me. Will not __DIR__ always resolve to <my local path>/vendor/tomasvotruba/phpstan-bodyscan/bin? I do not see how require_once __DIR__ . '/../vendor/autoload.php' can work.

Application seem to work as expected altering line 15 to require_once $_composer_autoload_path;

steinmb avatar Feb 03 '25 20:02 steinmb

do you run the tool from its sources, or did you install a stable release it like described in the readme?

staabm avatar Feb 14 '25 08:02 staabm

Thank you for getting back to me. This is running from commit: https://github.com/TomasVotruba/phpstan-bodyscan/commit/9a9c1c93ee09495ce0d9c94d78e3da79670c3553 testing out PHPStan 2.0 support.

steinmb avatar Feb 15 '25 00:02 steinmb