Skip to content

Commit 0144b0c

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 cd52283 commit 0144b0c

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

phpcs.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
<!-- Do not allow unreachable code. -->
130130
<rule ref="Squiz.PHP.NonExecutableCode"/>
131131

132+
<!-- Do not allow ambiguous conditions. -->
133+
<rule ref="Generic.CodeAnalysis.RequireExplicitBooleanOperatorPrecedence"/>
134+
132135
<!-- The testing bootstrap file uses string concats to stop IDEs seeing the class aliases -->
133136
<rule ref="Generic.Strings.UnnecessaryStringConcat">
134137
<exclude-pattern>tests/bootstrap\.php</exclude-pattern>

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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1727,7 +1727,7 @@ protected function tokenize($string)
17271727
|| (stripos($newContent, '0b') === 0 && bindec(str_replace('_', '', $newContent)) > PHP_INT_MAX)
17281728
|| (stripos($newContent, '0o') === 0 && octdec(str_replace('_', '', $newContent)) > PHP_INT_MAX)
17291729
|| (stripos($newContent, '0x') !== 0
1730-
&& stripos($newContent, 'e') !== false || strpos($newContent, '.') !== false)
1730+
&& (stripos($newContent, 'e') !== false || strpos($newContent, '.') !== false))
17311731
|| (strpos($newContent, '0') === 0 && stripos($newContent, '0x') !== 0
17321732
&& stripos($newContent, '0b') !== 0 && octdec(str_replace('_', '', $newContent)) > PHP_INT_MAX)
17331733
|| (strpos($newContent, '0') !== 0 && str_replace('_', '', $newContent) > PHP_INT_MAX))

0 commit comments

Comments
 (0)