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

Request #18799 Please add a token for the backtick operator
Submitted: 2011-09-07 09:50 UTC
From: wolfen Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.3.0)
PHP Version: Irrelevant OS: linux 2.6.9
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


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 : 42 - 9 = ?

 
 [2011-09-07 09:50 UTC] wolfen (Peter Wolfenden)
Description: ------------ Today, in order to detect usage of the backtick operator, a Sniff must register a callback with the T_NONE token and check the "content" field of the associated file token to see if it matches "`". It would be more intuitive for CodeSniffer to provide support for T_BACKTICK_STRING token, even though the PHP parser itself has no such token. By way of precedent, CodeSniffer has already introduced a special token to handle closures - even though these aren't recognized by the PHP parser, either. Test script: --------------- What I have to write today: class test_Sniffs_Dangerous_BackTickSniff implements PHP_CodeSniffer_Sniff { public $supportedTokenizers = array('PHP'); public function register() { return array(T_NONE); } public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { // generate one error per line with backticks // (typically one for every pair): static $reported = array(); $all_tokens = $phpcsFile->getTokens(); if ($all_tokens[$stackPtr]['content'] == '`') { $lno = $all_tokens[$stackPtr]['line']; if (!isset($reported[$lno])) { $reported[$lno] = true; $phpcsFile->addError('Avoid backticks', $stackPtr); } } } } Expected result: ---------------- What I would like to be able to write instead: class test_Sniffs_Dangerous_BackTickSniff implements PHP_CodeSniffer_Sniff { public $supportedTokenizers = array('PHP'); public function register() { return array(T_BACKTICK_STRING); } public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { $phpcsFile->addError('Avoid backticks', $stackPtr); } }

Comments

 [2011-09-12 09:28 UTC] squiz (Greg Sherwood)
-Status: Open +Status: Closed -Assigned To: +Assigned To: squiz
This bug has been fixed in SVN. 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. Good idea. I've added it as T_BACKTICK.
 [2011-09-12 18:58 UTC] wolfen (Peter Wolfenden)
Thanks!