-
Notifications
You must be signed in to change notification settings - Fork 26
Is it within PSR-12 standard to break foreach into multiple lines #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Nether PSR-12 nor the Coding Style PER would allow splitting foreaches the way you're showing, the only allowed use of foreach is as shown in the example you linked. A more readable approach would be to use a variable to store the array you're iterating over: $contracts = $client->getContractsByCustomerId($customer['id']);
foreach ($contracts as $contract) {
...
} |
@KorvinSzanto I don't see anywhere that this is explicitly prohibited, or allowed within the PER-CS or PSR-12 language around the |
I'd definitely accept a pull request, it could be written more clearly with MUSTs. |
@KorvinSzanto As a contributor and user of the PHP prettier code formatter, I am trying to understand where the decision that a |
The
foreach
is not too clear whether it is okay to break the expression into multiple lines. https://www.php-fig.org/psr/psr-12/#55-foreach . Other expressions likefor
andwhile
are very clear on the issue. I am unsure why this restriction is onforeach
if other loop expressions are "allowed" to do this.I need to know for these two issues:
squizlabs/PHP_CodeSniffer#3673
prettier/plugin-php#2060
example:
or is only this within the standard:
The text was updated successfully, but these errors were encountered: