Skip to content

Commit

Permalink
PHP 8.0 | PSR2/PSR12/ControlStructureSpacing: check match expressions
Browse files Browse the repository at this point in the history
This adds support for checking the spacing inside single line conditions for `match` expressions to the PSR2 sniff and by extension to the PSR12 sniff, as well as explicitly for multiline conditions to the PSR12 sniff.

Includes unit tests.
  • Loading branch information
jrfnl committed Feb 23, 2021
1 parent b52a018 commit 6023ed6
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function register()
T_ELSE,
T_ELSEIF,
T_CATCH,
T_MATCH,
];

}//end register()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,17 @@ EOD
) {
break;
}

match (
$expr1 &&
$expr2 &&
$expr3
) {
// structure body
};

match ($expr1 &&
$expr2 &&
$expr3) {
// structure body
};
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,19 @@ EOD
) {
break;
}

match (
$expr1 &&
$expr2 &&
$expr3
) {
// structure body
};

match (
$expr1 &&
$expr2 &&
$expr3
) {
// structure body
};
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public function getErrorList()
48 => 2,
58 => 1,
59 => 1,
92 => 1,
96 => 1,
97 => 1,
98 => 2,
];

}//end getErrorList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function register()
T_ELSE,
T_ELSEIF,
T_CATCH,
T_MATCH,
];

}//end register()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,14 @@ if ($expr1
&& $expr2
/* comment */ ) {
}

$r = match ($x) {};
$r = match ( $x ) {};

// phpcs:set PSR2.ControlStructures.ControlStructureSpacing requiredSpacesAfterOpen 1
// phpcs:set PSR2.ControlStructures.ControlStructureSpacing requiredSpacesBeforeClose 1
$r = match ($x) {};
$r = match ( $x ) {};
$r = match ( $x ) {};
// phpcs:set PSR2.ControlStructures.ControlStructureSpacing requiredSpacesAfterOpen 0
// phpcs:set PSR2.ControlStructures.ControlStructureSpacing requiredSpacesBeforeClose 0
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,14 @@ if ($expr1
&& $expr2
/* comment */) {
}

$r = match ($x) {};
$r = match ($x) {};

// phpcs:set PSR2.ControlStructures.ControlStructureSpacing requiredSpacesAfterOpen 1
// phpcs:set PSR2.ControlStructures.ControlStructureSpacing requiredSpacesBeforeClose 1
$r = match ( $x ) {};
$r = match ( $x ) {};
$r = match ( $x ) {};
// phpcs:set PSR2.ControlStructures.ControlStructureSpacing requiredSpacesAfterOpen 0
// phpcs:set PSR2.ControlStructures.ControlStructureSpacing requiredSpacesBeforeClose 0
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public function getErrorList()
60 => 1,
64 => 1,
69 => 1,
73 => 2,
77 => 2,
79 => 2,
];

}//end getErrorList()
Expand Down

0 comments on commit 6023ed6

Please sign in to comment.