wongjn / vscode-php-sniffer

Visual Studio Code extension for PHP_Codesniffer validation and formatting.
https://marketplace.visualstudio.com/items?itemName=wongjn.php-sniffer
MIT License
46 stars 7 forks source link

PHP Sniffer complains about php version even though needed php version is there #58

Closed finn-matti closed 2 years ago

finn-matti commented 3 years ago

Describe the bug PHP Sniffer complains about a wrong config, specifically the php version, although the right is present. Error:

Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0". You are running 7.3.24-(to be removed in future macOS). in /Users/mhaehnel/.composer/vendor/composer/platform_check.php on line 24

The right php is installed:

php -i
phpinfo()
PHP Version => 8.0.8
...

PHP is installed through phpbrew:

which -a php
/Users/mhaehnel/.phpbrew/php/php-8.0.8/bin/php
/usr/bin/php

And the right php is also in my path first:

echo $PATH
/Users/mhaehnel/.composer/vendor/bin/:/Users/mhaehnel/bin/:/Users/mhaehnel/.phpbrew/php/php-8.0.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

To be clear. This message doesn't always appear, but is in any case wrong.

Screen Shot 2021-09-06 at 18 24 47

To Reproduce Not sure yet. Especially since it doesn't consistently happen. But I'm happy to investigate.

Expected behavior No error.

Environment

Extension settings

{
    "phpSniffer.run": "onSave",
    "phpSniffer.onTypeDelay": 250,
    "phpSniffer.executablesFolder": "",
    "phpSniffer.autoDetect": false,
    "phpSniffer.standard": "PSR12",
    "phpSniffer.snippetExcludeSniffs" : [],
}
finn-matti commented 3 years ago

Oh I should also point out, that a restart generally seems to fix the issue.

wongjn commented 3 years ago

Does running the commands phpcbf and phpcs multiple times produce the error? How about running the commands after the error shows up in VSCode? Might be something funky happening with a dependency somewhere that needs a certain code path for the error to trigger 🤔

jvega commented 3 years ago

same issue for me, but I don't understand why phpcs binary needs to check composer config

also I use phpbrew and overwrite the OSX php native version with brew install php@7.4 and brew link php@7.4 --force --overwrite so WHY still vscode found the php native version??

BTW my workaround is setting "platform-check": false at composer.json

finn-matti commented 3 years ago

Does running the commands phpcbf and phpcs multiple times produce the error? How about running the commands after the error shows up in VSCode?

I'm not exactly sure how you meant this. But I ran into the problem again and ran phpcbf and phpcs in vs code's terminal three times each, without producing this error.

$ phpcs
ERROR: You must supply at least one file or directory to process.

Run "phpcs --help" for usage information
$ phpcbf
ERROR: You must supply at least one file or directory to process.

Run "phpcbf --help" for usage information
n18l commented 2 years ago

I think this is actually caused by the way macOS handles new terminal sessions, including those spawned by VSCode. Long story short, I previously fixed this issue by adding the following to my settings.json:

"terminal.integrated.inheritEnv": false

You can read a little bit more about this in the VSCode docs and see the same issue over in the VSCode repo.

wongjn commented 2 years ago

Thank you for that information, I'll take this as the work-around.