cvs: pear /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Functions FunctionDeclarationSniff.php GlobalFunctionSniff.php
/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions FunctionDeclarationUnitTest.inc FunctionDeclarationUnitTest.php
GlobalFunctionUnitTest.inc GlobalFunctionUnitTest.php

From: Date: Wed, 27 Dec 2006 23:18:37 +0000
Subject: cvs: pear /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Functions FunctionDeclarationSniff.php GlobalFunctionSniff.php
/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions FunctionDeclarationUnitTest.inc FunctionDeclarationUnitTest.php
GlobalFunctionUnitTest.inc GlobalFunctionUnitTest.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-43849@lists.php.net to get a copy of this message
squiz Wed Dec 27 23:18:37 2006 UTC Added files: /pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Functions FunctionDeclarationSniff.php GlobalFunctionSniff.php /pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions FunctionDeclarationUnitTest.inc FunctionDeclarationUnitTest.php GlobalFunctionUnitTest.inc GlobalFunctionUnitTest.php Log: Sniff added to Squiz coding standard

http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Functions/FunctionDeclarationSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Functions/FunctionDeclarationSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Functions/FunctionDeclarationSniff.php <?php /** * Squiz_Sniffs_Functions_FunctionDeclarationSniff. * * 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: FunctionDeclarationSniff.php,v 1.1 2006/12/27 23:18:37 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ require_once 'PHP/CodeSniffer/Standards/AbstractPatternSniff.php'; /** * Squiz_Sniffs_Functions_FunctionDeclarationSniff. * * Checks the function declaration is correct. * * @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_Functions_FunctionDeclarationSniff extends PHP_CodeSniffer_Standards_AbstractPatternSniff { /** * Returns an array of patterns to check are correct. * * @return array */ protected function getPatterns() { return array( 'function abc(...);', 'abstract function abc(...);', "function abc(...)\n", ); }//end getPatterns() }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Functions/GlobalFunctionSniff.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Functions/GlobalFunctionSniff.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Functions/GlobalFunctionSniff.php <?php /** * Squiz_Sniffs_Functions_GlobalFunctionSniff. * * 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: GlobalFunctionSniff.php,v 1.1 2006/12/27 23:18:37 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ require_once 'PHP/CodeSniffer/Sniff.php'; /** * Squiz_Sniffs_Functions_GlobalFunctionSniff. * * Tests for functions outside of classes. * * @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_Functions_GlobalFunctionSniff 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 (empty($tokens[$stackPtr]['conditions']) === true) { $functionName = $phpcsFile->getDeclarationName($stackPtr); $error = "Consider putting global function \"$functionName\" in a static class"; $phpcsFile->addWarning($error, $stackPtr); } }//end process() }//end class ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions/FunctionDeclarationUnitTest.inc?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions/FunctionDeclarationUnitTest.inc +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions/FunctionDeclarationUnitTest.inc <?php function func1() { }//end func1() function func1() { }//end func1() class MyClass { private function func1() { }//end func1() public function func1() { }//end func1() }//end class abstract class MyClass { abstract function func1(); public function func1() { }//end func1() }//end class interface MyInterface { function func1(); function func2() ; }//end interface ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions/FunctionDeclarationUnitTest.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions/FunctionDeclarationUnitTest.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions/FunctionDeclarationUnitTest.php <?php /** * Unit test class for the FunctionDeclaration 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: FunctionDeclarationUnitTest.php,v 1.1 2006/12/27 23:18:37 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ /** * Unit test class for the FunctionDeclaration 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_Functions_FunctionDeclarationUnitTest 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( 10 => 1, 25 => 1, 40 => 1, 55 => 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/Functions/GlobalFunctionUnitTest.inc?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions/GlobalFunctionUnitTest.inc +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions/GlobalFunctionUnitTest.inc <?php function func1() {} class MyClass { function func1() {} } interface MyInterface { function func1() {} } ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions/GlobalFunctionUnitTest.php?view=markup&rev=1.1 Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions/GlobalFunctionUnitTest.php +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions/GlobalFunctionUnitTest.php <?php /** * Unit test class for the GlobalFunction 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: GlobalFunctionUnitTest.php,v 1.1 2006/12/27 23:18:37 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ /** * Unit test class for the GlobalFunction 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_Functions_GlobalFunctionUnitTest 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(); }//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( 2 => 1, ); }//end getWarningList() }//end class ?>
« previous php.pear.cvs (#43849) next »