cvs: pear /PHP_CodeSniffer package.xml /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP DisallowCountInLoopsSniff.php
DisallowSizeFunctionsInLoopsSniff.php /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP DisallowCountInLoopsUnitTest.inc
DisallowCountInLoopsUnitTest.php DisallowSizeFunctionsInLoopsUnitTest.inc DisallowSizeFunctionsInLoopsUnitTest.php

From: Date: Mon, 07 Apr 2008 01:14:00 +0000
Subject: cvs: pear /PHP_CodeSniffer package.xml /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP DisallowCountInLoopsSniff.php
DisallowSizeFunctionsInLoopsSniff.php /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP DisallowCountInLoopsUnitTest.inc
DisallowCountInLoopsUnitTest.php DisallowSizeFunctionsInLoopsUnitTest.inc DisallowSizeFunctionsInLoopsUnitTest.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-51828@lists.php.net to get a copy of this message
squiz Mon Apr 7 01:14:00 2008 UTC Added files: /pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP DisallowSizeFunctionsInLoopsSniff.php /pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP DisallowSizeFunctionsInLoopsUnitTest.inc DisallowSizeFunctionsInLoopsUnitTest.php Removed files: /pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP DisallowCountInLoopsSniff.php /pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP DisallowCountInLoopsUnitTest.inc DisallowCountInLoopsUnitTest.php Modified files: /pear/PHP_CodeSniffer package.xml Log: Replaced Squiz DisallowCountInLoopsSniff with Squiz DisallowSizeFunctionsInLoopsSniff

http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/package.xml?r1=1.259&r2=1.260&diff_format=u Index: pear/PHP_CodeSniffer/package.xml diff -u pear/PHP_CodeSniffer/package.xml:1.259 pear/PHP_CodeSniffer/package.xml:1.260 --- pear/PHP_CodeSniffer/package.xml:1.259 Mon Mar 31 00:52:00 2008 +++ pear/PHP_CodeSniffer/package.xml Mon Apr 7 01:13:59 2008 @@ -45,6 +45,8 @@ -- Thanks to Manuel Pichler for the contribution of all these sniffs. - Squiz FunctionCommentThrowTagSniff no longer throws errors for function that only throw variables - Generic ScopeIndentSniff now has private member to enforce exact indent matching + - Replaced Squiz DisallowCountInLoopsSniff with Squiz DisallowSizeFunctionsInLoopsSniff + -- Thanks to Jan Miczaika for the sniff - Squiz BlockCommentSniff now checks inline doc block comments - Squiz InlineCommentSniff now checks inline doc block comments - Squiz BlockCommentSniff now checks for no blank line before first comment in a function @@ -844,9 +846,6 @@ <file baseinstalldir="PHP" name="CommentedOutCodeSniff.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> - <file baseinstalldir="PHP" name="DisallowCountInLoopsSniff.php" role="php"> - <tasks:replace from="@package_version@" to="version" type="package-info" /> - </file> <file baseinstalldir="PHP" name="DisallowInlineIfSniff.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> @@ -856,6 +855,9 @@ <file baseinstalldir="PHP" name="DisallowObEndFlushSniff.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> + <file baseinstalldir="PHP" name="DisallowSizeFunctionsInLoopsSniff.php" role="php"> + <tasks:replace from="@package_version@" to="version" type="package-info" /> + </file> <file baseinstalldir="PHP" name="EmbeddedPhpSniff.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> @@ -1158,10 +1160,6 @@ <file baseinstalldir="PHP" name="CommentedOutCodeUnitTest.php" role="test"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> - <file baseinstalldir="PHP" name="DisallowCountInLoopsUnitTest.inc" role="test" /> - <file baseinstalldir="PHP" name="DisallowCountInLoopsUnitTest.php" role="test"> - <tasks:replace from="@package_version@" to="version" type="package-info" /> - </file> <file baseinstalldir="PHP" name="DisallowInlineIfUnitTest.inc" role="test" /> <file baseinstalldir="PHP" name="DisallowInlineIfUnitTest.php" role="test"> <tasks:replace from="@package_version@" to="version" type="package-info" /> @@ -1174,6 +1172,10 @@ <file baseinstalldir="PHP" name="DisallowObEndFlushUnitTest.php" role="test"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> + <file baseinstalldir="PHP" name="DisallowSizeFunctionsInLoopsUnitTest.inc" role="test" /> + <file baseinstalldir="PHP" name="DisallowSizeFunctionsInLoopsUnitTest.php" role="test"> + <tasks:replace from="@package_version@" to="version" type="package-info" /> + </file> <file baseinstalldir="PHP" name="EmbeddedPhpUnitTest.inc" role="test" /> <file baseinstalldir="PHP" name="EmbeddedPhpUnitTest.php" role="test"> <tasks:replace from="@package_version@" to="version" type="package-info" /> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowSizeFunctionsInLoopsSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowSizeFunctionsInLoopsSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowSizeFunctionsInLoopsSniff.php <?php /** * Squiz_Sniffs_PHP_DisallowSizeFunctionsInLoopsSniff. * * PHP version 5 * * @category PHP * @package PHP_CodeSniffer * @author Greg Sherwood <gsherwood@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: DisallowSizeFunctionsInLoopsSniff.php,v 1.1 2008/04/07 01:14:00 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ /** * Squiz_Sniffs_PHP_DisallowSizeFunctionsInLoopsSniff. * * Bans the use of size-based functions in loop conditions. * * @category PHP * @package PHP_CodeSniffer * @author Greg Sherwood <gsherwood@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 Release: @package_version@ * @link http://pear.php.net/package/PHP_CodeSniffer */ class Squiz_Sniffs_PHP_DisallowSizeFunctionsInLoopsSniff implements PHP_CodeSniffer_Sniff { /** * An array of functions we don't want in the condition of loops. * * @return array */ protected $forbiddenFunctions = array( 'sizeof', 'strlen', 'count', ); /** * Returns an array of tokens this test wants to listen for. * * @return array */ public function register() { return array(T_WHILE, T_FOR); }//end register() /** * Processes this test, when one of its tokens is encountered. * * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. * @param int $stackPtr The position of the current token * in the stack passed in $tokens. * * @return void */ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $openBracket = $tokens[$stackPtr]['parenthesis_opener']; $closeBracket = $tokens[$stackPtr]['parenthesis_closer']; for ($i = ($openBracket + 1); $i < $closeBracket; $i++) { if ($tokens[$i]['code'] === T_STRING && in_array($tokens[$i]['content'], $this->forbiddenFunctions)) { $error = 'The use of '.$tokens[$i]['content'].'() inside a loop condition is not allowed. Assign the return value of '.$tokens[$i]['content'].'() to a variable and use the variable in the loop condition instead.'; $phpcsFile->addError($error, $i); } } }//end process() }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/DisallowSizeFunctionsInLoopsUnitTest.inc?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/DisallowSizeFunctionsInLoopsUnitTest.inc +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/DisallowSizeFunctionsInLoopsUnitTest.inc <?php for ($i = 0; $i < count($array); $i++) { } $num = count($array); while ($i < count($array)) { } do { } while ($i < count($array)); for ($i = 0; $i < count($this->children); $i++) { } for ($i = 0; $i < sizeof($array); $i++) { } $num = sizeof($array); while ($i < sizeof($array)) { } do { } while ($i < sizeof($array)); for ($i = 0; $i < sizeof($this->children); $i++) { } for ($i = 0; $i < strlen($string); $i++) { } $num = strlen($string); while ($i < strlen($string)) { } do { } while ($i < strlen($string)); for ($i = 0; $i < strlen($this->string); $i++) { } ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/DisallowSizeFunctionsInLoopsUnitTest.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/DisallowSizeFunctionsInLoopsUnitTest.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/DisallowSizeFunctionsInLoopsUnitTest.php <?php /** * Unit test class for the DisallowSizeFunctionsInLoops sniff. * * PHP version 5 * * @category PHP * @package PHP_CodeSniffer * @author Greg Sherwood <gsherwood@squiz.net> * @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: DisallowSizeFunctionsInLoopsUnitTest.php,v 1.1 2008/04/07 01:14:00 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ /** * Unit test class for the DisallowSizeFunctionsInLoops sniff. * * A sniff unit test checks a .inc file for expected violations of a single * coding standard. Expected errors and warnings are stored in this class. * * @category PHP * @package PHP_CodeSniffer * @author Greg Sherwood <gsherwood@squiz.net> * @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 Release: @package_version@ * @link http://pear.php.net/package/PHP_CodeSniffer */ class Squiz_Tests_PHP_DisallowSizeFunctionsInLoopsUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * * The key of the array should represent the line number and the value * should represent the number of errors that should occur on that line. * * @return array(int => int) */ public function getErrorList() { return array( 2 => 1, 7 => 1, 11 => 1, 13 => 1, 18 => 1, 23 => 1, 27 => 1, 29 => 1, 35 => 1, 40 => 1, 44 => 1, 46 => 1, ); }//end getErrorList() /** * Returns the lines where warnings should occur. * * The key of the array should represent the line number and the value * should represent the number of warnings that should occur on that line. * * @return array(int => int) */ public function getWarningList() { return array(); }//end getWarningList() }//end class ?>
« previous php.pear.cvs (#51828) next »