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

Do not report deprecations as errors

javaDeveloperKid opened this issue · comments

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)

  • I intend to create a pull request to implement this feature.

@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:

  • -n will silence all warnings (not show them at all nor use them to determine the exit code)
  • --runtime-set ignore_warnings_on_exit 1 will show the deprecation notices, but will not exit on 1 for warnings (=deprecations).

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.

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.

@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

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 🙂