Home » PHP » PHP_Beautifier » Bug #7759
comment after case causes mistake
Details
| Submitted | 2006-05-30 19:13 UTC |
|---|---|
| From | aspearphp at dsgml dot com |
| Assigned | clbustos |
| Status | Closed |
| Package | PHP_Beautifier |
| PHP Version | 5.1.2 |
| OS | Linux |
| Roadmaps | (Not assigned) |
Comments
[2006-05-30 19:13 UTC] aspearphp at dsgml dot com
Description:
------------
Adding a comment after a case statement in a switch causes the indenting to be wrong.
Test script:
---------------
<?
echo 0;
switch(1) {
case 1:
echo 1;
break;
case 2: //2
default:
echo '2';
break;
}
echo 1;
?>
Expected result:
----------------
<?
echo 0;
switch (1) {
case 1:
echo 1;
break;
case 2: //2
default:
echo '2';
break;
}
echo 1;
?>
Actual result:
--------------
<?
echo 0;
switch (1) {
case 1:
echo 1;
break;
case 2: //2
default:
echo '2';
break;
}
echo 1;
?>
[2006-05-30 19:17 UTC] aspearphp at dsgml dot com
Actually adding anything after a case breaks it. It seems it's expecting either: case to follow directly after case.
OR case to be closed by a break.
But that's not correct. You can have case, then code, then NO break, another case and more code.
Eg:
<?
switch (1) {
case 1:
echo 1;
case 2:
echo '2';
break;
}
?>
This is legal, but doesn't not beautify properly.
[2006-05-30 19:20 UTC] aspearphp at dsgml dot com
And one other thing: in my ever so humble opinion, the break should be indented with it's code. It should not be pulled forward to match the case statement.
This is not like a standard block with an open and close. The break is just another line of code - it does not signify closing the case.
[2006-06-06 05:25 UTC] clbustos at php dot net
Thank you for your bug report. This issue has been fixed
in the latest released version of the package, which you can download at
http://pear.php.net/get/PHP_Beautifier
Fixed on PHP_Beautifier 0.1.9
[2006-06-06 07:32 UTC] aspearphp at dsgml dot com
The new version fixed the problem with a comment, but not the one with a case without a break.
Specifically this:
<?
switch (1) {
case 1:
echo 1;
case 2:
echo '2';
break;
}
?>
Also, I'll copy what I wrote before:
"in my ever so humble opinion, the break should be
indented with it's code. It should not be pulled forward to match the case statement.
This is not like a standard block with an open and close. The break is just another line of code - it does not signify closing the case."
Also, I'm getting these messages:
Jun 06 03:28:56 php_beautifier [info] Push:327->switch
Jun 06 03:28:56 php_beautifier [info] Push Parenthesis: 327 ->switch
Jun 06 03:28:56 php_beautifier [info] Pop Parenthesis:327
Jun 06 03:28:56 php_beautifier [info] Push:329->case
Jun 06 03:28:56 php_beautifier [info] Pop:329
Jun 06 03:28:56 php_beautifier [info] Push:329->case
Jun 06 03:28:56 php_beautifier [info] Push:330->default
Jun 06 03:28:56 php_beautifier [info] Pop:330
Jun 06 03:28:56 php_beautifier [info] end bracket:;
Jun 06 03:28:56 php_beautifier [info] Pop:329
[2006-06-06 22:57 UTC] clbustos at php dot net
Is true that case doesn't need to be closed by a break, but 99% of the times is used on that way. Anyway, the Pear filter have the behaviour that you need.
I'm currently researching how fix the last bug that you send me... i will have to auto deindent the beggining of the case, not indenting the next line after a switch.
[2006-06-13 21:27 UTC] clbustos at php dot net
This bug has been fixed in CVS.
If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET).
If this was a problem with the pear.php.net website, the change should be live shortly.
Otherwise, the fix will appear in the package's next release.
Thank you for the report and for helping us make PEAR better.
Use svn co https://svn.sourceforge.net/svnroot/beautifyphp/trunk PHP_Beautifier