The Drupal.Formatting.SpaceUnaryOperator.IncDecRight sniffer can cause syntax error.

Checking a php file with the following content will result in this validation error for the two lines using post increment and post decrement: "A unary operator statement must not be followed by a single space"

<?php

namespace Test;

/**
 * Class Test.
 */
class Test {
  private $prop = 0;

  /**
   * Test constructor.
   */
  public function __construct() {
    $this->prop++;
    $this->prop--;
    --$this->prop;
    ++$this->prop;
  }

}

It's even worse, that the fixer "fixes" these violations by removing the ; and the new line character after.
Running the fixer results this file:

<?php

namespace Test;

/**
 * Class Test.
 */
class Test {
  private $prop = 0;

  /**
   * Test constructor.
   */
  public function __construct() {
    $this->prop++$this->prop--$this->prop;
    ++$this->prop;
  }

}

Comments

smatyas created an issue. See original summary.

smatyas’s picture

  • klausi committed dd6979b on 8.x-2.x
    Issue #2617904: Fixed increment/decrement operator sniff with object...
klausi’s picture

Status: Active » Fixed

Committed a fix, thanks for reporting!

smatyas’s picture

Thanks for the fix @klausi just one question: doesn't this repo use auto-update for the packagest package? It seems to be out of sync. The current version for 8.x-2.x shows the hash 363f5ab269b0f93e4f3ffbb2e369b055a017b2bd from 2015-11-08 21:22 UTC - https://packagist.org/packages/drupal/coder#dev-8.x-2.x

git status sais there are 14 commits since (including this one):

vendor/drupal/coder (8.x-2.x) $ git status
On branch 8.x-2.x
Your branch is behind 'origin/8.x-2.x' by 14 commits, and can be fast-forwarded.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.