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

Bug #11105 getIncludedSniffs() not working anymore
Submitted: 2007-05-23 12:15 UTC
From: adviva Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 0.6.0)
PHP Version: Irrelevant OS: Linux
Roadmaps: (Not assigned)    
Subscription  


 [2007-05-23 12:15 UTC] adviva (Blair Robertson)
Description: ------------ Hi guys, Had a problem when I upgraded from 0.5.0 to 0.6.0. I have the code below in my class that inherits from PHP_CodeSniffer_Standards_CodingStandard and none of the included sniffs were being picked up. The problem is because you are doing a realpath() on the each element in the array returned by getIncludedSniffs() - which is fine if the element is referring to a directory, but when it is referring to an individual file realpath() returns false because the '.php' has not been suffixed. See the attached patch file for a fix to the problem. cheers Test script: --------------- function getIncludedSniffs() { return array( 'Generic/Sniffs/Formatting/MultipleStatementAlignmentSniff', 'Generic/Sniffs/Functions/OpeningFunctionBraceKernighanRitchieSniff', 'Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff', 'Generic/Sniffs/PHP/LowerCaseConstantSniff', 'PEAR/Sniffs/Commenting/InlineCommentSniff', 'PEAR/Sniffs/Files/IncludingFileSniff', 'PEAR/Sniffs/Functions/FunctionCallArgumentSpacingSniff', 'PEAR/Sniffs/Functions/FunctionCallSignatureSniff', 'PEAR/Sniffs/Functions/ValidDefaultValueSniff', 'PEAR/Sniffs/WhiteSpace/ScopeClosingBraceSniff', ); }//end getIncludedSniffs()

Comments

 [2007-05-23 22:24 UTC] squiz (Greg Sherwood)
I've been looking into this problem this week and have decided to just get people to add .php to the end of their included and excluded sniffs so realpath works as expected. This is the way I should have done it in the past because PHP_CodeSniffer already enforces the .php extension, so it makes sense to add it here as it can never change. If adding the extension works for you, I'll change the docs and mark this as a documentation problem.
 [2007-05-24 13:56 UTC] adviva (Blair Robertson)
Adding the extension works for me with the following patch. You might want to throw an error or exception when an entry in the included/excluded sniffs list doesn't exist.
 [2007-05-24 13:57 UTC] adviva (Blair Robertson)
Sorry for clarity patch is CodeSniffer.php.patch.2 cheers
 [2007-05-27 01:58 UTC] squiz (Greg Sherwood)
The exception is a good idea, thanks.
 [2007-05-29 05:29 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. BC BREAK: Included and excluded sniffs now require .php extension. Please update your coding standard classes and add ".php" to all sniff entires. See CodeSniffer/Standards/PEAR/PEARCodingStandard.php for an example. Also, exception is now thrown if an included or excluded entry is not valid.