vimeo / psalm

A static analysis tool for finding errors in PHP applications
https://psalm.dev
MIT License
5.54k stars 660 forks source link

Composer platform check fails in combination with default disable uopz extension #9144

Open WietseGielen opened 1 year ago

WietseGielen commented 1 year ago

The uopz extension is disabled by default from Psalm 3.4.3 due to https://github.com/vimeo/psalm/issues/1741 in commit https://github.com/vimeo/psalm/commit/9573429f1e3077ef0be85cd52eab8a94fd7bc5e4.

This results in a failing composer platform check when trying to execute Psalm (version 5.4)

wietse@64cc875fd2f7:/var/vhost$ php /var/vhost/vendor/bin/psalm
Uncaught RuntimeException: PHP Error: Composer detected issues in your platform: Your Composer dependencies require the following PHP extensions to be installed: uopz. in /var/vhost/vendor/composer/platform_check.php:40 for command with CLI args "/var/vhost/vendor/bin/psalm" in /var/vhost/vendor/vimeo/psalm/src/Psalm/Internal/ErrorHandler.php:75
Stack trace:
#0 [internal function]: Psalm\Internal\ErrorHandler::Psalm\Internal\{closure}(256, 'Composer detect...', '/var/vhost/vend...', 40)
#1 /var/vhost/vendor/composer/platform_check.php(40): trigger_error('Composer detect...', 256)
#2 /var/vhost/vendor/composer/autoload_real.php(25): require('/var/vhost/vend...')
#3 /var/vhost/vendor/autoload.php(7): ComposerAutoloaderInit26c0485e4fa17bb07e883920d9d32bd3::getLoader()
#4 /var/vhost/vendor/vimeo/psalm/src/Psalm/Internal/CliUtils.php(137): require_once('/var/vhost/vend...')
#5 /var/vhost/vendor/vimeo/psalm/src/Psalm/Internal/Cli/Psalm.php(221): Psalm\Internal\CliUtils::requireAutoloaders('/var/vhost/', false, 'vendor')
#6 /var/vhost/vendor/vimeo/psalm/src/Psalm/Internal/IncludeCollector.php(35): Psalm\Internal\Cli\Psalm::Psalm\Internal\Cli\{closure}()
#7 /var/vhost/vendor/vimeo/psalm/src/Psalm/Internal/Cli/Psalm.php(222): Psalm\Internal\IncludeCollector->runAndCollect(Object(Closure))
#8 /var/vhost/vendor/vimeo/psalm/psalm(9): Psalm\Internal\Cli\Psalm::run(Array)
#9 /var/vhost/vendor/bin/psalm(120): include('/var/vhost/vend...')
#10 {main}
(Psalm (unknown version) crashed due to an uncaught Throwable)

When I comment out the disable uopz extension in vendor/vimeo/psalm/src/Psalm/Internal/Cli/Psalm.php::L910 Psalm works as it should.

wietse@64cc875fd2f7:/var/vhost$ php /var/vhost/vendor/bin/psalm
Target PHP version: 8.1 (inferred from composer.json) Extensions enabled: simplexml (unsupported extensions: ctype, iconv, uopz)
Scanning files...
Deprecation: Psalm stubs for ext-apcu loaded using legacy way. Instead, please declare ext-apcu as dependency in composer.json or use <enableExtensions> directive in Psalm config.
Analyzing files...

------------------------------                                                  

       No errors found!       

------------------------------

Checks took 82.20 seconds and used 1,225.901MB of memory
Psalm was able to infer types for 95.1587% of the codebase

Is it an option to remove the disable uopz extension by default?
Or to add an argument to skip the platform check e.g. --skip-platform-reqs?

weirdan commented 1 year ago

As a workaround, you can run Psalm without restarting by specifying PSALM_ALLOW_XDEBUG env var: PSALM_ALLOW_XDEBUG=1 vendor/bin/psalm ...

WietseGielen commented 1 year ago

@weirdan This workaround solves the issue, thanks!