cvs: pear /PHP_CodeSniffer package.xml /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Arrays ArrayDeclarationSniff.php

From: Date: Wed, 26 Sep 2007 05:32:15 +0000
Subject: cvs: pear /PHP_CodeSniffer package.xml /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Arrays ArrayDeclarationSniff.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-48684@lists.php.net to get a copy of this message
squiz Wed Sep 26 05:32:15 2007 UTC Modified files: /pear/PHP_CodeSniffer package.xml /pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Arrays ArrayDeclarationSniff.php Log: Fixed error with multi-token array indexes in Squiz ArrayDeclarationSniff. Sniff was assuming that all indexes were a single token, which is not the case when you have things like string concatentation. http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/package.xml?r1=1.118&r2=1.119&diff_format=u Index: pear/PHP_CodeSniffer/package.xml diff -u pear/PHP_CodeSniffer/package.xml:1.118 pear/PHP_CodeSniffer/package.xml:1.119 --- pear/PHP_CodeSniffer/package.xml:1.118 Mon Sep 24 05:44:59 2007 +++ pear/PHP_CodeSniffer/package.xml Wed Sep 26 05:32:15 2007 @@ -23,8 +23,8 @@ <date>2007-09-24</date> <time>15:35:00</time> <version> - <release>0.9.0</release> - <api>0.9.0</api> + <release>0.9.1</release> + <api>0.9.1</api> </version> <stability> <release>beta</release> @@ -32,14 +32,7 @@ </stability> <license uri="http://matrix.squiz.net/developer/tools/php_cs/licence">BSD License</license> <notes> - - Added a config system for setting config data across phpcs runs - - You can now change the default coding standard from PEAR to something else - -- Run: phpcs --config-set default_standard [standard] - - Added new Zend coding standard to check code against the Zend Framework standards - -- The complete standard is not yet implemented - -- Specify --standard=Zend to use - -- Thanks to Johann-Peter Hartmann for the contribution of some sniffs - -- Thanks to Holger Kral for the Code Analyzer sniff + - Fixed error with multi-token array indexes in Squiz ArrayDeclarationSniff </notes> <contents> <dir name="/"> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php?r1=1.10&r2=1.11&diff_format=u Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php diff -u pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php:1.10 pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php:1.11 --- pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php:1.10 Fri Jul 27 05:36:24 2007 +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php Wed Sep 26 05:32:15 2007 @@ -10,7 +10,7 @@ * @author Marc McIntyre <mmcintyre@squiz.net> * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence - * @version CVS: $Id: ArrayDeclarationSniff.php,v 1.10 2007/07/27 05:36:24 squiz Exp $ + * @version CVS: $Id: ArrayDeclarationSniff.php,v 1.11 2007/09/26 05:32:15 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ @@ -248,11 +248,22 @@ $currentEntry['arrow'] = $nextToken; $keyUsed = true; - // Find the index that uses this double arrow. - $index = $phpcsFile->findPrevious(array(T_WHITESPACE), ($nextToken - 1), $arrayStart, true); - $currentEntry['index'] = $index; - if ($maxLength < strlen($tokens[$index]['content'])) { - $maxLength = strlen($tokens[$index]['content']); + // Find the start of index that uses this double arrow. + $indexEnd = $phpcsFile->findPrevious(T_WHITESPACE, ($nextToken - 1), $arrayStart, true); + $indexStart = $phpcsFile->findPrevious(T_WHITESPACE, $indexEnd, $arrayStart); + + if ($indexStart === false) { + $index = $indexEnd; + } else { + $index = $indexStart + 1; + } + + $currentEntry['index'] = $index; + $currentEntry['index_content'] = $phpcsFile->getTokensAsString($index, ($indexEnd - $index + 1)); + + $indexLength = strlen($currentEntry['index_content']); + if ($maxLength < $indexLength) { + $maxLength = $indexLength; } // Find the value of this index. @@ -343,9 +354,9 @@ } if ($tokens[$index['arrow']]['column'] !== $arrowStart) { - $expected = ($arrowStart - (strlen($tokens[$index['index']]['content']) + $tokens[$index['index']]['column'])); + $expected = ($arrowStart - (strlen($index['index_content']) + $tokens[$index['index']]['column'])); $expected .= ($expected === 1) ? ' space' : ' spaces'; - $found = ($tokens[$index['arrow']]['column'] - (strlen($tokens[$index['index']]['content']) + $tokens[$index['index']]['column'])); + $found = ($tokens[$index['arrow']]['column'] - (strlen($index['index_content']) + $tokens[$index['index']]['column'])); $phpcsFile->addError("Array double arrow not aligned correctly; expected $expected but found $found", $index['arrow']); continue; }

« previous php.pear.cvs (#48684) next »