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

Bug #13156 Bug in Squiz_Sniffs_PHP_NonExecutableCodeSniff
Submitted: 2008-02-20 09:11 UTC
From: jotango Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.0.1)
PHP Version: Irrelevant OS:
Roadmaps: 1.1.0    
Subscription  


 [2008-02-20 09:11 UTC] jotango (Jan Miczaika)
Description: ------------ Hello, I am getting the following notice when I run the Squiz_Sniffs_PHP_NonExecutableCodeSniff: PHP Notice: Undefined index: scope_condition in C:\xampp\php\PEAR\PHP\CodeSniffer\Standards\Hitflip\Sniffs\PHP\NonExec utableCodeSniff.php on line 127 The line is: if ($tokens[$closer]['scope_condition'] !== $condition) { If I look into the array, scope_condition is not defined. Rather, there is an array of conditions. If I change the line to: if ((isset($tokens[$closer]['scope_condition']) === true) && $tokens[$closer]['scope_condition'] !== $condition) { The notice doesn't come any more, but I cannot see whether I have changed the scripts functionality. The test script below shows how to reproduce the notice. I feel it has something to do with the nested case statements. Test script: --------------- <?php switch($POST->action){ case 'csv': { switch($POST->csv_type){ case 'free': { $sFrom = $POST->Date_Start_Year.'-'.$POST->Date_Start_Month.'-'.$POST->Date_Start_Day.' 00:00:00'; $sTo = $POST->Date_End_Year.'-'.$POST->Date_End_Month.'-'.$POST->Date_End_Day.' 00:00:00'; break; } case 'month': { $sFrom = $POST->Date_Year.'-'.$POST->Date_Month.'-01 00:00:00'; if ($POST->Date_Month == 12){ $POST->Date_Month = 0; $POST->Date_Year++; } $sTo = $POST->Date_Year.'-'.((int)$POST->Date_Month+1).'-01 00:00:00'; break; } } } } ?>

Comments

 [2008-02-20 22:16 UTC] squiz (Greg Sherwood)
It is caused by using curly braces for case statements. I've never seen PHP code written like that so PHP_CodeSniffer does not support it correctly at the moment.
 [2008-02-20 22:35 UTC] squiz (Greg Sherwood)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.