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

Bug #15008 Nested Parentheses in Control Structure Sniffs
Submitted: 2008-11-13 00:29 UTC
From: jrhernandez Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.1.0)
PHP Version: Irrelevant OS:
Roadmaps: (Not assigned)    
Subscription  


 [2008-11-13 00:29 UTC] jrhernandez (Jessie Hernandez)
Description: ------------ In PEAR_Sniffs_ControlStructures_ControlSignatureSniff, there are patterns to check if, while, etc. statements. The content between parentheses is marked by the ... token. This works fine when the opening brace is in the same line, but when the desired position of the opening brace is the next line and the condition contains a function call, the sniff fails. I would be willing to submit a patch if you can give me a few pointers on how I can go about fixing this in the source. Test script: --------------- Using an if sniff of "if (...)EOL...{EOL", consider the following code: function test() { if (myfunc() == 50) { // do something... } } Expected result: ---------------- The above code should pass the sniff. Actual result: -------------- Instead, PHP_CodeSniffer reports "Expected "if (...)\n...{\n"; found "if (...)\n...)"".

Comments

 [2008-11-13 09:48 UTC] squiz (Greg Sherwood)
Oh, this is going to be a fun one to track down :) AbstractPatternSniff is a strange beast. Don't worry about a patch, I'll give it a go. Every time I touch something in there I end up breaking a bunch of tests, so leave it with me. I would suggest using a different sniff to test for this though. if you can, write a sniff that listens for T_IF and then check that the scope_opener's line is T_IF's line + 1.
 [2008-11-13 23:46 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.