AbstractClassRestrictionsSniff: fix insufficient defensive coding#2500
Merged
dingo-d merged 1 commit intoOct 4, 2024
Merged
Conversation
This commit fixes the test failure seen in PR 2499. The test failure was surfaced due to a new exception in PHPCS (see: PHPCSStandards/PHP_CodeSniffer 524), which will be included in PHPCS 3.11.0. The test failure highlighted that the above mentioned PHPCS PR needs a follow-up with some extra defensive coding, however, that defensive coding is needed in a part in PHPCS which does the error handling for PHP notices being encountered, i.e. the throwing of `Internal.Exception` errors. This implied there was also an underlying issue in WPCS causing the `Internal.Exception`, which apparently was only triggered when the fixer was being run. > Note: the fact that `Internal.Exception`s during a PHPCBF run are being suppressed is a known issue, but fixing that is not that easy, so that definitely won't happen before PHPCS 4.0 (and may not even make it into 4.0). See: squizlabs/PHP_CodeSniffer 2871 Either way, I've looked into the `Internal.Exception` now. The error was as follows: ``` An error occurred during processing; checking has been aborted. The error message was: PHPCSUtils\Utils\GetTokensAsString::getString(): Argument #2 ($start) must be a stack pointer which exists in the $phpcsFile object, 8 given. The error originated in the AbstractClassRestrictionsSniff.php sniff on line 131. ``` The additional defensive coding added in this commit, fixes the issue.
Member
Author
|
Related upstream fix has also been pulled: PHPCSStandards/PHP_CodeSniffer#625 |
GaryJones
approved these changes
Oct 3, 2024
dingo-d
approved these changes
Oct 4, 2024
lesterchan
added a commit
to lesterchan/WordPress-Coding-Standards
that referenced
this pull request
Jun 8, 2025
* upstream/develop: (428 commits) Rulesets: update schema URL GH Actions: use the xmllint-validate action runner and enhance checks (WordPress#2522) AbstractFunctionParameterSniff: fix first class callables and function imports (WordPress#2518) DontExtractStandard.xml file creation (WordPress#2456) Add documentation for WordPress.NamingConventions.ValidVariableName (WordPress#2457) Remove unused variables from a few sniffs (WordPress#2514) I18nTextDomainFixer: remove unnecessary variable initialization (WordPress#2513) GH Actions: Bump codecov/codecov-action from 4 to 5 (WordPress#2510) GH Actions: PHP 8.4 has been released CS/QA: remove redundant condition GH Actions: use explicit PHPStan major Various sniffs: simplify skipping the rest of the file GH Actions: always quote variables Release checklist: add new action item AbstractClassRestrictionsSniff: fix insufficient defensive coding (WordPress#2500) ✨ New WordPress.WP.GetMetaSingle sniff (WordPress#2465) Fix typo in AbstractFunctionRestrictionsSniff::is_targetted_token() DocBlock (WordPress#2477) Fix typos (WordPress#2472) Documentation: capitalization consistency fixes (WordPress#2469) [Documentation]: WordPress.DB.PreparedSQL (WordPress#2454) ...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit fixes the test failure seen in PR #2499.
The test failure was surfaced due to a new exception in PHPCS (see: PHPCSStandards/PHP_CodeSniffer#524), which will be included in PHPCS 3.11.0.
The test failure highlighted that the above mentioned PHPCS PR needs a follow-up with some extra defensive coding, however, that defensive coding is needed in a part in PHPCS which does the error handling for PHP notices being encountered, i.e. the throwing of
Internal.Exceptionerrors.This implied there was also an underlying issue in WPCS causing the
Internal.Exception, which apparently was only triggered when the fixer was being run.Either way, I've looked into the
Internal.Exceptionnow. The error was as follows:The additional defensive coding added in this commit, fixes the issue.