Single line conditions
When using simple conditions for early returns / guard statements the current formatting is quite verbose:
function test($arg1) {
if (!$arg) return;
for ($i = 0; $i < 10; $i++) {
if ($i % 2 === 0) continue;
// do something if the number is odd
}
}
will be converted to:
function test($arg1) {
if (!$arg) {
return;
}
for ($i = 0; $i < 10; $i++) {
if ($i % 2 === 0) {
continue;
}
// do something if the number is odd
}
}
It would be great if these single line conditions would be preserved. Alot of formatters for c-style languages like prettier for javascript or ClangFormat allow this, resulting in much more concise code.
Hi @arnoson, thanks for reaching out about this. We chose to adhere to the PER-CS coding standard in this project as much as possible, which doesn't allow single line conditions: https://www.php-fig.org/per/coding-style/#5-control-structures That's why I don't think this is a change we should be making, but I'll leave the issue open for further discussion.