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

From: Date: Sat, 25 Oct 2014 00:19:25 +0000
Subject: Bug #20432 [Fbk]: Switch statements with inline returns
References: 1  Groups: php.pear.bugs 
Request: Send a blank email to pear-bugs+get-11083@lists.php.net to get a copy of this message
Edit report at https://pear.php.net/bugs/bug.php?id=20432&edit=1 ID: 20432 Updated by: gsherwood@squiz.net 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: Thanks, but as I said before, I can't replicate any error with your code. Are you able to provide a sample file that shows the problem, and also show me the output of PHP_CodeSniffer (please use the -s command line argument so I can see where the error messages come from). Previous Comments: ------------------------------------------------------------------------ [2014-10-24 20:08:47] xmeltrut I just added the break to see if that fixed it, originally I was just using return and I had the same issue. ------------------------------------------------------------------------ [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

« previous php.pear.bugs (#11083) next »