Skip to content

Commit

Permalink
Merge pull request #136 from PHPCSStandards/universal/disallowstandal…
Browse files Browse the repository at this point in the history
…onepostincdec-use-objoperators-method

DisallowStandalonePostIncrementDecrement: prevent looking for nullsafe object operator
  • Loading branch information
jrfnl committed Oct 25, 2022
2 parents 6c59982 + b74734d commit 7e1cae2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public function register()
$this->allowedTokens += Collections::objectOperators();
$this->allowedTokens += Collections::namespacedNameTokens();

/*
* Remove potential nullsafe object operator. In/decrement not allowed in write context,
* so ignore.
*/
unset($this->allowedTokens[\T_NULLSAFE_OBJECT_OPERATOR]);

return Collections::incrementDecrementOperators();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,8 @@ $a = 10 + $i++ - 5;

return $a['key'][$i++];

// Intentional parse error. Nullsafe operator not allowed in write-context. Ignore.
$obj?->prop++;

// Intentional parse error.
++;
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,8 @@ $a = 10 + $i++ - 5;

return $a['key'][$i++];

// Intentional parse error. Nullsafe operator not allowed in write-context. Ignore.
$obj?->prop++;

// Intentional parse error.
++;

0 comments on commit 7e1cae2

Please sign in to comment.