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

Bug #19264 Squiz.PHP.NonExecutableCode does not handle RETURN in CASE without BREAK
Submitted: 2012-01-31 19:34 UTC
From: sebastian Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.3.2)
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  


 [2012-01-31 19:34 UTC] sebastian (Sebastian Bergmann)
Description: ------------ Conditional RETURN statements should be ignored. Test script: --------------- protected function matches($other) { switch ($this->type) { case 'numeric': { return is_numeric($other); } case 'integer': case 'int': { return is_integer($other); } case 'float': { return is_float($other); } case 'string': { return is_string($other); } case 'boolean': case 'bool': { return is_bool($other); } case 'null': { return is_null($other); } case 'array': { return is_array($other); } case 'object': { return is_object($other); } case 'resource': { return is_resource($other); } case 'scalar': { return is_scalar($other); } case 'callable': { return is_callable($other); } } } Expected result: ---------------- No warnings. Actual result: -------------- FILE: /usr/local/src/phpunit/PHPUnit/Framework/Constraint/IsType.php -------------------------------------------------------------------------------- FOUND 0 ERROR(S) AND 19 WARNING(S) AFFECTING 19 LINE(S) -------------------------------------------------------------------------------- 137 | WARNING | Code after RETURN statement cannot be executed 139 | WARNING | Code after RETURN statement cannot be executed 141 | WARNING | Code after RETURN statement cannot be executed 143 | WARNING | Code after RETURN statement cannot be executed 145 | WARNING | Code after RETURN statement cannot be executed 147 | WARNING | Code after RETURN statement cannot be executed 150 | WARNING | Code after RETURN statement cannot be executed 152 | WARNING | Code after RETURN statement cannot be executed 154 | WARNING | Code after RETURN statement cannot be executed 156 | WARNING | Code after RETURN statement cannot be executed 158 | WARNING | Code after RETURN statement cannot be executed 160 | WARNING | Code after RETURN statement cannot be executed 162 | WARNING | Code after RETURN statement cannot be executed 164 | WARNING | Code after RETURN statement cannot be executed 166 | WARNING | Code after RETURN statement cannot be executed 168 | WARNING | Code after RETURN statement cannot be executed 170 | WARNING | Code after RETURN statement cannot be executed 172 | WARNING | Code after RETURN statement cannot be executed 174 | WARNING | Code after RETURN statement cannot be executed --------------------------------------------------------------------------------

Comments

 [2012-02-03 09:16 UTC] squiz (Greg Sherwood)
-Assigned To: +Assigned To: squiz
The fact that none of the CASE statements include a BREAK is the thing that is throwing it off. It can't tell if you meant the RETURN to be there or if you expecting execution to go to the next CASE but you accidentally put a non-conditional RETURN in there. The first case is more likely (you have the RETURN there on purpose) so I'll change the code to make this assumption as well.
 [2012-02-03 10:10 UTC] squiz (Greg Sherwood)
-Summary: Squiz.PHP.NonExecutableCode does not handle conditional RETURN statements +Summary: Squiz.PHP.NonExecutableCode does not handle RETURN in CASE without BREAK
 [2012-02-03 10:13 UTC] squiz (Greg Sherwood)
-Status: Assigned +Status: Closed
Fix in Git repo. Need both commits: https://github.com/squizlabs/PHP_CodeSniffer/commit/6defcb9d05a41da80c4cbd49d 74dc8cae0228b34 https://github.com/squizlabs/PHP_CodeSniffer/commit/811fb22d022d526a6dab38fe1 da0398ecb2669bb