Skip to content

Commit

Permalink
Handle class syntax in UnaryOperatorsSniff (#181)
Browse files Browse the repository at this point in the history
closes GH-179
  • Loading branch information
mmoll authored and djoos committed Jan 22, 2020
1 parent 88bc24b commit 78e3b0b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Symfony/Sniffs/ControlStructure/UnaryOperatorsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

if (T_CLASS === $tokens[$stackPtr + 1]['code']
|| T_SELF === $tokens[$stackPtr + 1]['code']
) {
return;
}

if ((T_VARIABLE !== $tokens[$stackPtr - 1]['code']
&& T_VARIABLE !== $tokens[$stackPtr + 1]['code'])
&& (T_OBJECT_OPERATOR !== $tokens[$stackPtr - 2]['code'])
Expand Down
34 changes: 33 additions & 1 deletion Symfony/Tests/ControlStructure/UnaryOperatorsUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,36 @@ $a[0] --;

++ $a[0];

-- $a[0];
-- $a[0];

++Class::$v;

--Class::$v;

Class::$v++;

Class::$v--;

++ Class::$v;

-- Class::$v;

Class::$v ++;

Class::$v --;

++self::$v;

--self::$v;

self::$v++;

self::$v--;

++ self::$v;

-- self::$v;

self::$v ++;

self::$v --;
8 changes: 8 additions & 0 deletions Symfony/Tests/ControlStructure/UnaryOperatorsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ public function getErrorList()
45 => 1,
47 => 1,
49 => 1,
59 => 1,
61 => 1,
63 => 1,
65 => 1,
75 => 1,
77 => 1,
79 => 1,
81 => 1,
);
}

Expand Down

0 comments on commit 78e3b0b

Please sign in to comment.