From 0144b0c5a08d43876e4ce58086a625027a935cc0 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 30 Dec 2023 01:16:04 +0100 Subject: [PATCH] CS: add the RequireExplicitBooleanOperatorPrecedence sniff to PHPCS native ruleset This commit adds the new sniff as introduced in 197 by TimWolla to the PHPCS native ruleset and fixes the few conditions which were ambiguous in this codebase. --- phpcs.xml.dist | 3 +++ .../PEAR/Sniffs/Commenting/FunctionCommentSniff.php | 8 ++++---- .../Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php | 4 ++-- src/Tokenizers/PHP.php | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index a5fa45793e..9185cd41b0 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -129,6 +129,9 @@ + + + tests/bootstrap\.php diff --git a/src/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php b/src/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php index 48ff5f254e..ee242cf6e1 100644 --- a/src/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php +++ b/src/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php @@ -60,10 +60,10 @@ public function register() public function process(File $phpcsFile, $stackPtr) { $scopeModifier = $phpcsFile->getMethodProperties($stackPtr)['scope']; - if ($scopeModifier === 'protected' - && $this->minimumVisibility === 'public' - || $scopeModifier === 'private' - && ($this->minimumVisibility === 'public' || $this->minimumVisibility === 'protected') + if (($scopeModifier === 'protected' + && $this->minimumVisibility === 'public') + || ($scopeModifier === 'private' + && ($this->minimumVisibility === 'public' || $this->minimumVisibility === 'protected')) ) { return; } diff --git a/src/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php b/src/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php index da149cae58..773d25d4f5 100644 --- a/src/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php +++ b/src/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php @@ -108,8 +108,8 @@ protected function processMemberVar(File $phpcsFile, $stackPtr) // Remove the newline after the docblock, and any entirely // empty lines before the member var. - if ($tokens[$i]['code'] === T_WHITESPACE - && $tokens[$i]['line'] === $tokens[$prev]['line'] + if (($tokens[$i]['code'] === T_WHITESPACE + && $tokens[$i]['line'] === $tokens[$prev]['line']) || ($tokens[$i]['column'] === 1 && $tokens[$i]['line'] !== $tokens[($i + 1)]['line']) ) { diff --git a/src/Tokenizers/PHP.php b/src/Tokenizers/PHP.php index 9c66d811f1..ecee80c430 100644 --- a/src/Tokenizers/PHP.php +++ b/src/Tokenizers/PHP.php @@ -1727,7 +1727,7 @@ protected function tokenize($string) || (stripos($newContent, '0b') === 0 && bindec(str_replace('_', '', $newContent)) > PHP_INT_MAX) || (stripos($newContent, '0o') === 0 && octdec(str_replace('_', '', $newContent)) > PHP_INT_MAX) || (stripos($newContent, '0x') !== 0 - && stripos($newContent, 'e') !== false || strpos($newContent, '.') !== false) + && (stripos($newContent, 'e') !== false || strpos($newContent, '.') !== false)) || (strpos($newContent, '0') === 0 && stripos($newContent, '0x') !== 0 && stripos($newContent, '0b') !== 0 && octdec(str_replace('_', '', $newContent)) > PHP_INT_MAX) || (strpos($newContent, '0') !== 0 && str_replace('_', '', $newContent) > PHP_INT_MAX))