Skip to content

Commit

Permalink
Merge pull request #326 from PHPCSStandards/feature/cs-ruleset-tweak
Browse files Browse the repository at this point in the history
CS: add the RequireExplicitBooleanOperatorPrecedence sniff to PHPCS native ruleset
  • Loading branch information
jrfnl authored Feb 4, 2024
2 parents cd52283 + 0144b0c commit f61820d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
3 changes: 3 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@
<!-- Do not allow unreachable code. -->
<rule ref="Squiz.PHP.NonExecutableCode"/>

<!-- Do not allow ambiguous conditions. -->
<rule ref="Generic.CodeAnalysis.RequireExplicitBooleanOperatorPrecedence"/>

<!-- The testing bootstrap file uses string concats to stop IDEs seeing the class aliases -->
<rule ref="Generic.Strings.UnnecessaryStringConcat">
<exclude-pattern>tests/bootstrap\.php</exclude-pattern>
Expand Down
8 changes: 4 additions & 4 deletions src/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
) {
Expand Down
2 changes: 1 addition & 1 deletion src/Tokenizers/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit f61820d

Please sign in to comment.