joomla/coding-standards

Operator Spacing Sniff Not Ignore Minus Operator in Conditional Statements

deminy opened this issue · 3 comments

$query->bind(':' . count($values), $values[$index], self::getType($v), is_string($v) ? strlen($v) : -1);

Above code throws out following error when running PHPCS using the Joomla coding standards:

Expected 1 space after "-"; 0 found

A temporary solution is to change the code to:

$query->bind(':' . count($values), $values[$index], self::getType($v), is_string($v) ? strlen($v) : (-1));

A previous fix ( http://drupal.org/node/1759346 ) can be used to validate following code properly:

$a = true ? -1 : 1;

However, the fix doesn't work for following code:

$a = true ? 1 : -1;

If we resync our sniff with the Squiz one, the issues with the minus sign go away. But, this line will still fail with Expected 1 space after "+"; 0 found:

$inc = ($this->getTask() == 'orderup') ? -1 : +1;

I believe this is fixed in the PHPCS-2 branch. I'll double check later today.

I can confirm that this issue is fixed in the PHPCS-2 branch, as such this issue can be closed.