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

Bug #19565 Non-Executable Code Sniff Broken for Case Statements with both return and break
Submitted: 2012-08-16 00:19 UTC
From: qbert00001 Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.3.6)
PHP Version: 5.3.10 OS: Linux
Roadmaps: (Not assigned)    
Subscription  


 [2012-08-16 00:19 UTC] qbert00001 (greg horvath)
Description: ------------ Any case statements that contain a return statement followed by a break cause an error to be thrown for each subsequent line of code in the entire switch statement. Test script: --------------- <?php function foo($color) { switch ($color) { case 'red': return 'yuck'; break; case 'blue': return 'yuck'; break; case 'orange': return 'yay'; break; default: return 'boring'; } } Expected result: ---------------- No errors (if a break after return in a case statement is just considered bad style and not a valid error) OR Errors only for the lines containing the break statement (if break after return in case statement is considered unreachable, which it is) Actual result: -------------- -------------------------------------------------------------------------- ------ FOUND 0 ERROR(S) AND 18 WARNING(S) AFFECTING 9 LINE(S) -------------------------------------------------------------------------- ------ 7 | WARNING | Code after RETURN statement cannot be executed 8 | WARNING | Code after BREAK statement cannot be executed 9 | WARNING | Code after BREAK statement cannot be executed 10 | WARNING | Code after BREAK statement cannot be executed 10 | WARNING | Code after RETURN statement cannot be executed 11 | WARNING | Code after BREAK statement cannot be executed 11 | WARNING | Code after BREAK statement cannot be executed 12 | WARNING | Code after BREAK statement cannot be executed 12 | WARNING | Code after BREAK statement cannot be executed 13 | WARNING | Code after BREAK statement cannot be executed 13 | WARNING | Code after BREAK statement cannot be executed 13 | WARNING | Code after RETURN statement cannot be executed 14 | WARNING | Code after BREAK statement cannot be executed 14 | WARNING | Code after BREAK statement cannot be executed 14 | WARNING | Code after BREAK statement cannot be executed 15 | WARNING | Code after BREAK statement cannot be executed 15 | WARNING | Code after BREAK statement cannot be executed 15 | WARNING | Code after BREAK statement cannot be executed -------------------------------------------------------------------------- ------

Comments

 [2012-08-16 11:02 UTC] squiz (Greg Sherwood)
-Summary: Non-Executable Code Sniff Broken for Case Statements with both return & break +Summary: Non-Executable Code Sniff Broken for Case Statements with both return and break -Status: Open +Status: Closed -Assigned To: +Assigned To: squiz
Fixed in github repo: https://github.com/squizlabs/PHP_CodeSniffer/commit/144809fb3c8689bb95f3242cb0 9af218b7d6ea0f Now reports an error for those BREAK statements that aren't required, but nothing else.