FAQ
Edit report at https://pear.php.net/bugs/bug.php?id=19565&edit=1

ID: 19565
Updated by: gsherwood@squiz.net
Reported By: ghorvath@etsy.com
-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
Type: Bug
Package: PHP_CodeSniffer
Operating System: Linux
Package Version: 1.3.6
PHP Version: 5.3.10
-Assigned To:
+Assigned To: squiz
Roadmap Versions:
New Comment:

-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.


Previous Comments:
------------------------------------------------------------------------

[2012-08-15 20:19:40] qbert00001

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
--------------------------------------------------------------------------
------

------------------------------------------------------------------------

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedAug 16, '12 at 4:56a
activeAug 16, '12 at 4:56a
posts1
users1
websitepear.php.net

1 user in discussion

Gsherwood: 1 post

People

Translate

site design / logo © 2022 Grokbase