Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.7.2

Bug #8884 another problem with nested switch() statements
Submitted: 2006-10-07 11:39 UTC
From: hholzgra Assigned: squiz
Status: Closed Package: PHP_CodeSniffer
PHP Version: 5.2.0 RC4 OS: linux
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 6 + 33 = ?

 
 [2006-10-07 11:39 UTC] hholzgra (Hartmut Holzgraefe)
Description: ------------ a nested switch() with a "return" instead of a "break" in the inner default case leads to wrong indentation warning even for functions declared *before* the one with the misinterpreted nested switch() Test script: --------------- <?php class Test { function getName() { return "test"; } function foobar($foo, $bar) { switch ($foo) { case 1: switch ($bar) { default: return false; // works fine with a break but gets confused by return } break; } } } Expected result: ---------------- no warnings Actual result: -------------- FILE: foo.php -------------------------------------------------------------------------------- FOUND 7 ERROR(S) AND 0 WARNING(S) AFFECTING 7 LINE(S) -------------------------------------------------------------------------------- [LINE 4] ERROR: Line indented incorrectly. Expected 0 spaces but found 4. [LINE 9] ERROR: Line indented incorrectly. Expected 0 spaces but found 4. [LINE 11] ERROR: Line indented incorrectly. Expected 4 spaces but found 8. [LINE 13] ERROR: Line indented incorrectly. Expected 4 spaces but found 12. [LINE 18] ERROR: Closing Brace Indented Incorrectly. Expected 12 spaces, but found 8. [LINE 19] ERROR: Closing Brace Indented Incorrectly. Expected 8 spaces, but found 4. [LINE 20] ERROR: Closing Brace Indented Incorrectly. Expected 4 spaces, but found 0. --------------------------------------------------------------------------------

Comments

 [2006-10-07 22:55 UTC] squiz at php dot net (Greg Sherwood)
It appears that it's not a problem with the return statement, but with the scope map trying to determine what closes the DEFAULT statement. Using this code sample for testing the map: <?php function foobar($foo, $bar) { switch ($foo) { case 1: switch ($bar) { default: } break; } } ?>
 [2006-10-08 01:38 UTC] squiz at php dot net (Greg Sherwood)
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.
 [2006-10-09 10:24 UTC] hholzgra (Hartmut Holzgraefe)
fixed for the simplified test case but still returning wrong results for PEAR::CodeGen_PECL/PECL/Element/Function.php from which i originally created the stripped down example from after running into this
 [2006-10-09 11:20 UTC] hholzgra (Hartmut Holzgraefe)
new test case: <?php class Foo { function getName() { return 42; } function isInternalName($name) { switch ($name) { case "MINIT": case "MSHUTDOWN": case "RINIT": case "RSHUTDOWN": case "MINFO": return true; } return false; } } ?> FILE: foo3.php -------------------------------------------------------------------------------- FOUND 11 ERROR(S) AND 0 WARNING(S) AFFECTING 11 LINE(S) -------------------------------------------------------------------------------- [LINE 4] ERROR: Line indented incorrectly. Expected 0 spaces but found 4. [LINE 9] ERROR: Line indented incorrectly. Expected 0 spaces but found 4. [LINE 11] ERROR: Line indented incorrectly. Expected 4 spaces but found 8. [LINE 12] ERROR: Line indented incorrectly. Expected 4 spaces but found 8. [LINE 13] ERROR: Line indented incorrectly. Expected 4 spaces but found 8. [LINE 14] ERROR: Line indented incorrectly. Expected 4 spaces but found 8. [LINE 15] ERROR: Line indented incorrectly. Expected 4 spaces but found 8. [LINE 16] ERROR: Line indented incorrectly. Expected 12 spaces but found 8. [LINE 17] ERROR: Line indented incorrectly. Expected at least 16 spaces, but found 12. [LINE 21] ERROR: Closing brace indented incorrectly. Expected 8 spaces, but found 4. [LINE 22] ERROR: Closing brace indented incorrectly. Expected 4 spaces, but found 0. --------------------------------------------------------------------------------
 [2006-10-10 05:24 UTC] squiz at php dot net (Greg Sherwood)
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.