Skip to content

Commit

Permalink
Fix ternary operator + negative numbers.
Browse files Browse the repository at this point in the history
A few uses in CakePHP were failing because of this rule
not being accurate.
  • Loading branch information
markstory committed Apr 27, 2012
1 parent aa274f2 commit 112ba26
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Sniffs/WhiteSpace/OperatorSpacingSniff.php
Expand Up @@ -156,13 +156,22 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
return;
}
}

if (
($prev !== false && $tokens[$prev]['code'] === T_CASE) &&
$tokens[$semi]['code'] === T_COLON
) {
// Inside a case statement
return;
}

if (
$prev !== false && in_array($tokens[$prev]['code'], array(T_INLINE_THEN)) &&
$tokens[$semi]['code'] === T_COLON
) {
// Inside a ternary op.
return;
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions tests/files/operator_spacing_pass.php
@@ -0,0 +1,9 @@
<?php
$foo = -1;

switch($foo) {
case -1:
break;
}
$bar = isset($foo) ? -2 : 0;
$ten = 10 * 2;

0 comments on commit 112ba26

Please sign in to comment.