cvs: pear /PHP_CodeSniffer package.xml /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Commenting DocCommentAlignmentSniff.php
/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Files FileExtensionSniff.php
/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions ValidConstantNameSniff.php ValidFunctionNameSniff.php
ValidInterfaceNameSniff.php ValidVariableNameSniff.php /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Commenting DocCommentAlignmentUnitTest.inc
DocCommentAlignmentUnitTest.php /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Files FileExtensionUnitTest.inc FileExtensionUnitTest.php
/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions ValidFunctionNameUnitTest.inc ValidFunctionNameUnitTest.php
ValidInterfaceNameUnitTest.inc ValidInterfaceNameUnitTest.php ValidVariableNameUnitTest.inc ValidVariableNameUnitTest.php
| From: | Greg Sherwood | Date: | Tue, 02 Jan 2007 00:10:14 +0000 |
| Subject: | cvs: pear /PHP_CodeSniffer package.xml /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Commenting DocCommentAlignmentSniff.php /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Files FileExtensionSniff.php /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions ValidConstantNameSniff.php ValidFunctionNameSniff.php ValidInterfaceNameSniff.php ValidVariableNameSniff.php /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Commenting DocCommentAlignmentUnitTest.inc DocCommentAlignmentUnitTest.php /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Files FileExtensionUnitTest.inc FileExtensionUnitTest.php /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions ValidFunctionNameUnitTest.inc ValidFunctionNameUnitTest.php ValidInterfaceNameUnitTest.inc ValidInterfaceNameUnitTest.php ValidVariableNameUnitTest.inc ValidVariableNameUnitTest.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-43916@lists.php.net to get a copy of this message | ||
squiz Tue Jan 2 00:10:14 2007 UTC
Added files:
/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Commenting
DocCommentAlignmentSniff.php
/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Files
FileExtensionSniff.php
/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions
ValidConstantNameSniff.php
ValidFunctionNameSniff.php
ValidInterfaceNameSniff.php
ValidVariableNameSniff.php
/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Commenting
DocCommentAlignmentUnitTest.inc
DocCommentAlignmentUnitTest.php
/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Files
FileExtensionUnitTest.inc
FileExtensionUnitTest.php
/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions
ValidFunctionNameUnitTest.inc
ValidFunctionNameUnitTest.php
ValidInterfaceNameUnitTest.inc
ValidInterfaceNameUnitTest.php
ValidVariableNameUnitTest.inc
ValidVariableNameUnitTest.php
Modified files:
/pear/PHP_CodeSniffer package.xml
Log:
Sniff added to Squiz coding standard
http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/package.xml?r1=1.21&r2=1.22&diff_format=u Index: pear/PHP_CodeSniffer/package.xml diff -u pear/PHP_CodeSniffer/package.xml:1.21 pear/PHP_CodeSniffer/package.xml:1.22 --- pear/PHP_CodeSniffer/package.xml:1.21 Fri Dec 29 00:07:01 2006 +++ pear/PHP_CodeSniffer/package.xml Tue Jan 2 00:10:14 2007 @@ -420,6 +420,9 @@ <file name="ClosingDeclarationCommentSniff.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> + <file name="DocCommentAlignmentSniff.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> <file name="EmptyCatchCommentSniff.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> @@ -457,6 +460,9 @@ </file> </dir> <dir name="Files"> + <file name="FileExtensionSniff.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> <file name="LineLengthSniff.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> @@ -493,6 +499,18 @@ <file name="UpperCasePhpConstantSniff.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> + <file name="ValidConstantNameSniff.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file name="ValidFunctionNameSniff.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file name="ValidInterfaceNameSniff.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file name="ValidVariableNameSniff.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> </dir> <dir name="PHP"> <file name="DisallowObEndFlushSniff.php"> @@ -591,6 +609,10 @@ <file name="ClosingDeclarationCommentUnitTest.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> + <file name="DocCommentAlignmentUnitTest.inc"/> + <file name="DocCommentAlignmentUnitTest.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> <file name="EmptyCatchCommentUnitTest.inc"/> <file name="EmptyCatchCommentUnitTest.php"> <replace type="package-info" from="@package_version@" to="version"/> @@ -638,6 +660,12 @@ <replace type="package-info" from="@package_version@" to="version"/> </file> </dir> + <dir name="Files"> + <file name="FileExtensionUnitTest.inc"/> + <file name="FileExtensionUnitTest.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> <dir name="Formatting"> <file name="OperatorBracketUnitTest.inc"/> <file name="OperatorBracketUnitTest.php"> @@ -662,6 +690,20 @@ <replace type="package-info" from="@package_version@" to="version"/> </file> </dir> + <dir name="NamingConventions"> + <file name="ValidFunctionNameUnitTest.inc"/> + <file name="ValidFunctionNameUnitTest.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file name="ValidInterfaceNameUnitTest.inc"/> + <file name="ValidInterfaceNameUnitTest.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file name="ValidVariableNameUnitTest.inc"/> + <file name="ValidVariableNameUnitTest.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> <dir name="PHP"> <file name="DisallowObEndFlushUnitTest.inc"/> <file name="DisallowObEndFlushUnitTest.php"> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Commenting/DocCommentAlignmentSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Commenting/DocCommentAlignmentSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Commenting/DocCommentAlignmentSniff.php <?php /** * Squiz_Sniffs_Commenting_EmptyCatchCommentSniff. * * 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: DocCommentAlignmentSniff.php,v 1.1 2007/01/02 00:10:14 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ require_once 'PHP/CodeSniffer/Sniff.php'; /** * Squiz_Sniffs_Commenting_DocCommentAlignmentSniff. * * Tests that the stars in a doc comment align correctly. * * @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_Commenting_DocCommentAlignmentSniff implements PHP_CodeSniffer_Sniff { /** * Returns an array of tokens this test wants to listen for. * * @return array */ public function register() { return array( T_DOC_COMMENT, ); }//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(); // We only want to get the first comment in a block. If there is // a comment on the line before this one, return. $docComment = $phpcsFile->findPrevious(T_DOC_COMMENT, $stackPtr - 1); if ($docComment !== false) { if ($tokens[$docComment]['line'] === ($tokens[$stackPtr]['line'] - 1)) { return; } } $comments = array($stackPtr); $currentComment = $stackPtr; $lastComment = $stackPtr; while (($currentComment = $phpcsFile->findNext(T_DOC_COMMENT, $currentComment + 1)) !== false) { if ($tokens[$lastComment]['line'] === ($tokens[$currentComment]['line'] - 1)) { $comments[] = $currentComment; $lastComment = $currentComment; } else { break; } } // The $comments array now contains pointers to each token in the // comment block. $requiredColumn = strpos($tokens[$stackPtr]['content'], '*'); $requiredColumn += $tokens[$stackPtr]['column']; foreach ($comments as $commentPointer) { $currentColumn = strpos($tokens[$commentPointer]['content'], '*'); $currentColumn += $tokens[$commentPointer]['column']; if ($currentColumn === $requiredColumn) { // Star is aligned correctly. continue; } $expected = ($requiredColumn - 1); $expected .= ($expected === 1) ? ' space' : ' spaces'; $found = ($currentColumn - 1); $error = "Expected $expected before asterisk; $found found"; $phpcsFile->addError($error, $commentPointer); } }//end process() }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Files/FileExtensionSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Files/FileExtensionSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Files/FileExtensionSniff.php <?php /** * Squiz_Sniffs_Files_FileExtensionSniff. * * 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: FileExtensionSniff.php,v 1.1 2007/01/02 00:10:14 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ require_once 'PHP/CodeSniffer/Sniff.php'; /** * Squiz_Sniffs_Files_FileExtensionSniff. * * Tests that the stars in a doc comment align correctly. * * @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_Files_FileExtensionSniff implements PHP_CodeSniffer_Sniff { /** * Returns an array of tokens this test wants to listen for. * * @return array */ public function register() { return array( T_OPEN_TAG, ); }//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(); // Make sure this is the first PHP open tag so we don't process // the same file twice. $prevOpenTag = $phpcsFile->findPrevious(T_OPEN_TAG, $stackPtr - 1); if ($prevOpenTag !== false) { return; } $fileName = $phpcsFile->getFileName(); $extension = substr($fileName, strrpos($fileName, '.')); $nextClass = $phpcsFile->findNext(array(T_CLASS, T_INTERFACE), $stackPtr); if ($extension === '.php') { if ($nextClass !== false) { $error = ucfirst($tokens[$nextClass]['content']).' found in ".php" file; use ".inc" extension instead'; $phpcsFile->addError($error, $stackPtr); } } else if ($extension === '.inc') { if ($nextClass === false) { $error = 'No interface or class found in ".inc" file; use ".php" extension instead'; $phpcsFile->addError($error, $stackPtr); } } }//end process() }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidConstantNameSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidConstantNameSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidConstantNameSniff.php <?php /** * Squiz_Sniffs_NamingConventions_ValidConstantNameSniff. * * 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: ValidConstantNameSniff.php,v 1.1 2007/01/02 00:10:14 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ require_once 'PHP/CodeSniffer/Standards/Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php'; /** * Squiz_Sniffs_NamingConventions_ValidConstantNameSniff. * * Ensures that constant names are all 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_ValidConstantNameSniff extends Generic_Sniffs_NamingConventions_UpperCaseConstantNameSniff { }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidFunctionNameSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidFunctionNameSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidFunctionNameSniff.php <?php /** * Squiz_Sniffs_NamingConventions_ValidFunctionNameSniff. * * 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: ValidFunctionNameSniff.php,v 1.1 2007/01/02 00:10:14 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ require_once 'PHP/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidFunctionNameSniff.php'; /** * Squiz_Sniffs_NamingConventions_ValidFunctionNameSniff. * * Ensures method names are correct depending on whether they are public * or private, and that functions are named correctly. * * @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_ValidFunctionNameSniff extends PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff { /** * Processes the tokens outside the scope. * * @param PHP_CodeSniffer_File $phpcsFile The file being processed. * @param int $stackPtr The position where this token was * found. * * @return void */ protected function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { $functionName = $phpcsFile->getDeclarationName($stackPtr); // Does this function claim to be magical? if (preg_match('|^__|', $functionName) !== 0) { $magicPart = substr($functionName, 2); $error = "Function name \"$functionName\" is invalid; only PHP magic methods should be prefixed with a double underscore."; $phpcsFile->addError($error, $stackPtr); return; } if (PHP_CodeSniffer::isCamelCaps($functionName, false, true, false) === false) { $error = "Function name \"$functionName\" is not in camel caps format"; $phpcsFile->addError($error, $stackPtr); } }//end processTokenOutsideScope() }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidInterfaceNameSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidInterfaceNameSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidInterfaceNameSniff.php <?php /** * Verifies that interface names begin with I. * * 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: ValidInterfaceNameSniff.php,v 1.1 2007/01/02 00:10:14 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ require_once 'PHP/CodeSniffer/Sniff.php'; /** * Verifies that interface names begin with I. * * @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_ValidInterfaceNameSniff implements PHP_CodeSniffer_Sniff { /** * Returns an array of tokens this test wants to listen for. * * @return array */ public function register() { return array( T_INTERFACE, ); }//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(); $interfaceName = $phpcsFile->findNext(T_STRING, $stackPtr); if (($tokens[$interfaceName]['content'][0] !== 'I') || (strtoupper($tokens[$interfaceName]['content'][1]) !== $tokens[$interfaceName]['content'][1])) { $newName = 'I'.$tokens[$interfaceName]['content']; $error = "Interface declaration must start with \"I\"; expected \"interface $newName\""; $phpcsFile->addError($error, $stackPtr); } }//end process() }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php <?php /** * Squiz_Sniffs_NamingConventions_ValidVariableNameSniff. * * 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: ValidVariableNameSniff.php,v 1.1 2007/01/02 00:10:14 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ require_once 'PHP/CodeSniffer/Standards/AbstractVariableSniff.php'; /** * Squiz_Sniffs_NamingConventions_ValidVariableNameSniff. * * Checks the naming of variables and member variables. * * @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_ValidVariableNameSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff { /** * Tokens to igore so that we can find a DOUBLE_COLON. * * @var array */ private $_ignore = array( T_WHITESPACE, T_COMMENT, ); /** * 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 */ protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $varName = ltrim($tokens[$stackPtr]['content'], '$'); $phpReservedVars = array( '_SERVER', '_GET', '_POST', '_REQUEST', 'GLOBALS', ); // If it's a php reserved var, then its ok. if (in_array($varName, $phpReservedVars) === true) { return; } $previous = $phpcsFile->findPrevious($this->_ignore, $stackPtr - 1, null, true); if ($previous !== -1 && $tokens[$previous]['code'] === T_DOUBLE_COLON) { // This is a static variable being referenced. This variable name // will get checked in the code below, so igore this. return; } if (PHP_CodeSniffer::isCamelCaps($varName, false, true) === false) { $error = "Variable \"$varName\" is not in valid camel caps format"; $phpcsFile->addError($error, $stackPtr); } }//end processVariable() /** * Processes class member variables. * * @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 */ protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $varName = ltrim($tokens[$stackPtr]['content'], '$'); $memberProps = $phpcsFile->getMemberProperties($stackPtr); $public = ($memberProps['scope'] !== 'private'); if ($public === true) { if (substr($varName, 0, 1) === '_') { if ($memberProps['scope'] !== '') { $error = ucfirst($memberProps['scope']); } else { $error = 'Public'; } $error .= " member variable \"$varName\" must not contain a leading underscore"; $phpcsFile->addError($error, $stackPtr); return; } } else { if (substr($varName, 0, 1) !== '_') { $error = "Private member variable \"$varName\" must contain a leading underscore"; $phpcsFile->addError($error, $stackPtr); return; } } if (PHP_CodeSniffer::isCamelCaps($varName, false, $public) === false) { $error = "Variable \"$varName\" is not in valid camel caps format"; $phpcsFile->addError($error, $stackPtr); } }//end processMemberVar() /** * Processes the variable found within a double quoted string. * * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. * @param int $stackPtr The position of the double quoted * string. * * @return void */ protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); if (preg_match_all('|\$[a-zA-Z0-9_]+|', $tokens[$stackPtr]['content'], $matches) !== 0) { foreach ($matches as $match) { if (PHP_CodeSniffer::isCamelCaps(ltrim($match[0], '$'), false, true) === false) { $varName = $match[0]; $error = "Variable \"$varName\" is not in valid camel caps format"; $phpcsFile->addError($error, $stackPtr); } } } }//end processVariableInString() }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.inc?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.inc +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.inc <?php /** * Some info about the class here * */ class MyClass { /** * Some info about the function here. * * @return void */ function myFunction() {} } /** * Some info about the class here * */ class MyClass { /** * Some info about the function here. * * @return void */ function myFunction() {} } /** * Some info about the class here * */ class MyClass { /** * Some info about the function here. * * @return void */ function myFunction() {} } ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.php <?php /** * Unit test class for the DocCommentAlignment 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: DocCommentAlignmentUnitTest.php,v 1.1 2007/01/02 00:10:14 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ /** * Unit test class for the DocCommentAlignment 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_Commenting_DocCommentAlignmentUnitTest 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( 17 => 1, 18 => 1, 19 => 1, 23 => 1, 24 => 1, 25 => 1, 26 => 1, 32 => 1, 33 => 1, 38 => 1, 39 => 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/Files/FileExtensionUnitTest.inc?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Files/FileExtensionUnitTest.inc +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Files/FileExtensionUnitTest.inc <?php function myFunction() {} ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Files/FileExtensionUnitTest.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Files/FileExtensionUnitTest.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Files/FileExtensionUnitTest.php <?php /** * Unit test class for the FileExtension 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: FileExtensionUnitTest.php,v 1.1 2007/01/02 00:10:14 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ /** * Unit test class for the FileExtension 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_Files_FileExtensionUnitTest 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( 1 => 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/NamingConventions/ValidFunctionNameUnitTest.inc?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidFunctionNameUnitTest.inc +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidFunctionNameUnitTest.inc <?php function getSomeValue() {} function parseMyDSN() {} function get_some_value() {} function getSomeValue_Again() {} function _getSomeValue() {} function _parseMyDSN() {} function _get_some_value() {} function _getSomeValue_Again() {} function __construct() {} function __destruct() {} function __myFunction() {} function __my_function() {} ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidFunctionNameUnitTest.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidFunctionNameUnitTest.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidFunctionNameUnitTest.php <?php /** * Unit test class for the ValidFunctionName 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: ValidFunctionNameUnitTest.php,v 1.1 2007/01/02 00:10:14 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ /** * Unit test class for the ValidFunctionName 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_NamingConventions_ValidFunctionNameUnitTest 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, 5 => 1, 6 => 1, 7 => 1, 8 => 1, 9 => 1, 11 => 1, 12 => 1, 13 => 1, 14 => 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/NamingConventions/ValidInterfaceNameUnitTest.inc?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidInterfaceNameUnitTest.inc +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidInterfaceNameUnitTest.inc <?php interface IMyInterface {} interface MyInterface {} ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidInterfaceNameUnitTest.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidInterfaceNameUnitTest.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidInterfaceNameUnitTest.php <?php /** * Unit test class for the ValidInterfaceName 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: ValidInterfaceNameUnitTest.php,v 1.1 2007/01/02 00:10:14 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ /** * Unit test class for the ValidInterfaceName 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_NamingConventions_ValidInterfaceNameUnitTest 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( 3 => 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/NamingConventions/ValidVariableNameUnitTest.inc?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.inc +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.inc <?php $varName = 'hello'; $var_name = 'hello'; $varname = 'hello'; $_varName = 'hello'; class MyClass { public $varName = 'hello'; public $var_name = 'hello'; public $varname = 'hello'; public $_varName = 'hello'; protected $varName = 'hello'; protected $var_name = 'hello'; protected $varname = 'hello'; protected $_varName = 'hello'; private $_varName = 'hello'; private $_var_name = 'hello'; private $_varname = 'hello'; private $varName = 'hello'; } echo $varName; echo $var_name; echo $varname; echo $_varName; ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.php <?php /** * Unit test class for the ValidVariableName 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: ValidVariableNameUnitTest.php,v 1.1 2007/01/02 00:10:14 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ /** * Unit test class for the ValidVariableName 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_NamingConventions_ValidVariableNameUnitTest 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( 3 => 1, 5 => 1, 10 => 1, 12 => 1, 15 => 1, 17 => 1, 20 => 1, 22 => 1, 26 => 1, 28 => 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/package.xml?r1=1.21&r2=1.22&diff_format=u Index: pear/PHP_CodeSniffer/package.xml diff -u pear/PHP_CodeSniffer/package.xml:1.21 pear/PHP_CodeSniffer/package.xml:1.22 --- pear/PHP_CodeSniffer/package.xml:1.21 Fri Dec 29 00:07:01 2006 +++ pear/PHP_CodeSniffer/package.xml Tue Jan 2 00:10:14 2007 @@ -420,6 +420,9 @@ <file name="ClosingDeclarationCommentSniff.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> + <file name="DocCommentAlignmentSniff.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> <file name="EmptyCatchCommentSniff.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> @@ -457,6 +460,9 @@ </file> </dir> <dir name="Files"> + <file name="FileExtensionSniff.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> <file name="LineLengthSniff.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> @@ -493,6 +499,18 @@ <file name="UpperCasePhpConstantSniff.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> + <file name="ValidConstantNameSniff.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file name="ValidFunctionNameSniff.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file name="ValidInterfaceNameSniff.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file name="ValidVariableNameSniff.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> </dir> <dir name="PHP"> <file name="DisallowObEndFlushSniff.php"> @@ -591,6 +609,10 @@ <file name="ClosingDeclarationCommentUnitTest.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> + <file name="DocCommentAlignmentUnitTest.inc"/> + <file name="DocCommentAlignmentUnitTest.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> <file name="EmptyCatchCommentUnitTest.inc"/> <file name="EmptyCatchCommentUnitTest.php"> <replace type="package-info" from="@package_version@" to="version"/> @@ -638,6 +660,12 @@ <replace type="package-info" from="@package_version@" to="version"/> </file> </dir> + <dir name="Files"> + <file name="FileExtensionUnitTest.inc"/> + <file name="FileExtensionUnitTest.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> <dir name="Formatting"> <file name="OperatorBracketUnitTest.inc"/> <file name="OperatorBracketUnitTest.php"> @@ -662,6 +690,20 @@ <replace type="package-info" from="@package_version@" to="version"/> </file> </dir> + <dir name="NamingConventions"> + <file name="ValidFunctionNameUnitTest.inc"/> + <file name="ValidFunctionNameUnitTest.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file name="ValidInterfaceNameUnitTest.inc"/> + <file name="ValidInterfaceNameUnitTest.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file name="ValidVariableNameUnitTest.inc"/> + <file name="ValidVariableNameUnitTest.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> <dir name="PHP"> <file name="DisallowObEndFlushUnitTest.inc"/> <file name="DisallowObEndFlushUnitTest.php"> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Commenting/DocCommentAlignmentSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Commenting/DocCommentAlignmentSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Commenting/DocCommentAlignmentSniff.php <?php /** * Squiz_Sniffs_Commenting_EmptyCatchCommentSniff. * * 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: DocCommentAlignmentSniff.php,v 1.1 2007/01/02 00:10:14 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ require_once 'PHP/CodeSniffer/Sniff.php'; /** * Squiz_Sniffs_Commenting_DocCommentAlignmentSniff. * * Tests that the stars in a doc comment align correctly. * * @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_Commenting_DocCommentAlignmentSniff implements PHP_CodeSniffer_Sniff { /** * Returns an array of tokens this test wants to listen for. * * @return array */ public function register() { return array( T_DOC_COMMENT, ); }//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(); // We only want to get the first comment in a block. If there is // a comment on the line before this one, return. $docComment = $phpcsFile->findPrevious(T_DOC_COMMENT, $stackPtr - 1); if ($docComment !== false) { if ($tokens[$docComment]['line'] === ($tokens[$stackPtr]['line'] - 1)) { return; } } $comments = array($stackPtr); $currentComment = $stackPtr; $lastComment = $stackPtr; while (($currentComment = $phpcsFile->findNext(T_DOC_COMMENT, $currentComment + 1)) !== false) { if ($tokens[$lastComment]['line'] === ($tokens[$currentComment]['line'] - 1)) { $comments[] = $currentComment; $lastComment = $currentComment; } else { break; } } // The $comments array now contains pointers to each token in the // comment block. $requiredColumn = strpos($tokens[$stackPtr]['content'], '*'); $requiredColumn += $tokens[$stackPtr]['column']; foreach ($comments as $commentPointer) { $currentColumn = strpos($tokens[$commentPointer]['content'], '*'); $currentColumn += $tokens[$commentPointer]['column']; if ($currentColumn === $requiredColumn) { // Star is aligned correctly. continue; } $expected = ($requiredColumn - 1); $expected .= ($expected === 1) ? ' space' : ' spaces'; $found = ($currentColumn - 1); $error = "Expected $expected before asterisk; $found found"; $phpcsFile->addError($error, $commentPointer); } }//end process() }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Files/FileExtensionSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Files/FileExtensionSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Files/FileExtensionSniff.php <?php /** * Squiz_Sniffs_Files_FileExtensionSniff. * * 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: FileExtensionSniff.php,v 1.1 2007/01/02 00:10:14 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ require_once 'PHP/CodeSniffer/Sniff.php'; /** * Squiz_Sniffs_Files_FileExtensionSniff. * * Tests that the stars in a doc comment align correctly. * * @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_Files_FileExtensionSniff implements PHP_CodeSniffer_Sniff { /** * Returns an array of tokens this test wants to listen for. * * @return array */ public function register() { return array( T_OPEN_TAG, ); }//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(); // Make sure this is the first PHP open tag so we don't process // the same file twice. $prevOpenTag = $phpcsFile->findPrevious(T_OPEN_TAG, $stackPtr - 1); if ($prevOpenTag !== false) { return; } $fileName = $phpcsFile->getFileName(); $extension = substr($fileName, strrpos($fileName, '.')); $nextClass = $phpcsFile->findNext(array(T_CLASS, T_INTERFACE), $stackPtr); if ($extension === '.php') { if ($nextClass !== false) { $error = ucfirst($tokens[$nextClass]['content']).' found in ".php" file; use ".inc" extension instead'; $phpcsFile->addError($error, $stackPtr); } } else if ($extension === '.inc') { if ($nextClass === false) { $error = 'No interface or class found in ".inc" file; use ".php" extension instead'; $phpcsFile->addError($error, $stackPtr); } } }//end process() }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidConstantNameSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidConstantNameSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidConstantNameSniff.php <?php /** * Squiz_Sniffs_NamingConventions_ValidConstantNameSniff. * * 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: ValidConstantNameSniff.php,v 1.1 2007/01/02 00:10:14 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ require_once 'PHP/CodeSniffer/Standards/Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php'; /** * Squiz_Sniffs_NamingConventions_ValidConstantNameSniff. * * Ensures that constant names are all 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_ValidConstantNameSniff extends Generic_Sniffs_NamingConventions_UpperCaseConstantNameSniff { }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidFunctionNameSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidFunctionNameSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidFunctionNameSniff.php <?php /** * Squiz_Sniffs_NamingConventions_ValidFunctionNameSniff. * * 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: ValidFunctionNameSniff.php,v 1.1 2007/01/02 00:10:14 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ require_once 'PHP/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidFunctionNameSniff.php'; /** * Squiz_Sniffs_NamingConventions_ValidFunctionNameSniff. * * Ensures method names are correct depending on whether they are public * or private, and that functions are named correctly. * * @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_ValidFunctionNameSniff extends PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff { /** * Processes the tokens outside the scope. * * @param PHP_CodeSniffer_File $phpcsFile The file being processed. * @param int $stackPtr The position where this token was * found. * * @return void */ protected function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { $functionName = $phpcsFile->getDeclarationName($stackPtr); // Does this function claim to be magical? if (preg_match('|^__|', $functionName) !== 0) { $magicPart = substr($functionName, 2); $error = "Function name \"$functionName\" is invalid; only PHP magic methods should be prefixed with a double underscore."; $phpcsFile->addError($error, $stackPtr); return; } if (PHP_CodeSniffer::isCamelCaps($functionName, false, true, false) === false) { $error = "Function name \"$functionName\" is not in camel caps format"; $phpcsFile->addError($error, $stackPtr); } }//end processTokenOutsideScope() }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidInterfaceNameSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidInterfaceNameSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidInterfaceNameSniff.php <?php /** * Verifies that interface names begin with I. * * 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: ValidInterfaceNameSniff.php,v 1.1 2007/01/02 00:10:14 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ require_once 'PHP/CodeSniffer/Sniff.php'; /** * Verifies that interface names begin with I. * * @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_ValidInterfaceNameSniff implements PHP_CodeSniffer_Sniff { /** * Returns an array of tokens this test wants to listen for. * * @return array */ public function register() { return array( T_INTERFACE, ); }//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(); $interfaceName = $phpcsFile->findNext(T_STRING, $stackPtr); if (($tokens[$interfaceName]['content'][0] !== 'I') || (strtoupper($tokens[$interfaceName]['content'][1]) !== $tokens[$interfaceName]['content'][1])) { $newName = 'I'.$tokens[$interfaceName]['content']; $error = "Interface declaration must start with \"I\"; expected \"interface $newName\""; $phpcsFile->addError($error, $stackPtr); } }//end process() }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php <?php /** * Squiz_Sniffs_NamingConventions_ValidVariableNameSniff. * * 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: ValidVariableNameSniff.php,v 1.1 2007/01/02 00:10:14 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ require_once 'PHP/CodeSniffer/Standards/AbstractVariableSniff.php'; /** * Squiz_Sniffs_NamingConventions_ValidVariableNameSniff. * * Checks the naming of variables and member variables. * * @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_ValidVariableNameSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff { /** * Tokens to igore so that we can find a DOUBLE_COLON. * * @var array */ private $_ignore = array( T_WHITESPACE, T_COMMENT, ); /** * 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 */ protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $varName = ltrim($tokens[$stackPtr]['content'], '$'); $phpReservedVars = array( '_SERVER', '_GET', '_POST', '_REQUEST', 'GLOBALS', ); // If it's a php reserved var, then its ok. if (in_array($varName, $phpReservedVars) === true) { return; } $previous = $phpcsFile->findPrevious($this->_ignore, $stackPtr - 1, null, true); if ($previous !== -1 && $tokens[$previous]['code'] === T_DOUBLE_COLON) { // This is a static variable being referenced. This variable name // will get checked in the code below, so igore this. return; } if (PHP_CodeSniffer::isCamelCaps($varName, false, true) === false) { $error = "Variable \"$varName\" is not in valid camel caps format"; $phpcsFile->addError($error, $stackPtr); } }//end processVariable() /** * Processes class member variables. * * @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 */ protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $varName = ltrim($tokens[$stackPtr]['content'], '$'); $memberProps = $phpcsFile->getMemberProperties($stackPtr); $public = ($memberProps['scope'] !== 'private'); if ($public === true) { if (substr($varName, 0, 1) === '_') { if ($memberProps['scope'] !== '') { $error = ucfirst($memberProps['scope']); } else { $error = 'Public'; } $error .= " member variable \"$varName\" must not contain a leading underscore"; $phpcsFile->addError($error, $stackPtr); return; } } else { if (substr($varName, 0, 1) !== '_') { $error = "Private member variable \"$varName\" must contain a leading underscore"; $phpcsFile->addError($error, $stackPtr); return; } } if (PHP_CodeSniffer::isCamelCaps($varName, false, $public) === false) { $error = "Variable \"$varName\" is not in valid camel caps format"; $phpcsFile->addError($error, $stackPtr); } }//end processMemberVar() /** * Processes the variable found within a double quoted string. * * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. * @param int $stackPtr The position of the double quoted * string. * * @return void */ protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); if (preg_match_all('|\$[a-zA-Z0-9_]+|', $tokens[$stackPtr]['content'], $matches) !== 0) { foreach ($matches as $match) { if (PHP_CodeSniffer::isCamelCaps(ltrim($match[0], '$'), false, true) === false) { $varName = $match[0]; $error = "Variable \"$varName\" is not in valid camel caps format"; $phpcsFile->addError($error, $stackPtr); } } } }//end processVariableInString() }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.inc?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.inc +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.inc <?php /** * Some info about the class here * */ class MyClass { /** * Some info about the function here. * * @return void */ function myFunction() {} } /** * Some info about the class here * */ class MyClass { /** * Some info about the function here. * * @return void */ function myFunction() {} } /** * Some info about the class here * */ class MyClass { /** * Some info about the function here. * * @return void */ function myFunction() {} } ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.php <?php /** * Unit test class for the DocCommentAlignment 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: DocCommentAlignmentUnitTest.php,v 1.1 2007/01/02 00:10:14 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ /** * Unit test class for the DocCommentAlignment 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_Commenting_DocCommentAlignmentUnitTest 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( 17 => 1, 18 => 1, 19 => 1, 23 => 1, 24 => 1, 25 => 1, 26 => 1, 32 => 1, 33 => 1, 38 => 1, 39 => 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/Files/FileExtensionUnitTest.inc?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Files/FileExtensionUnitTest.inc +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Files/FileExtensionUnitTest.inc <?php function myFunction() {} ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Files/FileExtensionUnitTest.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Files/FileExtensionUnitTest.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Files/FileExtensionUnitTest.php <?php /** * Unit test class for the FileExtension 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: FileExtensionUnitTest.php,v 1.1 2007/01/02 00:10:14 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ /** * Unit test class for the FileExtension 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_Files_FileExtensionUnitTest 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( 1 => 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/NamingConventions/ValidFunctionNameUnitTest.inc?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidFunctionNameUnitTest.inc +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidFunctionNameUnitTest.inc <?php function getSomeValue() {} function parseMyDSN() {} function get_some_value() {} function getSomeValue_Again() {} function _getSomeValue() {} function _parseMyDSN() {} function _get_some_value() {} function _getSomeValue_Again() {} function __construct() {} function __destruct() {} function __myFunction() {} function __my_function() {} ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidFunctionNameUnitTest.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidFunctionNameUnitTest.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidFunctionNameUnitTest.php <?php /** * Unit test class for the ValidFunctionName 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: ValidFunctionNameUnitTest.php,v 1.1 2007/01/02 00:10:14 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ /** * Unit test class for the ValidFunctionName 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_NamingConventions_ValidFunctionNameUnitTest 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, 5 => 1, 6 => 1, 7 => 1, 8 => 1, 9 => 1, 11 => 1, 12 => 1, 13 => 1, 14 => 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/NamingConventions/ValidInterfaceNameUnitTest.inc?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidInterfaceNameUnitTest.inc +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidInterfaceNameUnitTest.inc <?php interface IMyInterface {} interface MyInterface {} ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidInterfaceNameUnitTest.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidInterfaceNameUnitTest.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidInterfaceNameUnitTest.php <?php /** * Unit test class for the ValidInterfaceName 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: ValidInterfaceNameUnitTest.php,v 1.1 2007/01/02 00:10:14 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ /** * Unit test class for the ValidInterfaceName 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_NamingConventions_ValidInterfaceNameUnitTest 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( 3 => 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/NamingConventions/ValidVariableNameUnitTest.inc?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.inc +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.inc <?php $varName = 'hello'; $var_name = 'hello'; $varname = 'hello'; $_varName = 'hello'; class MyClass { public $varName = 'hello'; public $var_name = 'hello'; public $varname = 'hello'; public $_varName = 'hello'; protected $varName = 'hello'; protected $var_name = 'hello'; protected $varname = 'hello'; protected $_varName = 'hello'; private $_varName = 'hello'; private $_var_name = 'hello'; private $_varname = 'hello'; private $varName = 'hello'; } echo $varName; echo $var_name; echo $varname; echo $_varName; ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.php <?php /** * Unit test class for the ValidVariableName 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: ValidVariableNameUnitTest.php,v 1.1 2007/01/02 00:10:14 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ /** * Unit test class for the ValidVariableName 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_NamingConventions_ValidVariableNameUnitTest 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( 3 => 1, 5 => 1, 10 => 1, 12 => 1, 15 => 1, 17 => 1, 20 => 1, 22 => 1, 26 => 1, 28 => 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 ?>