PHPCompatibility / PHPCompatibility

PHP Compatibility check for PHP_CodeSniffer

Home Page:http://techblog.wimgodden.be/tag/codesniffer/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UTF8_encode/UTF8_decode deprecated in 8.2 but no warnings generated

ClaburGitHub opened this issue · comments

Bug Description

I'm running PHP_CodeSniffer version 3.7.2 together with PHPCompatibility 9.3.5 in the Terminal of my Mac. Most things seem to work fine but I get no warnings at all regarding that utf8_enode and utf8_decode are deprecated from PHP 8.2. I'm running it like this phpcs -p /Path/to/checked/folder --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 8.2 --ignore=/other/,/v2/

Given the following reproduction Scenario

Here is an example of code in the checked folder:

$return[utf8_encode($key)];

The issue happens when running this command:

phpcs -p /Path/to/checked/folder --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 8.2 --ignore=*/other/*,*/v2/*

... over a file containing this code:

$return[utf8_encode($key)];

I'd expect the following behaviour

That I would get warnings that utf8_encode and ut8_decode are being used in the code.

Instead this happened

No warnings generated that utf8_encode and ut8_decode are being used in the code.

Environment

Mac OS X Catalina 10.15.7, PHP 7.4.12
phpcompatibility/php-compatibility 9.3.5
phpstan/phpstan 1.10.29
rector/rector 0.17.13
squizlabs/php_codesniffer 3.7.2

Environment Answer
PHP version 7.4.12
PHP_CodeSniffer version 3.7.2
PHPCSUtils version x.y.z
PHPCompatibility version 9.3.5
Install type Composer global

@ClaburGitHub Those functions will be flagged since #1605, but the PHP 8.2 related checks are (for now) only in the develop branch.

Ok, thank you Juliette I understand. I downloaded PHPcompatilbilty now from the dev branch instead with this command:
composer require --dev phpcompatibility/php-compatibility:dev-develop

But now when I try to run this command :
phpcs -p /Path/to/checked/folder --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 8.2 --ignore=/other/,/v2/

I get an error message which I don't get with the ordinary PHPCompatibility release:
Fatal error: Uncaught Error: Class 'PHPCSUtils\Tokens\Collections' not found in /Users/MyUser/vendor/phpcompatibility/php-compatibility/PHPCompatibility/AbstractFunctionCallParameterSniff.php:78
Stack trace:
#0 /Users/MyUser/.composer/vendor/squizlabs/php_codesniffer/src/Ruleset.php(1236): PHPCompatibility\AbstractFunctionCallParameterSniff->register()
#1 /Users/MyUser/.composer/vendor/squizlabs/php_codesniffer/src/Ruleset.php(218): PHP_CodeSniffer\Ruleset->populateTokenListeners()
#2 /Users/MyUser/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php(336): PHP_CodeSniffer\Ruleset->__construct(Object(PHP_CodeSniffer\Config))
#3 /Users/MyUser/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php(72): PHP_CodeSniffer\Runner->init()
#4 /Users/MyUser/.composer/vendor/squizlabs/php_codesniffer/bin/phpcs(18): PHP_CodeSniffer\Runner->runPHPCS()
#5 {main}
thrown in /Users/MyUSer/vendor/phpcompatibility/php-compatibility/PHPCompatibility/AbstractFunctionCallParameterSniff.php on line 78

Any suggestions what's causing this for the dev version of PHPCompatibility and how to solve it?
When i go back and install the latest official release 9.3.5 it works again, but I need the PHP 8.2 compatibilty-check in the dev version.

Thanks
Clas

@ClaburGitHub Could you try using this command ?

vendor/bin/phpcs -p /Path/to/checked/folder --standard=PHPCompatibility --runtime-set testVersion 8.2 --ignore=/other/,/v2/

The develop version (and v 10.0.0 for that matter) has two extra dependencies, one of which will automatically "install" (register) PHPCompatibility (and the PHPCSUtils dependency) with PHPCS.

That does mean you cannot mix using a global PHPCS install with a local PHPCompatibility install anymore as the global PHPCS install won't know about the PHPCSUtils dependency.

If you (also) install PHPCompatibility with Composer globally, that would be different (of course).

Another option would be to tell PHPCS about both on the command-line (should work, but I haven't tested this):

phpcs -p /Path/to/checked/folder --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility,vendor/phpcsstandards/phpcsutils --runtime-set testVersion 8.2 --ignore=/other/,/v2/

Thank you Juliette! It seems to be working fine running the dev-version with the command you suggested:
vendor/bin/phpcs -p /Path/to/checked/folder --standard=PHPCompatibility --runtime-set testVersion 8.2 --ignore=/other/,/v2/

I get no dependencies errors now and the PHP 8.2 incompatibilities like for example utf_encode/decode show up in the result as warnings (or errors).

Thanks! :-)
/Clas

@ClaburGitHub Happy to hear that! Does this mean we can close this issue ?

@jrfnl Yes, I think we can close this issue. Thanks again 👍