Suppress PHPCS auto_detect_line_endings deprecation notice#1371
Suppress PHPCS auto_detect_line_endings deprecation notice#1371GeorgeWebDevCy wants to merge 1 commit into
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Instead of suppressing may be we should explore why it is coming. |
|
Thanks, I explored that path. What I found:
So this PR keeps the workaround narrowly scoped to the PHPCS runner call and only swallows this exact PHPCS deprecation from |
There was a problem hiding this comment.
Pull request overview
This pull request addresses a PHP 8.4+ deprecation notice (auto_detect_line_endings is deprecated) emitted by PHP_CodeSniffer during Plugin Check’s PHPCS-backed checks, by temporarily intercepting that specific deprecation while PHPCS runs and validating the behavior via a regression test.
Changes:
- Register a temporary error handler around PHPCS execution to suppress the specific
auto_detect_line_endingsdeprecation originating from PHPCS’sRunner.php. - Restore the prior error handler after PHPCS completes.
- Add a PHPUnit regression test that installs an outer error handler which would throw if the deprecation leaks through.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| includes/Checker/Checks/Abstract_PHP_CodeSniffer_Check.php | Adds a scoped error handler around PHPCS execution to suppress the targeted deprecation and restore prior handling afterward. |
| tests/phpunit/tests/Checker/Checks/Plugin_Review_PHPCS_Check_Tests.php | Adds a regression test to ensure the PHPCS deprecation does not leak through an outer error handler. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -118,6 +120,8 @@ final public function run( Check_Result $result ) { | |||
| } catch ( Exception $e ) { | |||
| $_SERVER['argv'] = $orig_cmd_args; | |||
| throw $e; | |||
| } finally { | |||
| restore_error_handler(); | |||
| } | |||
| set_error_handler( | ||
| static function ( $errno, $errstr, $errfile, $errline ) { | ||
| if ( E_DEPRECATED === $errno && false !== strpos( $errstr, 'auto_detect_line_endings is deprecated' ) ) { | ||
| throw new ErrorException( $errstr, 0, $errno, $errfile, $errline ); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| ); |
Summary
auto_detect_line_endings is deprecatednotice while PHPCS runs.Fixes #1368.
Testing
php -l includes/Checker/Checks/Abstract_PHP_CodeSniffer_Check.phpphp -l tests/phpunit/tests/Checker/Checks/Plugin_Review_PHPCS_Check_Tests.phpvendor/bin/phpcs --standard=phpcs.xml.dist includes/Checker/Checks/Abstract_PHP_CodeSniffer_Check.php tests/phpunit/tests/Checker/Checks/Plugin_Review_PHPCS_Check_Tests.phpauto_detect_line_endings is deprecated:errors=0 warnings=0