Skip to content

Commit

Permalink
PHP 8.0 | Squiz/DisallowMultipleAssignments: correct errorcode for as…
Browse files Browse the repository at this point in the history
…signment in match expression

The `Squiz.PHP.DisallowMultipleAssignments` sniff differentiates in the error code between "normal" assignments which aren't the only thing on a line and assignments in control structure conditions.

This adds `match` to the list of control structures, so it gets the correct error code.

Includes unit test.
  • Loading branch information
jrfnl committed Feb 23, 2021
1 parent 8b0137a commit 87bc198
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public function process(File $phpcsFile, $stackPtr)
T_SWITCH => T_SWITCH,
T_CASE => T_CASE,
T_FOR => T_FOR,
T_MATCH => T_MATCH,
];
foreach ($nested as $opener => $closer) {
if (isset($tokens[$opener]['parenthesis_owner']) === true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,15 @@ class Bar
public bool $c = false, $d = true;
protected int $e = 123, $f = 987;
}

switch ($b < 10 && $a = 10) {
case true:
break;
}

$array = [
match ($b < 10 && $a = 10) {
true => 10,
false => 0
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public function getErrorList()
12 => 1,
14 => 1,
15 => 1,
79 => 1,
85 => 1,
];

}//end getErrorList()
Expand Down

0 comments on commit 87bc198

Please sign in to comment.