cvs: pear /PHP_CodeSniffer package.xml /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions UpperCasePhpConstantSniff.php
/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP DisallowShortOpenTagSniff.php ForbiddenFunctionsSniff.php GlobalKeywordSniff.php
HeredocSniff.php InnerFunctionsSniff.php /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Strings DoubleQuoteUsageSniff.php EchoedStringsSniff.php
/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP ForbiddenFunctionsUnitTest.inc ForbiddenFunctionsUnitTest.php GlobalKeywordUnitTest.inc
GlobalKeywordUnitTest.php HeredocUnitTest.inc HeredocUnitTest.php InnerFunctionsUnitTest.inc InnerFunctionsUnitTest.php
/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Strings DoubleQuoteUsageUnitTest.inc DoubleQuoteUsageUnitTest.php EchoedStringsUnitTest.inc
EchoedStringsUnitTest.php

From: Date: Thu, 28 Dec 2006 06:03:47 +0000
Subject: cvs: pear /PHP_CodeSniffer package.xml /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions UpperCasePhpConstantSniff.php
/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP DisallowShortOpenTagSniff.php ForbiddenFunctionsSniff.php GlobalKeywordSniff.php
HeredocSniff.php InnerFunctionsSniff.php /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Strings DoubleQuoteUsageSniff.php EchoedStringsSniff.php
/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP ForbiddenFunctionsUnitTest.inc ForbiddenFunctionsUnitTest.php GlobalKeywordUnitTest.inc
GlobalKeywordUnitTest.php HeredocUnitTest.inc HeredocUnitTest.php InnerFunctionsUnitTest.inc InnerFunctionsUnitTest.php
/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Strings DoubleQuoteUsageUnitTest.inc DoubleQuoteUsageUnitTest.php EchoedStringsUnitTest.inc
EchoedStringsUnitTest.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-43862@lists.php.net to get a copy of this message
squiz Thu Dec 28 06:03:47 2006 UTC Added files: /pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions UpperCasePhpConstantSniff.php /pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP DisallowShortOpenTagSniff.php ForbiddenFunctionsSniff.php GlobalKeywordSniff.php HeredocSniff.php InnerFunctionsSniff.php /pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Strings DoubleQuoteUsageSniff.php EchoedStringsSniff.php /pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP ForbiddenFunctionsUnitTest.inc ForbiddenFunctionsUnitTest.php GlobalKeywordUnitTest.inc GlobalKeywordUnitTest.php HeredocUnitTest.inc HeredocUnitTest.php InnerFunctionsUnitTest.inc InnerFunctionsUnitTest.php /pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Strings DoubleQuoteUsageUnitTest.inc DoubleQuoteUsageUnitTest.php EchoedStringsUnitTest.inc EchoedStringsUnitTest.php Modified files: /pear/PHP_CodeSniffer package.xml Log: Sniffs added to Squiz coding standard

http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/package.xml?r1=1.19&r2=1.20&diff_format=u Index: pear/PHP_CodeSniffer/package.xml diff -u pear/PHP_CodeSniffer/package.xml:1.19 pear/PHP_CodeSniffer/package.xml:1.20 --- pear/PHP_CodeSniffer/package.xml:1.19 Thu Dec 28 00:25:43 2006 +++ pear/PHP_CodeSniffer/package.xml Thu Dec 28 06:03:47 2006 @@ -31,6 +31,7 @@ - some may be moved into the Generic coding standard if required - Added MultipleStatementAlignmentSniff to Generic standard - Added ScopeIndentSniff to Generic standard + - Added ForbiddenFunctionsSniff to Generic standard - Added FileCommentSniff to PEAR standard - Added ClassCommentSniff to PEAR standard - Added FunctionCommentSniff to PEAR standard @@ -176,6 +177,9 @@ <file name="DisallowShortOpenTagSniff.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> + <file name="ForbiddenFunctionsSniff.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> <file name="LowerCaseConstantSniff.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> @@ -223,6 +227,10 @@ <file name="DisallowShortOpenTagUnitTest.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> + <file name="ForbiddenFunctionsUnitTest.inc"/> + <file name="ForbiddenFunctionsUnitTest.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> <file name="LowerCaseConstantUnitTest.inc"/> <file name="LowerCaseConstantUnitTest.php"> <replace type="package-info" from="@package_version@" to="version"/> @@ -480,6 +488,11 @@ <replace type="package-info" from="@package_version@" to="version"/> </file> </dir> + <dir name="NamingConventions"> + <file name="UpperCasePhpConstantSniff.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> <dir name="PHP"> <file name="DisallowObEndFlushSniff.php"> <replace type="package-info" from="@package_version@" to="version"/> @@ -487,6 +500,18 @@ <file name="EmbeddedPhpSniff.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> + <file name="ForbiddenFunctionsSniff.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file name="GlobalKeywordSniff.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file name="HeredocSniff.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file name="InnerFunctionsSniff.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> </dir> <dir name="Scope"> <file name="MemberVarScopeSniff.php"> @@ -503,6 +528,12 @@ <file name="ConcatenationSpacingSniff.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> + <file name="DoubleQuoteUsageSniff.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file name="EchoedStringsSniff.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> </dir> <dir name="WhiteSpace"> <file name="ControlStructureSpacingSniff.php"> @@ -639,6 +670,22 @@ <file name="EmbeddedPhpUnitTest.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> + <file name="ForbiddenFunctionsUnitTest.inc"/> + <file name="ForbiddenFunctionsUnitTest.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file name="GlobalKeywordUnitTest.inc"/> + <file name="GlobalKeywordUnitTest.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file name="HeredocUnitTest.inc"/> + <file name="HeredocUnitTest.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file name="InnerFunctionsUnitTest.inc"/> + <file name="InnerFunctionsUnitTest.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> </dir> <dir name="Scope"> <file name="MemberVarScopeUnitTest.inc"/> @@ -659,6 +706,14 @@ <file name="ConcatenationSpacingUnitTest.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> + <file name="DoubleQuoteUsageUnitTest.inc"/> + <file name="DoubleQuoteUsageUnitTest.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file name="EchoedStringsUnitTest.inc"/> + <file name="EchoedStringsUnitTest.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> </dir> <dir name="WhiteSpace"> <file name="ControlStructureSpacingUnitTest.inc"/> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/UpperCasePhpConstantSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/UpperCasePhpConstantSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/UpperCasePhpConstantSniff.php <?php /** * Squiz_Sniffs_NamingConventions_UpperCasePhpConstantSniff. * * 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: UpperCasePhpConstantSniff.php,v 1.1 2006/12/28 06:03:47 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ require_once 'PHP/CodeSniffer/Standards/Generic/Sniffs/PHP/UpperCaseConstantSniff.php'; /** * Squiz_Sniffs_NamingConventions_UpperCasePhpConstantSniff. * * Checks that all uses of TRUE, FALSE and NULL are uppercase. * * @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_Sniffs_NamingConventions_UpperCasePhpConstantSniff extends Generic_Sniffs_PHP_UpperCaseConstantSniff { }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowShortOpenTagSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowShortOpenTagSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP/DisallowShortOpenTagSniff.php <?php /** * Squiz_Sniffs_PHP_DisallowShortOpenTagSniff. * * 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: DisallowShortOpenTagSniff.php,v 1.1 2006/12/28 06:03:47 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ require_once 'PHP/CodeSniffer/Standards/Generic/Sniffs/PHP/DisallowShortOpenTagSniff.php'; /** * Squiz_Sniffs_PHP_DisallowShortOpenTagSniff. * * Makes sure that shorthand PHP open tags are not used. * * @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_Sniffs_PHP_DisallowShortOpenTagSniff extends Generic_Sniffs_PHP_DisallowShortOpenTagSniff { }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP/ForbiddenFunctionsSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP/ForbiddenFunctionsSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP/ForbiddenFunctionsSniff.php <?php /** * Squiz_Sniffs_PHP_ForbiddenFunctionsSniff. * * 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: ForbiddenFunctionsSniff.php,v 1.1 2006/12/28 06:03:47 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ require_once 'PHP/CodeSniffer/Standards/Generic/Sniffs/PHP/ForbiddenFunctionsSniff.php'; /** * Squiz_Sniffs_PHP_ForbiddenFunctionsSniff. * * Discourages the use of alias functions that are kept in PHP for compatibility * with older versions. Can be used to forbid the use of any function. * * @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_Sniffs_PHP_ForbiddenFunctionsSniff extends Generic_Sniffs_PHP_ForbiddenFunctionsSniff { /** * A list of forbidden functions with their alternatives. * * The value is NULL if no alternative exists. IE, the * function should just not be used. * * @var array(string => string|null) */ protected $forbiddenFunctions = array( 'sizeof' => 'count', 'delete' => 'unset', 'create_function' => null, ); }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP/GlobalKeywordSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP/GlobalKeywordSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP/GlobalKeywordSniff.php <?php /** * Squiz_Sniffs_PHP_GlobalKeywordSniff. * * 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: GlobalKeywordSniff.php,v 1.1 2006/12/28 06:03:47 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ require_once 'PHP/CodeSniffer/Sniff.php'; /** * Squiz_Sniffs_PHP_GlobalKeywordSniff. * * Stops the usage of the "global" keyword. * * @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_Sniffs_PHP_GlobalKeywordSniff implements PHP_CodeSniffer_Sniff { /** * Returns an array of tokens this test wants to listen for. * * @return array */ public function register() { return array(T_GLOBAL); }//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(); $nextVar = $tokens[$phpcsFile->findNext(array(T_VARIABLE), $stackPtr)]; $varName = str_replace('$', '', $nextVar['content']); $error = "Use of the \"global\" keyword is forbidden; use \"\$GLOBALS['$varName']\" instead"; $phpcsFile->addError($error, $stackPtr); }//end process() }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP/HeredocSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP/HeredocSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP/HeredocSniff.php <?php /** * Squiz_Sniffs_PHP_HeredocSniff. * * 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: HeredocSniff.php,v 1.1 2006/12/28 06:03:47 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ require_once 'PHP/CodeSniffer/Sniff.php'; /** * Squiz_Sniffs_PHP_HeredocSniff. * * Heredocs are prohibited. This test enforces that. * * @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_Sniffs_PHP_HeredocSniff implements PHP_CodeSniffer_Sniff { /** * Returns an array of tokens this test wants to listen for. * * @return array */ public function register() { return array(T_START_HEREDOC); }//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) { $error = 'Use of heredoc syntax ("<<<") is not allowed; use standard strings or inline HTML instead'; $phpcsFile->addError($error, $stackPtr); }//end process() }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP/InnerFunctionsSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP/InnerFunctionsSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP/InnerFunctionsSniff.php <?php /** * Squiz_Sniffs_PHP_InnerFunctionsSniff. * * 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: InnerFunctionsSniff.php,v 1.1 2006/12/28 06:03:47 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ require_once 'PHP/CodeSniffer/Sniff.php'; /** * Squiz_Sniffs_PHP_InnerFunctionsSniff. * * Ensures that functions within functions are never used. * * @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_Sniffs_PHP_InnerFunctionsSniff implements PHP_CodeSniffer_Sniff { /** * Returns an array of tokens this test wants to listen for. * * @return array */ public function register() { return array(T_FUNCTION); }//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(); if ($phpcsFile->hasCondition($stackPtr, T_FUNCTION) === true) { $error = 'The use of inner functions is forbidden'; $phpcsFile->addError($error, $stackPtr); } }//end process() }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Strings/DoubleQuoteUsageSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Strings/DoubleQuoteUsageSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Strings/DoubleQuoteUsageSniff.php <?php /** * Squiz_Sniffs_Strings_DoubleQuoteUsageSniff. * * 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: DoubleQuoteUsageSniff.php,v 1.1 2006/12/28 06:03:47 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ require_once 'PHP/CodeSniffer/Sniff.php'; /** * Squiz_Sniffs_Strings_DoubleQuoteUsageSniff. * * Makes sure that any use of Double Quotes ("") are warranted. * * @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_Sniffs_Strings_DoubleQuoteUsageSniff implements PHP_CodeSniffer_Sniff { /** * Returns an array of tokens this test wants to listen for. * * @return array */ public function register() { return array( T_CONSTANT_ENCAPSED_STRING, ); }//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(); $workingString = $tokens[$stackPtr]['content']; // Check if it's a double quoted string. if (strpos($workingString, '"') === false) { return; } // Make sure it's not a part of a string started above. // If it is, then we have already checked it. if ($workingString[0] !== '"') { return; } // Work through the following tokens, in case this string is stretched // over multiple Lines. $limit = count($tokens); for ($i = ($stackPtr + 1); $i < $limit; $i++) { if ($tokens[$i]['type'] !== 'T_CONSTANT_ENCAPSED_STRING') { break; } $workingString .= $tokens[$i]['content']; } $allowedChars = array('\n', '\r', '\t', '\''); foreach ($allowedChars as $testChar) { if (strpos($workingString, $testChar) !== false) { return; } } $error = "String $workingString does not require double quotes; use single quotes instead"; $phpcsFile->addError($error, $stackPtr); }//end process() }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Strings/EchoedStringsSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Strings/EchoedStringsSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Strings/EchoedStringsSniff.php <?php /** * Squiz_Sniffs_Strings_EchoedStringsSniff. * * 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: EchoedStringsSniff.php,v 1.1 2006/12/28 06:03:47 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ require_once 'PHP/CodeSniffer/Sniff.php'; /** * Squiz_Sniffs_Strings_EchoedStringsSniff. * * Makes sure that any strings that are "echoed" are not enclosed in brackets * like a function call. * * @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_Sniffs_Strings_EchoedStringsSniff implements PHP_CodeSniffer_Sniff { /** * Returns an array of tokens this test wants to listen for. * * @return array */ public function register() { return array(T_ECHO); }//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(); $firstContent = $phpcsFile->findNext(array(T_WHITESPACE), $stackPtr + 1, null, true); // If the first non-whitespace token is not an opening parenthesis, then we are not concerned. if ($tokens[$firstContent]['code'] !== T_OPEN_PARENTHESIS) { return; } $endOfStatement = $phpcsFile->findNext(array(T_SEMICOLON), $stackPtr, null, false); // If the token before the semi-colon is not a closing parenthesis, then we are not concerned. if ($tokens[$endOfStatement - 1]['code'] !== T_CLOSE_PARENTHESIS) { return; } if (($phpcsFile->findNext(array(T_MINUS, T_PLUS, T_MULTIPLY, T_DIVIDE, T_MODULUS, T_POWER), $stackPtr, $endOfStatement, false)) === false) { // There are no arithmetic operators in this. $error = 'Echoed strings should not be bracketed'; $phpcsFile->addError($error, $stackPtr); } }//end process() }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/ForbiddenFunctionsUnitTest.inc?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/ForbiddenFunctionsUnitTest.inc +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/ForbiddenFunctionsUnitTest.inc <?php $newfunc = create_function('$a,$b', 'return "ln($a) + ln($b) = " . log($a * $b);'); ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/ForbiddenFunctionsUnitTest.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/ForbiddenFunctionsUnitTest.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/ForbiddenFunctionsUnitTest.php <?php /** * Unit test class for the ForbiddenFunctions 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: ForbiddenFunctionsUnitTest.php,v 1.1 2006/12/28 06:03:47 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ /** * Unit test class for the ForbiddenFunctions 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_ForbiddenFunctionsUnitTest 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, ); }//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 ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/GlobalKeywordUnitTest.inc?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/GlobalKeywordUnitTest.inc +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/GlobalKeywordUnitTest.inc <?php $var = 'hello'; $var2 = 'hello'; $GLOBALS['var'] = 'hello'; function func1() { global $var; global $var, $var2; echo $var; echo $GLOBALS['var']; } ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/GlobalKeywordUnitTest.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/GlobalKeywordUnitTest.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/GlobalKeywordUnitTest.php <?php /** * Unit test class for the GlobalKeyword 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: GlobalKeywordUnitTest.php,v 1.1 2006/12/28 06:03:47 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ /** * Unit test class for the GlobalKeyword 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_GlobalKeywordUnitTest 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( 8 => 1, 9 => 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 ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/HeredocUnitTest.inc?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/HeredocUnitTest.inc +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/HeredocUnitTest.inc <?php $str = <<<EOD Example of string spanning multiple lines using heredoc syntax. EOD; ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/HeredocUnitTest.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/HeredocUnitTest.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/HeredocUnitTest.php <?php /** * Unit test class for the Heredoc 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: HeredocUnitTest.php,v 1.1 2006/12/28 06:03:47 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ /** * Unit test class for the Heredoc 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_HeredocUnitTest 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, ); }//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 ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/InnerFunctionsUnitTest.inc?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/InnerFunctionsUnitTest.inc +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/InnerFunctionsUnitTest.inc <?php function outer() { if (!function_exists('inner')) { function inner() { } } } ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/InnerFunctionsUnitTest.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/InnerFunctionsUnitTest.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/PHP/InnerFunctionsUnitTest.php <?php /** * Unit test class for the InnerFunctions 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: InnerFunctionsUnitTest.php,v 1.1 2006/12/28 06:03:47 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ /** * Unit test class for the InnerFunctions 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_InnerFunctionsUnitTest 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( 5 => 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 ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Strings/DoubleQuoteUsageUnitTest.inc?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Strings/DoubleQuoteUsageUnitTest.inc +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Strings/DoubleQuoteUsageUnitTest.inc <?php $string = "Hello\tThere"; $string = "Hello There\n"; $string = "Hello There"; $string = "Hello $there"; $string = 'Hello'."$there '".'hi'; $string = "My name is 'Greg'"; $string = "Hello"." There"."\n"; ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Strings/DoubleQuoteUsageUnitTest.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Strings/DoubleQuoteUsageUnitTest.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Strings/DoubleQuoteUsageUnitTest.php <?php /** * Unit test class for the DoubleQuoteUsage 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: DoubleQuoteUsageUnitTest.php,v 1.1 2006/12/28 06:03:47 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ /** * Unit test class for the DoubleQuoteUsage 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_Strings_DoubleQuoteUsageUnitTest 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( 4 => 1, 8 => 2, ); }//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 ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Strings/EchoedStringsUnitTest.inc?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Strings/EchoedStringsUnitTest.inc +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Strings/EchoedStringsUnitTest.inc <?php $string = 'hello'; echo $string; echo 'hello'; echo('hello'); echo($hello); echo ('hello'); echo ($hello); ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Strings/EchoedStringsUnitTest.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Strings/EchoedStringsUnitTest.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Strings/EchoedStringsUnitTest.php <?php /** * Unit test class for the EchoedStrings 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: EchoedStringsUnitTest.php,v 1.1 2006/12/28 06:03:47 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ /** * Unit test class for the EchoedStrings 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_Strings_EchoedStringsUnitTest 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( 5 => 1, 6 => 1, 7 => 1, 8 => 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 (#43862) next »