[PEAR-BUG] Bug #20432 [Fbk]: Switch statements with inline returns

[email protected] Fri, 24 Oct 2014 20:08:47 +0100 (BST)
Newsgroups php.pear.bugs
Message-ID <[email protected]>
Edit report at https://pear.php.net/bugs/bug.php?id=20432&edit=1

 ID:               20432
 Updated by:       [email protected]
 Reported By:      xmeltrut at gmail dot com
 Summary:          Switch statements with inline returns
 Status:           Feedback
 Type:             Bug
 Package:          PHP_CodeSniffer
 Package Version:  1.5.5
 PHP Version:      5.6.0
 Assigned To:      squiz
 Roadmap Versions: 
 New Comment:

I just added the break to see if that fixed it, originally I was just
using return and I had 
the same issue.


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

[2014-10-24 13:21:39] squiz

-Status:      Open
+Status:      Feedback
-Assigned To:
+Assigned To: squiz
I can't replicate the closing brace error, but I can tell you that the
RETURN statement 
is actually the breaking statement of the case. Your BREAK line is
unreachable code 
and should be removed. PHP_CodeSniffer recognises the RETURN as the
closing 
statement for reach CASE, so you may be getting indentation errors
because of that.

So you'd write the code like this:

switch {
    case 'a':
        return 'a';
    case 'b':
        return 'b';
}

Does that remove your error? If not, I'd need to see code around the
switch 
statement because I can't replicate any indent errors with the switch
statement 
you've provided.

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

[2014-10-24 13:09:56] xmeltrut

Description:
------------
When you use a return statement inside a switch case, CodeSniffer 
complains about indentation:

Closing brace indented incorrectly; expected 16 spaces, found 20

Test script:
---------------
switch {
    case 'a':
        return 'a';
        break;
    case 'b':
        return 'b';
        break;
}

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


-- 
Edit this bug report at https://pear.php.net/bugs/bug.php?id=20432&edit=1