Skip to content

Commit e78cd2e

Browse files
committed
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.
1 parent 92cefb2 commit e78cd2e

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

phpcs.xml.dist

+3
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@
134134
<!-- Do not allow unreachable code. -->
135135
<rule ref="Squiz.PHP.NonExecutableCode"/>
136136

137+
<!-- Do not allow ambiguous conditions. -->
138+
<rule ref="Generic.CodeAnalysis.RequireExplicitBooleanOperatorPrecedence"/>
139+
137140
<!-- The testing bootstrap file uses string concats to stop IDEs seeing the class aliases -->
138141
<rule ref="Generic.Strings.UnnecessaryStringConcat">
139142
<exclude-pattern>tests/bootstrap\.php</exclude-pattern>

src/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ public function register()
6060
public function process(File $phpcsFile, $stackPtr)
6161
{
6262
$scopeModifier = $phpcsFile->getMethodProperties($stackPtr)['scope'];
63-
if ($scopeModifier === 'protected'
64-
&& $this->minimumVisibility === 'public'
65-
|| $scopeModifier === 'private'
66-
&& ($this->minimumVisibility === 'public' || $this->minimumVisibility === 'protected')
63+
if (($scopeModifier === 'protected'
64+
&& $this->minimumVisibility === 'public')
65+
|| ($scopeModifier === 'private'
66+
&& ($this->minimumVisibility === 'public' || $this->minimumVisibility === 'protected'))
6767
) {
6868
return;
6969
}

src/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ protected function processMemberVar(File $phpcsFile, $stackPtr)
108108

109109
// Remove the newline after the docblock, and any entirely
110110
// empty lines before the member var.
111-
if ($tokens[$i]['code'] === T_WHITESPACE
112-
&& $tokens[$i]['line'] === $tokens[$prev]['line']
111+
if (($tokens[$i]['code'] === T_WHITESPACE
112+
&& $tokens[$i]['line'] === $tokens[$prev]['line'])
113113
|| ($tokens[$i]['column'] === 1
114114
&& $tokens[$i]['line'] !== $tokens[($i + 1)]['line'])
115115
) {

src/Tokenizers/PHP.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ protected function tokenize($string)
14851485
|| (stripos($newContent, '0b') === 0 && bindec(str_replace('_', '', $newContent)) > PHP_INT_MAX)
14861486
|| (stripos($newContent, '0o') === 0 && octdec(str_replace('_', '', $newContent)) > PHP_INT_MAX)
14871487
|| (stripos($newContent, '0x') !== 0
1488-
&& stripos($newContent, 'e') !== false || strpos($newContent, '.') !== false)
1488+
&& (stripos($newContent, 'e') !== false || strpos($newContent, '.') !== false))
14891489
|| (strpos($newContent, '0') === 0 && stripos($newContent, '0x') !== 0
14901490
&& stripos($newContent, '0b') !== 0 && octdec(str_replace('_', '', $newContent)) > PHP_INT_MAX)
14911491
|| (strpos($newContent, '0') !== 0 && str_replace('_', '', $newContent) > PHP_INT_MAX))

0 commit comments

Comments
 (0)