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

Bug #16533 Duplicate errors and warnings.
Submitted: 2009-08-17 20:27 UTC
From: williamb Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.2.0)
PHP Version: 5.3.0 OS:
Roadmaps: (Not assigned)    
Subscription  


 [2009-08-17 20:27 UTC] williamb (William Bailey)
Description: ------------ Sometimes sniffs will register duplicate errors and warnings. Test script: --------------- A big offender was the PEAR.WhiteSpace.ScopeClosingBrace sniff. To fix a simple in_array check can be performed in the PHP_CodeSniffer_File::addError() and PHP_CodeSniffer_File::addWarning() methods.. $record = array( 'message' => $error, 'source' => $sniff, ); if (!in_array($record, $this->_errors[$lineNum][$column])) { $this->_errors[$lineNum][$column][] = $record; $this->_errorCount++; } Expected result: ---------------- Errors and warnings should only me reported once per line. Actual result: -------------- The "Closing brace indented incorrectly; expected 12 spaces, found 8" error was reported multiple times for the same line.

Comments

 [2009-08-20 10:32 UTC] squiz (Greg Sherwood)
-Status: Open +Status: Feedback -Assigned To: +Assigned To: squiz
PHP_CodeSniffer will often report multiple errors on the same line because multiple sniffs might find errors (e.g., indentation, variable name, line length). If a specific sniff is report the exact same error or the same line, then that needs to be looked at, but I need some sample code to find out why it is doing this. Are you able to provide some code that can reproduce the error?
 [2009-08-20 16:30 UTC] williamb (William Bailey)
I know the code below is not to the PEAR standard but it does highlight the duplicate line and error message issue and in any case the error should only be reported once. PHP File: <?php switch($httpResponseCode) { case 100: return 'Continue.'; case 101: return 'Switching protocols.'; case 102: return 'Processing.'; case 200: return 'OK.'; case 201: return 'Created.'; case 202: return 'Accepted.'; } PHP_CodeSniffer Output: > phpcs --standard=PEAR -s blah.php -------------------------------------------------------------------------------- FOUND 14 ERROR(S) AND 0 WARNING(S) AFFECTING 9 LINE(S) -------------------------------------------------------------------------------- 1 | ERROR | End of line character is invalid; expected "\n" but found "\r\n" | | (PEAR.Files.LineEndings) 2 | ERROR | Missing file doc comment (PEAR.Commenting.FileComment) 3 | ERROR | Line indented incorrectly; expected 0 spaces, found 4 | | (PEAR.WhiteSpace.ScopeIndent) 5 | ERROR | Line indented incorrectly; expected 0 spaces, found 4 | | (PEAR.WhiteSpace.ScopeIndent) 7 | ERROR | Line indented incorrectly; expected 0 spaces, found 4 | | (PEAR.WhiteSpace.ScopeIndent) 9 | ERROR | Line indented incorrectly; expected 0 spaces, found 4 | | (PEAR.WhiteSpace.ScopeIndent) 11 | ERROR | Line indented incorrectly; expected 0 spaces, found 4 | | (PEAR.WhiteSpace.ScopeIndent) 13 | ERROR | Line indented incorrectly; expected 0 spaces, found 4 | | (PEAR.WhiteSpace.ScopeIndent) 15 | ERROR | Closing brace indented incorrectly; expected 4 spaces, found 0 | | (PEAR.WhiteSpace.ScopeClosingBrace) 15 | ERROR | Closing brace indented incorrectly; expected 4 spaces, found 0 | | (PEAR.WhiteSpace.ScopeClosingBrace) 15 | ERROR | Closing brace indented incorrectly; expected 4 spaces, found 0 | | (PEAR.WhiteSpace.ScopeClosingBrace) 15 | ERROR | Closing brace indented incorrectly; expected 4 spaces, found 0 | | (PEAR.WhiteSpace.ScopeClosingBrace) 15 | ERROR | Closing brace indented incorrectly; expected 4 spaces, found 0 | | (PEAR.WhiteSpace.ScopeClosingBrace) 15 | ERROR | Closing brace indented incorrectly; expected 4 spaces, found 0 | | (PEAR.WhiteSpace.ScopeClosingBrace) --------------------------------------------------------------------------------
 [2009-08-21 07:22 UTC] squiz (Greg Sherwood)
-Status: Feedback +Status: Assigned
Thanks for this sample code. It appears to just be the fact that all CASE statements share the same scope closer (the closing curly brace of the switch) so the sniff is reporting an error for each CASE. I'll fix this up so the sniff only reports for the first CASE.
 [2009-08-21 12:09 UTC] squiz (Greg Sherwood)
-Status: Assigned +Status: Closed
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.