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

Request #19404 Improve the exact mode of ScopeIndentSniff
Submitted: 2012-05-01 06:47 UTC
From: klausi Assigned: squiz
Status: Assigned Package: PHP_CodeSniffer (version SVN)
PHP Version: 5.3.9 OS: Ubuntu 12.04
Roadmaps: (Not assigned)    
Subscription  


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 30 - 24 = ?

 
 [2012-05-01 06:47 UTC] klausi (Klaus Purer)
Description: ------------ If you configure Generic_Sniffs_Whitespace_ScopeIndentSniff with $exact = true; then it will throw a few false positives on multi line statements and T_DOC_COMMENTs. Here is a valid example that uses an indentation of 2 spaces. I will also attach a patch how I solved it for drupalcs. Test script: --------------- class Bar { /** * Enter description here ... */ public function foo() { $result = db_select('node') ->condition('type', 'article') ->execute(); } } Expected result: ---------------- There should be no indentation error. Actual result: -------------- The sniff complains about the indentation of the doc block and the chained method invocations.

Comments

 [2012-05-01 06:47 UTC] klausi (Klaus Purer)
 [2012-05-01 06:48 UTC] klausi (Klaus Purer)
 [2012-05-08 10:31 UTC] squiz (Greg Sherwood)
-Type: Bug +Type: Feature/Change Request -Assigned To: +Assigned To: squiz
I agree with the comment indent change because the sniff already needs to check if it is inside a comment. It fits nicely and doesn't take any more time to check. I only changed that part of your patch slightly: https://github.com/squizlabs/PHP_CodeSniffer/commit/c0c677be0e85de4a5ee93fe35 79fc0e2921fd420 The other bit is harder. I agree with it in principle, but it needs more work to ensure it doesn't slow things down. A flag to indicate that you are inside a parenthesis block is easy enough, and then not apply the exact flag, but checking if you are inside the same statement is a bit slower. I really don't want to be looking back through the tokens array for each line to find the last non-whitespace/non-comment taken on a line (or even one several lines higher). PHP is so flexible that you can't assume code structures for generic sniffs, so things could get a bit messy. The one thing really going for the change though is the fact that the exact settings is hardly ever used, so it is unlikely to affect a large number of developers if something does go wrong. And possible, given the nature of the flag, it would be used by developers who have a more strict standard than others, possible meaning the code is cleaner anyway.