Skip to content

Commit

Permalink
PHP 8.0 | Squiz/IncrementDecrementUsage: allow for nullsafe object op…
Browse files Browse the repository at this point in the history
…erator

Includes unit test.

Note: there is quite a lot more which can do with improvement in this sniff, as the sniff is not code style independent, nor does it take all allowed syntaxes into account, such as array in/decrementing `$a[0]++` or nested property in/decrementing `--$obj->prop->nested` and more along those lines, but that's outside the scope of this PR.
  • Loading branch information
jrfnl committed Sep 1, 2020
1 parent 85f3521 commit 616eb38
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ protected function processIncDec($phpcsFile, $stackPtr)
// start looking for other operators.
if ($tokens[($stackPtr - 1)]['code'] === T_VARIABLE
|| ($tokens[($stackPtr - 1)]['code'] === T_STRING
&& $tokens[($stackPtr - 2)]['code'] === T_OBJECT_OPERATOR)
&& ($tokens[($stackPtr - 2)]['code'] === T_OBJECT_OPERATOR
|| $tokens[($stackPtr - 2)]['code'] === T_NULLSAFE_OBJECT_OPERATOR))
) {
$start = ($stackPtr + 1);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ $var = (1 + $var);
$expected[$i]['sort_order'] = ($i + 1);
$expected[($i + 1)]['sort_order'] = ($i + 1);

$id = $id.($this->i++).$id;
$id = $id.($obj->i++).$id;
$id = $obj?->i++.$id;
$id = $obj?->i++*10;
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public function getErrorList()
27 => 1,
29 => 1,
31 => 1,
41 => 1,
42 => 1,
];

}//end getErrorList()
Expand Down

0 comments on commit 616eb38

Please sign in to comment.