PHPCompatibility / PHPCompatibility

PHP Compatibility check for PHP_CodeSniffer
http://techblog.wimgodden.be/tag/codesniffer/
GNU Lesser General Public License v3.0
2.16k stars 193 forks source link

Do not report deprecations as errors #1678

Closed javaDeveloperKid closed 6 months ago

javaDeveloperKid commented 6 months ago

Is your feature request related to a problem?

I use an external package that autogenerates the code and that code must be compatibile with PHP 7.1-8.1. It generates some code that is deprecated but it's working fine so I don't want exit code 1. I couldn't find the information how to achieve this in the README file (I assume this is the only package documentation).

Describe the solution you'd like

We could add option to toggle how deprecated code is treated. E.g. --deprecations-as-errors=false

Additional context (optional)

jrfnl commented 6 months ago

@javaDeveloperKid Deprecations do not shown as errors, but as warnings. This is by design.

This allows for using the PHP_CodeSniffer native functionality to influence the exit code/whether these warnings are shown:

In both cases, if there are also errors, PHPCS will still exit on 1.

Run phpcs -h for more info on options available or have a look at the Wiki

In other words, you are asking for a feature which is already available.

javaDeveloperKid commented 6 months ago

Thank you for the exhausted explanation. I've just tried this option and it still returns exit code 1. However I think I know what's going on. Given

$ /vendor/bin/phpcs -p --standard=PHPCompatibility --runtime-set ignore_warnings_on_exit 1 --runtime-set testVersion 7.2- -- src/
FILE: MyClass.php
--------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------------
 181 | ERROR | Using "parent" inside a class without parent is deprecated since PHP 7.4
--------------------------------------------------------------------------------------------------------

I've just checked and it's a fatal error in PHP 8 so reported error level is fine. I misunderstood the error message. It says deprecated but it doesn't say removed. I think we should be explicit about this information. Especially in PHP where semantic versioning is not always followed.

jrfnl commented 6 months ago

@javaDeveloperKid Yes, that was a bug. The message for that sniff has been updated for the next release to ensure that it shows a warning when the code under scan doesn't need to support PHP 8.0+ and an error (with an updated message) when PHP 8.0+ does need to be supported. See #1156

javaDeveloperKid commented 6 months ago

Ok. I think I will switch to develop branch as the latest ^9.0 was released in 2019 so I bet that develop branch is much richer after 4 years :slightly_smiling_face: