From eeee4e6722518597ed4d27c2c143c56537480e48 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 21 Jul 2023 00:30:27 +0200 Subject: [PATCH] PHP 8.3 | Generic/ScopeIndent: bug fix - missing defensive coding As of PHP 8.3, PHP will throw a `Warning: Decrement on type bool has no effect, this will change in the next major version of PHP` notice. A test run with PHP 8.3 showed this deprecation notice being thrown in the `Generic.WhiteSpace.ScopeIndent` sniff. Investigation of the notice showed that this was actually a bug due to too little defensive coding. The sniff tries to skip over multi-line/multi-token text strings, but the `findNext()` will return `false` for a single-line/single-token text string, which would lead to `$i` being reset to `0`. This commit fixes this by only changing `$i` when the return from the call to `findNext()` is not `false`. Ref: https://wiki.php.net/rfc/saner-inc-dec-operators --- .../Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php b/src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php index 17e9c7d7b4..7789a7a915 100644 --- a/src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php +++ b/src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php @@ -1090,8 +1090,11 @@ public function process(File $phpcsFile, $stackPtr) if ($tokens[$i]['code'] === T_CONSTANT_ENCAPSED_STRING || $tokens[$i]['code'] === T_DOUBLE_QUOTED_STRING ) { - $i = $phpcsFile->findNext($tokens[$i]['code'], ($i + 1), null, true); - $i--; + $nextNonTextString = $phpcsFile->findNext($tokens[$i]['code'], ($i + 1), null, true); + if ($nextNonTextString !== false) { + $i = ($nextNonTextString - 1); + } + continue; }