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

PHPCompatibility used with php_codesniffer 3.9 seems not taking into account the target PHP 8.3

philprl opened this issue · comments

Bug Description

Warnings about deprecated features or removed obsolete functionnalities of PHP code seem to be not reported with php_codesniffer 3.9 using standard PHPCompatibilty on target PHP 8.3.
None warning PHP 8.3 is given by the followng command:
phpcs "C:\path_to_PHP_code" --extensions=php --standard=PHPCompatibility --runtime-set testVersion 8.3
N.B.:
I don't know if that it is a bug or a problem of upgrade php_codesniffer from 2.7 to 9.3 version.

Given the following reproduction Scenario

...
$ldapHost = "ldap://annuaire.sesam-vitale.fr";
$ldapPort = 389;
$ds = ldap_connect($ldapHost,$ldapPort);
...

The issue happens when running this command:

phpcs  file.php --extensions=php --standard=PHPCompatibility --runtime-set testVersion 8.3-

... over a file containing this code:

global ${$var};

$ldapHost = "ldap://annuaire.test.com";
$ldapPort = 389;
$ds = ldap_connect($ldapHost,$ldapPort);

I'd expect the following behaviour

FILE: file.php

FOUND 0 ERRORS AND 2 WARNING AFFECTING 2 LINES

2 | WARNING | Global with anything other than bare variables is discouraged since PHP 7.0. Found ${$var}
6 | WARNING | Usage of ldap_connect with two arguments is deprecated

These two lignes of warning about deprecated code are expected.

Instead this happened

FILE: file.php

FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE

2 | WARNING | Global with anything other than bare variables is discouraged since PHP 7.0. Found ${$var}

What is the current (buggy) behavior?
Only the warning about deprecated code since PHP 7.1 on line 2 of file.php is reported,
the warning about deprecated code (on ldap_connect since PHP 8.3) at line 6 of file.php is not reported

Environment

composer
Composer version 2.7.1

Environment Answer
PHP version 8.3.1
PHP_CodeSniffer version 3.9.0
PHPCSUtils version 1.0.9
PHPCompatibility version 9.3.5
Install type Composer (global)

Additional Context (optional)

When testing PHP code that was written in PHP 7.4 using PHP_CodeSniffer 2.7 with PHPCompatibility on target PHP 8.1, the problem was not encountered: warnings on deprecated code PHP 7.4 were well reported

Tested Against develop branch?

  • I have verified the issue still exists in the develop branch of PHPCompatibility.

PHPCompatibility 9.3.5 was released in Dec 2019, so doesn't contain that check yet. See #1284 for context about why we haven't released 10.0.0 yet.

In the mean time, closing as invalid.

This issue is already detected since PR #1620 which is included in the develop branch:

------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
------------------------------------------------------------------------------------------------------------------------------------------------------
 3 | WARNING | Global with anything other than bare variables is discouraged since PHP 7.0. Found ${$var}
   |         | (PHPCompatibility.Variables.ForbiddenGlobalVariableVariable.NonBareVariableFound)
 7 | WARNING | Calling ldap_connect() with two parameters is deprecated since PHP 8.3. Call ldap_connect() with an LDAP-URI as the first (and only)
   |         | parameter instead. (PHPCompatibility.ParameterValues.RemovedLdapConnectSignatures.DeprecatedTwoParamSignature)
------------------------------------------------------------------------------------------------------------------------------------------------------

If you need help using the develop branch, see: #1306