I've created a new branch (nikulis/prettier-php@7ee8034) to address this, but did not want to PR at the moment since it is based on the already-open #14.
The php break statement should accept an optional trailing integer denoting the number of nested control statements to break. Currently, any trailing integer is removed.
Input:
<?php
while(true) {
while(true) {
break 2;
}
}
Current output:
<?php
while(true) {
while(true) {
break;
}
}
There are a couple other quirks surrounding the use of the break statement that may or may not fall under the purview of this project to auto-correct and/or offer configurable parameters for:
Apparently, php also allows for parentheses around the trailing integer, making it look like a function call, e.g. break(2);. Could we automatically remove the parentheses so that all breaks follow the same convention?
break 1; could be collapsed to break;.
Can you break $count? (I really hope not)
php 5.4.0 "Removed the ability to pass in variables (e.g., $num = 2; break $num;) as the numerical argument."
Which leads to the question (maybe best discussed as a separate issue): what version(s) of php will this plugin target?
Nice work!
I'd suggest only targeting supported versions of PHP, i.e. 5.6 and 7.x.
About the question on parentheses: I'd prefer removing them always to enforce consistent style.
Agreed, and fixed in nikulis/prettier-php@da6aea4
Hi @nikulis, #14 was just merged - would you like to create a PR?