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

Bug #9274 nested_parenthesis element not set for open and close parenthesis tokens
Submitted: 2006-11-08 14:55 UTC
From: brobertson at adviva dot com Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 0.2.0)
PHP Version: 5.1.2 OS: Linux
Roadmaps: (Not assigned)    
Subscription  


 [2006-11-08 14:55 UTC] brobertson at adviva dot com (Blair Robertson)
Description: ------------ All tokens get the 'nested_parenthesis' element in their token array when it is applicable - except for T_OPEN_PARENTHESIS and T_CLOSE_PARENTHESIS. This can be fixed with a simple change to PHP_CodeSniffer_File::_createParenthesisNestingMap() Test script: --------------- Test file to Parse: ----------------------------------------- <?php echo ((10 + 15) * 22); ?> ----------------------------------------- Patch: --- pear.orig/php/PHP/CodeSniffer/File.php 2006-10-17 12:37:28.000000000 +0100 +++ pear/php/PHP/CodeSniffer/File.php 2006-11-08 15:51:16.074794538 +0000 @@ -752,9 +752,17 @@ $map = array(); for ($i = 0; $i < $numTokens; $i++) { if (isset($this->_tokens[$i]['parenthesis_opener']) === true && $i === $this->_tokens[$i]['parenthesis_opener']) { + if (empty($map) === false) { + $this->_tokens[$i]['nested_parenthesis'] = $map; + } $map[$this->_tokens[$i]['parenthesis_opener']] = $this->_tokens[$i]['parenthesis_closer']; + } else if (isset($this->_tokens[$i]['parenthesis_closer']) === true && $i === $this->_tokens[$i]['parenthesis_closer']) { array_pop($map); + if (empty($map) === false) { + $this->_tokens[$i]['nested_parenthesis'] = $map; + } + } else { if (empty($map) === false) { $this->_tokens[$i]['nested_parenthesis'] = $map; Expected result: ---------------- Array ( ... SNIP ... [4] => Array ( [type] => T_OPEN_PARENTHESIS [code] => 1004 [content] => ( [line] => 2 [parenthesis_opener] => 4 [parenthesis_closer] => 16 [column] => 10 [level] => 0 [conditions] => Array ( ) ) [5] => Array ( [type] => T_OPEN_PARENTHESIS [code] => 1004 [content] => ( [line] => 2 [parenthesis_opener] => 5 [parenthesis_closer] => 11 [nested_parenthesis] => Array ( [4] => 16 ) [column] => 11 [level] => 0 [conditions] => Array ( ) ) ... SNIP ... ) Actual result: -------------- Array ( ... SNIP ... [4] => Array ( [type] => T_OPEN_PARENTHESIS [code] => 1004 [content] => ( [line] => 2 [parenthesis_opener] => 4 [parenthesis_closer] => 16 [column] => 10 [level] => 0 [conditions] => Array ( ) ) [5] => Array ( [type] => T_OPEN_PARENTHESIS [code] => 1004 [content] => ( [line] => 2 [parenthesis_opener] => 5 [parenthesis_closer] => 11 [column] => 11 [level] => 0 [conditions] => Array ( ) ) ... SNIP ... )

Comments

 [2006-11-09 04:18 UTC] squiz at php dot net (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. Thanks for the patch. Worked perfectly.