Subversion Repositories Applications.framework

Compare Revisions

Problem with comparison.

Ignore whitespace Rev HEAD → Rev 5

/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Docs/Functions/OpeningFunctionBraceBsdAllmanStandard.xml
New file
0,0 → 1,24
<documentation title="Opening Brace in Function Declarations">
<standard>
<![CDATA[
Function declarations follow the "BSD/Allman style". The function brace is on the line following the function declaration and is indented to the same column as the start of the function declaration.
]]>
</standard>
<code_comparison>
<code title="Valid: brace on next line">
<![CDATA[
function fooFunction($arg1, $arg2 = '')
<em>{</em>
...
}
]]>
</code>
<code title="Invalid: brace on same line">
<![CDATA[
function fooFunction($arg1, $arg2 = '') <em>{</em>
...
}
]]>
</code>
</code_comparison>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Docs/Functions/OpeningFunctionBraceKernighanRitchieStandard.xml
New file
0,0 → 1,24
<documentation title="Opening Brace in Function Declarations">
<standard>
<![CDATA[
Function declarations follow the "Kernighan/Ritchie style". The function brace is on the same line as the function declaration. One space is required between the closing parenthesis and the brace.
]]>
</standard>
<code_comparison>
<code title="Valid: brace on same line">
<![CDATA[
function fooFunction($arg1, $arg2 = '')<em> {</em>
...
}
]]>
</code>
<code title="Invalid: brace on next line">
<![CDATA[
function fooFunction($arg1, $arg2 = '')
<em>{</em>
...
}
]]>
</code>
</code_comparison>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Docs/Formatting/MultipleStatementAlignmentStandard.xml
New file
0,0 → 1,56
<documentation title="Aligning Blocks of Assignments">
<standard>
<![CDATA[
There should be one space on either side of an equals sign used to assign a value to a variable. In the case of a block of related assignments, more space may be inserted to promote readability.
]]>
</standard>
<code_comparison>
<code title="Equals signs aligned">
<![CDATA[
$shortVar <em>=</em> (1 + 2);
$veryLongVarName <em>=</em> 'string';
$var <em>=</em> foo($bar, $baz, $quux);
]]>
</code>
<code title="Not aligned; harder to read">
<![CDATA[
$shortVar <em>=</em> (1 + 2);
$veryLongVarName <em>=</em> 'string';
$var <em>=</em> foo($bar, $baz, $quux);
]]>
</code>
</code_comparison>
<standard>
<![CDATA[
When using plus-equals, minus-equals etc. still ensure the equals signs are aligned to one space after the longest variable name.
]]>
</standard>
<code_comparison>
<code title="Equals signs aligned; only one space after longest var name">
<![CDATA[
$shortVar <em>+= </em>1;
$veryLongVarName<em> = </em>1;
]]>
</code>
<code title="Two spaces after longest var name">
<![CDATA[
$shortVar <em> += </em>1;
$veryLongVarName<em> = </em>1;
]]>
</code>
</code_comparison>
<code_comparison>
<code title="Equals signs aligned">
<![CDATA[
$shortVar <em> = </em>1;
$veryLongVarName<em> -= </em>1;
]]>
</code>
<code title="Equals signs not aligned">
<![CDATA[
$shortVar <em> = </em>1;
$veryLongVarName<em> -= </em>1;
]]>
</code>
</code_comparison>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Docs/NamingConventions/UpperCaseConstantNameStandard.xml
New file
0,0 → 1,29
<documentation title="Constant Names">
<standard>
<![CDATA[
Constants should always be all-uppercase, with underscores to separate words.
]]>
</standard>
<code_comparison>
<code title="Valid: all uppercase">
<![CDATA[
define('<em>FOO_CONSTANT</em>', 'foo');
 
class FooClass
{
const <em>FOO_CONSTANT</em> = 'foo';
}
]]>
</code>
<code title="Invalid: mixed case">
<![CDATA[
define('<em>Foo_Constant</em>', 'foo');
 
class FooClass
{
const <em>foo_constant</em> = 'foo';
}
]]>
</code>
</code_comparison>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Docs/Files/LineLengthStandard.xml
New file
0,0 → 1,7
<documentation title="Line Length">
<standard>
<![CDATA[
It is recommended to keep lines at approximately 80 characters long for better code readability.
]]>
</standard>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Docs/PHP/DisallowShortOpenTagStandard.xml
New file
0,0 → 1,7
<documentation title="PHP Code Tags">
<standard>
<![CDATA[
Always use <?php ?> to delimit PHP code, not the <? ?> shorthand. This is the most portable way to include PHP code on differing operating systems and setups.
]]>
</standard>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Docs/PHP/LowerCaseConstantStandard.xml
New file
0,0 → 1,23
<documentation title="PHP Constants">
<standard>
<![CDATA[
The <em>true</em>, <em>false</em> and <em>null</em> constants must always be lowercase.
]]>
</standard>
<code_comparison>
<code title="Valid: lowercase constants">
<![CDATA[
if ($var === <em>false</em> || $var === <em>null</em>) {
$var = <em>true</em>;
}
]]>
</code>
<code title="Invalid: uppercase constants">
<![CDATA[
if ($var === <em>FALSE</em> || $var === <em>NULL</em>) {
$var = <em>TRUE</em>;
}
]]>
</code>
</code_comparison>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Docs/PHP/UpperCaseConstantStandard.xml
New file
0,0 → 1,23
<documentation title="PHP Constants">
<standard>
<![CDATA[
The <em>true</em>, <em>false</em> and <em>null</em> constants must always be uppercase.
]]>
</standard>
<code_comparison>
<code title="Valid: uppercase constants">
<![CDATA[
if ($var === <em>FALSE</em> || $var === <em>NULL</em>) {
$var = <em>TRUE</em>;
}
]]>
</code>
<code title="Invalid: lowercase constants">
<![CDATA[
if ($var === <em>false</em> || $var === <em>null</em>) {
$var = <em>true</em>;
}
]]>
</code>
</code_comparison>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Commenting/TodoSniff.php
New file
0,0 → 1,88
<?php
/**
* Generic_Sniffs_Commenting_TodoSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: TodoSniff.php,v 1.3 2008/12/02 02:38:34 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_Commenting_TodoSniff.
*
* Warns about TODO comments.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Commenting_TodoSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
'JS',
);
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return PHP_CodeSniffer_Tokens::$commentTokens;
 
}//end register()
 
 
/**
* Processes this sniff, 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();
 
$content = $tokens[$stackPtr]['content'];
$matches = Array();
if (preg_match('|[^a-z]+todo[^a-z]+(.*)|i', $content, $matches) !== 0) {
// Clear whitespace and some common characters not required at
// the end of a to-do message to make the warning more informative.
$todoMessage = trim($matches[1]);
$todoMessage = trim($todoMessage, '[]().');
$error = 'Comment refers to a TODO task';
if ($todoMessage !== '') {
$error .= " \"$todoMessage\"";
}
 
$phpcsFile->addWarning($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Files/LineEndingsSniff.php
New file
0,0 → 1,99
<?php
/**
* Generic_Sniffs_Files_LineEndingsSniff.
*
* 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: LineEndingsSniff.php,v 1.4 2008/10/28 04:42:37 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_Files_LineEndingsSniff.
*
* Checks that end of line characters are 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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Files_LineEndingsSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
'JS',
'CSS',
);
 
/**
* The valid EOL character.
*
* @var string
*/
protected $eolChar = "\n";
 
 
/**
* 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 sniff, 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)
{
// We are only interested if this is the first open tag.
if ($stackPtr !== 0) {
if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) {
return;
}
}
 
if ($phpcsFile->eolChar !== $this->eolChar) {
$expected = $this->eolChar;
$expected = str_replace("\n", '\n', $expected);
$expected = str_replace("\r", '\r', $expected);
$found = $phpcsFile->eolChar;
$found = str_replace("\n", '\n', $found);
$found = str_replace("\r", '\r', $found);
$error = "End of line character is invalid; expected \"$expected\" but found \"$found\"";
$phpcsFile->addError($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Files/LineLengthSniff.php
New file
0,0 → 1,134
<?php
/**
* Generic_Sniffs_Files_LineLengthSniff.
*
* 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: LineLengthSniff.php,v 1.16 2008/06/27 01:58:38 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_Files_LineLengthSniff.
*
* Checks all lines in the file, and throws warnings if they are over 80
* characters in length and errors if they are over 100. Both these
* figures can be changed by extending this sniff in your own standard.
*
* @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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Files_LineLengthSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* The limit that the length of a line should not exceed.
*
* @var int
*/
protected $lineLimit = 80;
 
/**
* The limit that the length of a line must not exceed.
*
* Set to zero (0) to disable.
*
* @var int
*/
protected $absoluteLineLimit = 100;
 
 
/**
* 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 open tag.
$previousOpenTag = $phpcsFile->findPrevious(array(T_OPEN_TAG), ($stackPtr - 1));
if ($previousOpenTag !== false) {
return;
}
 
$tokenCount = 0;
$currentLineContent = '';
$currentLine = 1;
 
for (; $tokenCount < $phpcsFile->numTokens; $tokenCount++) {
if ($tokens[$tokenCount]['line'] === $currentLine) {
$currentLineContent .= $tokens[$tokenCount]['content'];
} else {
$currentLineContent = trim($currentLineContent, $phpcsFile->eolChar);
$this->checkLineLength($phpcsFile, ($tokenCount - 1), $currentLineContent);
$currentLineContent = $tokens[$tokenCount]['content'];
$currentLine++;
}
}
 
$this->checkLineLength($phpcsFile, ($tokenCount - 1), $currentLineContent);
 
}//end process()
 
 
/**
* Checks if a line is too long.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The token at the end of the line.
* @param string $lineContent The content of the line.
*
* @return void
*/
protected function checkLineLength(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $lineContent)
{
// If the content is a CVS or SVN id in a version tag, or it is
// a license tag with a name and URL, there is nothing the
// developer can do to shorten the line, so don't throw errors.
if (preg_match('|@version[^\$]+\$Id|', $lineContent) === 0 && preg_match('|@license|', $lineContent) === 0) {
$lineLength = strlen($lineContent);
if ($this->absoluteLineLimit > 0 && $lineLength > $this->absoluteLineLimit) {
$error = 'Line exceeds maximum limit of '.$this->absoluteLineLimit." characters; contains $lineLength characters";
$phpcsFile->addError($error, $stackPtr);
} else if ($lineLength > $this->lineLimit) {
$warning = 'Line exceeds '.$this->lineLimit." characters; contains $lineLength characters";
$phpcsFile->addWarning($warning, $stackPtr);
}
}
 
}//end checkLineLength()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php
New file
0,0 → 1,120
<?php
/**
* Generic_Sniffs_ControlStructures_InlineControlStructureSniff.
*
* 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: InlineControlStructureSniff.php,v 1.1 2008/05/01 00:49:31 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_ControlStructures_InlineControlStructureSniff.
*
* Verifies that inline control statements are not present.
*
* @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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_ControlStructures_InlineControlStructureSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
'JS',
);
 
/**
* If true, an error will be thrown; otherwise a warning.
*
* @var bool
*/
protected $error = true;
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_IF,
T_ELSE,
T_FOREACH,
T_WHILE,
T_DO,
T_SWITCH,
T_FOR,
);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
if (isset($tokens[$stackPtr]['scope_opener']) === false) {
// Ignore the ELSE in ELSE IF. We'll process the IF part later.
if (($tokens[$stackPtr]['code'] === T_ELSE) && ($tokens[($stackPtr + 2)]['code'] === T_IF)) {
return;
}
 
if ($tokens[$stackPtr]['code'] === T_WHILE) {
// This could be from a DO WHILE, which doesn't have an opening brace.
$lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
if ($tokens[$lastContent]['code'] === T_CLOSE_CURLY_BRACKET) {
$brace = $tokens[$lastContent];
if (isset($brace['scope_condition']) === true) {
$condition = $tokens[$brace['scope_condition']];
if ($condition['code'] === T_DO) {
return;
}
}
}
}
 
// This is a control structure without an opening brace,
// so it is an inline statement.
if ($this->error === true) {
$phpcsFile->addError('Inline control structures are not allowed', $stackPtr);
} else {
$phpcsFile->addWarning('Inline control structures are discouraged', $stackPtr);
}
 
return;
}//end if
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Metrics/NestingLevelSniff.php
New file
0,0 → 1,107
<?php
/**
* Checks the nesting level for methods.
*
* 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: NestingLevelSniff.php,v 1.1 2007/07/30 04:55:35 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Checks the nesting level for methods.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Johann-Peter Hartmann <hartmann@mayflower.de>
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2007 Mayflower GmbH
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Metrics_NestingLevelSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* A nesting level than this value will throw a warning.
*
* @var int
*/
protected $nestingLevel = 5;
 
/**
* A nesting level than this value will throw an error.
*
* @var int
*/
protected $absoluteNestingLevel = 10;
 
 
/**
* 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();
 
// Ignore abstract methods.
if (isset($tokens[$stackPtr]['scope_opener']) === false) {
return;
}
 
// Detect start and end of this function definition.
$start = $tokens[$stackPtr]['scope_opener'];
$end = $tokens[$stackPtr]['scope_closer'];
 
$nestingLevel = 0;
 
// Find the maximum nesting level of any token in the function.
for ($i = ($start + 1); $i < $end; $i++) {
$level = $tokens[$i]['level'];
if ($nestingLevel < $level) {
$nestingLevel = $level;
}
}
 
// We subtract the nesting level of the function itself.
$nestingLevel = ($nestingLevel - $tokens[$stackPtr]['level'] - 1);
 
if ($nestingLevel > $this->absoluteNestingLevel) {
$error = "Function's nesting level ($nestingLevel) exceeds allowed maximum of ".$this->absoluteNestingLevel;
$phpcsFile->addError($error, $stackPtr);
} else if ($nestingLevel > $this->nestingLevel) {
$warning = "Function's nesting level ($nestingLevel) exceeds ".$this->nestingLevel.'; consider refactoring the function';
$phpcsFile->addWarning($warning, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Metrics/CyclomaticComplexitySniff.php
New file
0,0 → 1,124
<?php
/**
* Checks the cyclomatic complexity (McCabe) for functions.
*
* 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: CyclomaticComplexitySniff.php,v 1.1 2007/07/30 04:55:35 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Checks the cyclomatic complexity (McCabe) for functions.
*
* The cyclomatic complexity (also called McCabe code metrics)
* indicates the complexity within a function by counting
* the different paths the function includes.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Johann-Peter Hartmann <hartmann@mayflower.de>
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2007 Mayflower GmbH
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Metrics_CyclomaticComplexitySniff implements PHP_CodeSniffer_Sniff
{
 
/**
* A complexity higher than this value will throw a warning.
*
* @var int
*/
protected $complexity = 10;
 
/**
* A complexity higer than this value will throw an error.
*
* @var int
*/
protected $absoluteComplexity = 20;
 
 
/**
* 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)
{
$this->currentFile = $phpcsFile;
 
$tokens = $phpcsFile->getTokens();
 
// Ignore abstract methods.
if (isset($tokens[$stackPtr]['scope_opener']) === false) {
return;
}
 
// Detect start and end of this function definition.
$start = $tokens[$stackPtr]['scope_opener'];
$end = $tokens[$stackPtr]['scope_closer'];
 
// Predicate nodes for PHP.
$find = array(
'T_CASE',
'T_DEFAULT',
'T_CATCH',
'T_IF',
'T_FOR',
'T_FOREACH',
'T_WHILE',
'T_DO',
'T_ELSEIF',
);
 
$complexity = 1;
 
// Iterate from start to end and count predicate nodes.
for ($i = ($start + 1); $i < $end; $i++) {
if (in_array($tokens[$i]['type'], $find) === true) {
$complexity++;
}
}
 
if ($complexity > $this->absoluteComplexity) {
$error = "Function's cyclomatic complexity ($complexity) exceeds allowed maximum of ".$this->absoluteComplexity;
$phpcsFile->addError($error, $stackPtr);
} else if ($complexity > $this->complexity) {
$warning = "Function's cyclomatic complexity ($complexity) exceeds ".$this->complexity.'; consider refactoring the function';
$phpcsFile->addWarning($warning, $stackPtr);
}
 
return;
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/VersionControl/SubversionPropertiesSniff.php
New file
0,0 → 1,169
<?php
/**
* Generic_Sniffs_VersionControl_SubversionPropertiesSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Jack Bates <ms419@freezone.co.uk>
* @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: SubversionPropertiesSniff.php,v 1.1 2009/01/05 01:07:47 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_VersionControl_SubversionPropertiesSniff.
*
* Tests that the correct Subversion properties are set.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Jack Bates <ms419@freezone.co.uk>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_VersionControl_SubversionPropertiesSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* The Subversion properties that should be set.
*
* @var array
*/
protected $properties = array(
'svn:keywords' => 'Author Id Revision',
'svn:eol-style' => 'native',
);
 
 
/**
* 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;
}
 
$path = $phpcsFile->getFileName();
$properties = $this->properties($path);
 
foreach (($properties + $this->properties) as $key => $value) {
if (isset($properties[$key]) === true
&& isset($this->properties[$key]) === false
) {
$error = 'Unexpected Subversion property "'.$key.'" = "'.$properties[$key].'"';
$phpcsFile->addError($error, $stackPtr);
continue;
}
 
if (isset($properties[$key]) === false
&& isset($this->properties[$key]) === true
) {
$error = 'Missing Subversion property "'.$key.'" = "'.$this->properties[$key].'"';
$phpcsFile->addError($error, $stackPtr);
continue;
}
 
if ($properties[$key] !== $this->properties[$key]) {
$error = 'Subversion property "'.$key.'" = "'.$properties[$key].'" does not match "'.$this->properties[$key].'"';
$phpcsFile->addError($error, $stackPtr);
}
}
 
}//end process()
 
 
/**
* Returns the Subversion properties which are actually set on a path.
*
* @param string $path The path to return Subversion properties on.
*
* @return array
* @throws PHP_CodeSniffer_Exception If Subversion properties file could
* not be opened.
*/
protected function properties($path)
{
$properties = array();
 
$paths = array();
$paths[] = dirname($path).'/.svn/props/'.basename($path).'.svn-work';
$paths[] = dirname($path).'/.svn/prop-base/'.basename($path).'.svn-base';
 
foreach ($paths as $path) {
if (true === file_exists($path)) {
if (false === $handle = fopen($path, 'r')) {
$error = 'Error opening file; could not get Subversion properties';
throw new PHP_CodeSniffer_Exception($error);
}
 
while (!feof($handle)) {
 
// Read a key length line. Might be END, though.
$buffer = fgets($handle);
 
// Check for the end of the hash.
if ("END\n" === $buffer) {
break;
}
 
// Now read that much into a buffer.
$key = fread($handle, substr($buffer, 2));
 
// Suck up extra newline after key data.
fgetc($handle);
 
// Read a value length line.
$buffer = fgets($handle);
 
// Now read that much into a buffer.
$value = fread($handle, substr($buffer, 2));
 
// Suck up extra newline after value data.
fgetc($handle);
 
$properties[$key] = $value;
}//end while
 
fclose($handle);
}//end if
}//end foreach
 
return $properties;
 
}//end properties()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/PHP/DisallowShortOpenTagSniff.php
New file
0,0 → 1,91
<?php
/**
* Generic_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.8 2008/12/03 04:42:41 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_PHP_DisallowShortOpenTagSniff 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,
T_OPEN_TAG_WITH_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)
{
// If short open tags are off, then any short open tags will be converted
// to inline_html tags so we can just ignore them.
// If its on, then we want to ban the use of them.
$option = ini_get('short_open_tag');
 
// Ini_get returns a string "0" if short open tags is off.
if ($option === '0') {
return;
}
 
$tokens = $phpcsFile->getTokens();
$openTag = $tokens[$stackPtr];
 
if ($openTag['content'] === '<?') {
$error = 'Short PHP opening tag used. Found "'.$openTag['content'].'" Expected "<?php".';
$phpcsFile->addError($error, $stackPtr);
}
 
if ($openTag['code'] === T_OPEN_TAG_WITH_ECHO) {
$nextVar = $tokens[$phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true)];
$error = 'Short PHP opening tag used with echo. Found "';
$error .= $openTag['content'].' '.$nextVar['content'].' ..." but expected "<?php echo '.$nextVar['content'].' ...".';
$phpcsFile->addError($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/PHP/LowerCaseConstantSniff.php
New file
0,0 → 1,84
<?php
/**
* Generic_Sniffs_PHP_LowerCaseConstantSniff.
*
* 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: LowerCaseConstantSniff.php,v 1.8 2008/02/18 00:01:06 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_PHP_LowerCaseConstantSniff.
*
* Checks that all uses of true, false and null are lowerrcase.
*
* @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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_PHP_LowerCaseConstantSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
'JS',
);
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_TRUE,
T_FALSE,
T_NULL,
);
 
}//end register()
 
 
/**
* Processes this sniff, 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();
 
$keyword = $tokens[$stackPtr]['content'];
if (strtolower($keyword) !== $keyword) {
$error = 'TRUE, FALSE and NULL must be lowercase; expected "'.strtolower($keyword).'" but found "'.$keyword.'"';
$phpcsFile->addError($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/PHP/NoSilencedErrorsSniff.php
New file
0,0 → 1,82
<?php
/**
* Generic_Sniffs_PHP_NoSilencedErrorsSniff
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Andy Brockhurst <abrock@yahoo-inc.com>
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: NoSilencedErrorsSniff.php,v 1.1 2008/12/03 04:42:07 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_PHP_NoSilencedErrorsSniff.
*
* Throws an error or warning when any code prefixed with an asperand is encountered.
*
* <code>
* if (@in_array($array, $needle))
* {
* doSomething();
* }
* </code>
*
* @category PHP
* @package PHP_CodeSniffer
* @author Andy Brockhurst <abrock@yahoo-inc.com>
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_PHP_NoSilencedErrorsSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* If true, an error will be thrown; otherwise a warning.
*
* @var bool
*/
protected $error = false;
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_ASPERAND);
 
}//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 = 'Silencing errors is ';
if ($this->error === true) {
$error .= 'forbidden';
$phpcsFile->addError($error, $stackPtr);
} else {
$error .= 'discouraged';
$phpcsFile->addWarning($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/PHP/UpperCaseConstantSniff.php
New file
0,0 → 1,75
<?php
/**
* Generic_Sniffs_PHP_UpperCaseConstantSniff.
*
* 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: UpperCaseConstantSniff.php,v 1.8 2008/02/18 00:01:06 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_PHP_UpperCaseConstantSniff.
*
* 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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_PHP_UpperCaseConstantSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_TRUE,
T_FALSE,
T_NULL,
);
 
}//end register()
 
 
/**
* Processes this sniff, 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();
 
$keyword = $tokens[$stackPtr]['content'];
if (strtoupper($keyword) !== $keyword) {
$error = 'TRUE, FALSE and NULL must be uppercase; expected "'.strtoupper($keyword).'" but found "'.$keyword.'"';
$phpcsFile->addError($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/PHP/ForbiddenFunctionsSniff.php
New file
0,0 → 1,115
<?php
/**
* Generic_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.7 2008/08/19 06:35:37 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_PHP_ForbiddenFunctionsSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* 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',
);
 
/**
* If true, an error will be thrown; otherwise a warning.
*
* @var bool
*/
protected $error = true;
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_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();
 
$prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
if (in_array($tokens[$prevToken]['code'], array(T_DOUBLE_COLON, T_OBJECT_OPERATOR, T_FUNCTION)) === true) {
// Not a call to a PHP function.
return;
}
 
$function = strtolower($tokens[$stackPtr]['content']);
 
if (in_array($function, array_keys($this->forbiddenFunctions)) === false) {
return;
}
 
$error = "The use of function $function() is ";
if ($this->error === true) {
$error .= 'forbidden';
} else {
$error .= 'discouraged';
}
 
if ($this->forbiddenFunctions[$function] !== null) {
$error .= '; use '.$this->forbiddenFunctions[$function].'() instead';
}
 
if ($this->error === true) {
$phpcsFile->addError($error, $stackPtr);
} else {
$phpcsFile->addWarning($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceBsdAllmanSniff.php
New file
0,0 → 1,122
<?php
/**
* Generic_Sniffs_Methods_OpeningMethodBraceBsdAllmanSniff.
*
* 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: OpeningFunctionBraceBsdAllmanSniff.php,v 1.8 2008/05/05 03:59:12 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff.
*
* Checks that the opening brace of a function is on the line after the
* function declaration.
*
* @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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Registers the tokens that this sniff wants to listen for.
*
* @return void
*/
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 (isset($tokens[$stackPtr]['scope_opener']) === false) {
return;
}
 
$openingBrace = $tokens[$stackPtr]['scope_opener'];
 
// The end of the function occurs at the end of the argument list. Its
// like this because some people like to break long function declarations
// over multiple lines.
$functionLine = $tokens[$tokens[$stackPtr]['parenthesis_closer']]['line'];
$braceLine = $tokens[$openingBrace]['line'];
 
$lineDifference = ($braceLine - $functionLine);
 
if ($lineDifference === 0) {
$error = 'Opening brace should be on a new line';
$phpcsFile->addError($error, $openingBrace);
return;
}
 
if ($lineDifference > 1) {
$ender = 'line';
if (($lineDifference - 1) !== 1) {
$ender .= 's';
}
 
$error = 'Opening brace should be on the line after the declaration; found '.($lineDifference - 1).' blank '.$ender;
$phpcsFile->addError($error, $openingBrace);
return;
}
 
// We need to actually find the first piece of content on this line,
// as if this is a method with tokens before it (public, static etc)
// or an if with an else before it, then we need to start the scope
// checking from there, rather than the current token.
$lineStart = $stackPtr;
while (($lineStart = $phpcsFile->findPrevious(array(T_WHITESPACE), ($lineStart - 1), null, false)) !== false) {
if (strpos($tokens[$lineStart]['content'], $phpcsFile->eolChar) !== false) {
break;
}
}
 
// We found a new line, now go forward and find the first non-whitespace
// token.
$lineStart = $phpcsFile->findNext(array(T_WHITESPACE), $lineStart, null, true);
 
// The opening brace is on the correct line, now it needs to be
// checked to be correctly indented.
$startColumn = $tokens[$lineStart]['column'];
$braceIndent = $tokens[$openingBrace]['column'];
 
if ($braceIndent !== $startColumn) {
$error = 'Opening brace indented incorrectly; expected '.($startColumn - 1).' spaces, found '.($braceIndent - 1);
$phpcsFile->addError($error, $openingBrace);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceKernighanRitchieSniff.php
New file
0,0 → 1,108
<?php
/**
* Generic_Sniffs_Functions_OpeningFunctionBraceKernighanRitchieSniff.
*
* 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: OpeningFunctionBraceKernighanRitchieSniff.php,v 1.5 2008/05/05 03:59:12 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_Functions_OpeningFunctionBraceKernighanRitchieSniff.
*
* Checks that the opening brace of a function is on the same line
* as the function declaration.
*
* @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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Functions_OpeningFunctionBraceKernighanRitchieSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Registers the tokens that this sniff wants to listen for.
*
* @return void
*/
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 (isset($tokens[$stackPtr]['scope_opener']) === false) {
return;
}
 
$openingBrace = $tokens[$stackPtr]['scope_opener'];
 
// The end of the function occurs at the end of the argument list. Its
// like this because some people like to break long function declarations
// over multiple lines.
$functionLine = $tokens[$tokens[$stackPtr]['parenthesis_closer']]['line'];
$braceLine = $tokens[$openingBrace]['line'];
 
$lineDifference = ($braceLine - $functionLine);
 
if ($lineDifference > 0) {
$error = 'Opening brace should be on the same line as the declaration';
$phpcsFile->addError($error, $openingBrace);
return;
}
 
// Checks that the closing parenthesis and the opening brace are
// separated by a whitespace character.
$closerColumn = $tokens[$tokens[$stackPtr]['parenthesis_closer']]['column'];
$braceColumn = $tokens[$openingBrace]['column'];
 
$columnDifference = ($braceColumn - $closerColumn);
 
if ($columnDifference !== 2) {
$error = 'Expected 1 space between the closing parenthesis and the opening brace; found '.($columnDifference - 1).'.';
$phpcsFile->addError($error, $openingBrace);
return;
}
 
// Check that a tab was not used instead of a space.
$spaceTokenPtr = ($tokens[$stackPtr]['parenthesis_closer'] + 1);
$spaceContent = $tokens[$spaceTokenPtr]['content'];
if ($spaceContent !== ' ') {
$error = 'Expected a single space character between closing parenthesis and opening brace; found "'.$spaceContent.'".';
$phpcsFile->addError($error, $openingBrace);
return;
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Strings/UnnecessaryStringConcatSniff.php
New file
0,0 → 1,112
<?php
/**
* Generic_Sniffs_Strings_UnnecessaryStringConcatSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: UnnecessaryStringConcatSniff.php,v 1.1 2008/12/05 04:39:00 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_Strings_UnnecessaryStringConcatSniff.
*
* Checks that two strings are not concatenated together; suggests
* using one string instead.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Strings_UnnecessaryStringConcatSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
'JS',
);
 
/**
* If true, an error will be thrown; otherwise a warning.
*
* @var bool
*/
protected $error = true;
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_STRING_CONCAT,
T_PLUS,
);
 
}//end register()
 
 
/**
* Processes this sniff, 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)
{
// Work out which type of file this is for.
$tokens = $phpcsFile->getTokens();
if ($tokens[$stackPtr]['code'] === T_STRING_CONCAT) {
if ($phpcsFile->tokenizerType === 'JS') {
return;
}
} else {
if ($phpcsFile->tokenizerType === 'PHP') {
return;
}
}
 
$prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
$next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
if ($prev === false || $next === false) {
return;
}
 
$stringTokens = PHP_CodeSniffer_Tokens::$stringTokens;
if (in_array($tokens[$prev]['code'], $stringTokens) === true
&& in_array($tokens[$next]['code'], $stringTokens) === true
) {
$error = 'String concat is not required here; use a single string instead';
if ($this->error === true) {
$phpcsFile->addError($error, $stackPtr);
} else {
$phpcsFile->addWarning($error, $stackPtr);
}
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Formatting/NoSpaceAfterCastSniff.php
New file
0,0 → 1,70
<?php
/**
* Generic_Sniffs_Formatting_NoSpaceAfterCastSniff.
*
* 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: NoSpaceAfterCastSniff.php,v 1.2 2007/07/23 01:47:52 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_Formatting_NoSpaceAfterCastSniff.
*
* Ensures there is no space after cast tokens.
*
* @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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Formatting_NoSpaceAfterCastSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return PHP_CodeSniffer_Tokens::$castTokens;
 
}//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 ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE) {
$error = 'A cast statement must not be followed by a space';
$phpcsFile->addError($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Formatting/SpaceAfterCastSniff.php
New file
0,0 → 1,76
<?php
/**
* Generic_Sniffs_Formatting_SpaceAfterCastSniff.
*
* 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: SpaceAfterCastSniff.php,v 1.2 2007/07/23 01:47:52 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_Formatting_SpaceAfterCastSniff.
*
* Ensures there is a single space after cast tokens.
*
* @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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Formatting_SpaceAfterCastSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return PHP_CodeSniffer_Tokens::$castTokens;
 
}//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 ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
$error = 'A cast statement must be followed by a single space';
$phpcsFile->addError($error, $stackPtr);
return;
}
 
if ($tokens[($stackPtr + 1)]['content'] !== ' ') {
$error = 'A cast statement must be followed by a single space';
$phpcsFile->addError($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Formatting/MultipleStatementAlignmentSniff.php
New file
0,0 → 1,287
<?php
/**
* Generic_Sniffs_Formatting_MultipleStatementAlignmentSniff.
*
* 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: MultipleStatementAlignmentSniff.php,v 1.23 2008/12/02 02:38:34 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_Formatting_MultipleStatementAlignmentSniff.
*
* Checks alignment of assignments. If there are multiple adjacent assignments,
* it will check that the equals signs of each assignment are aligned. It will
* display a warning to advise that the signs should be aligned.
*
* @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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Formatting_MultipleStatementAlignmentSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
'JS',
);
 
/**
* If true, an error will be thrown; otherwise a warning.
*
* @var bool
*/
protected $error = false;
 
/**
* The maximum amount of padding before the alignment is ignored.
*
* If the amount of padding required to align this assignment with the
* surrounding assignments exceeds this number, the assignment will be
* ignored and no errors or warnings will be thrown.
*
* @var int
*/
protected $maxPadding = 1000;
 
/**
* If true, multi-line assignments are not checked.
*
* @var int
*/
protected $ignoreMultiLine = false;
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return PHP_CodeSniffer_Tokens::$assignmentTokens;
 
}//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();
 
// Ignore assignments used in a condition, like an IF or FOR.
if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
foreach ($tokens[$stackPtr]['nested_parenthesis'] as $start => $end) {
if (isset($tokens[$start]['parenthesis_owner']) === true) {
return;
}
}
}
 
/*
By this stage, it is known that there is an assignment on this line.
We only want to process the block once we reach the last assignment,
so we need to determine if there are more to follow.
*/
 
// The assignment may span over multiple lines, so look for the
// end of the assignment so we can check assignment blocks correctly.
$lineEnd = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr + 1));
 
$nextAssign = $phpcsFile->findNext(
PHP_CodeSniffer_Tokens::$assignmentTokens,
($lineEnd + 1)
);
 
if ($nextAssign !== false) {
$isAssign = true;
if ($tokens[$nextAssign]['line'] === ($tokens[$lineEnd]['line'] + 1)) {
// Assignment may be in the same block as this one. Just make sure
// it is not used in a condition, like an IF or FOR.
if (isset($tokens[$nextAssign]['nested_parenthesis']) === true) {
foreach ($tokens[$nextAssign]['nested_parenthesis'] as $start => $end) {
if (isset($tokens[$start]['parenthesis_owner']) === true) {
// Not an assignment.
$isAssign = false;
break;
}
}
}
 
if ($isAssign === true) {
return;
}
}
}
 
// Getting here means that this is the last in a block of statements.
$assignments = array();
$assignments[] = $stackPtr;
$prevAssignment = $stackPtr;
$lastLine = $tokens[$stackPtr]['line'];
 
while (($prevAssignment = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$assignmentTokens, ($prevAssignment - 1))) !== false) {
 
// The assignment's end token must be on the line directly
// above the current one to be in the same assignment block.
$lineEnd = $phpcsFile->findNext(T_SEMICOLON, ($prevAssignment + 1));
 
// And the end token must actually belong to this assignment.
$nextOpener = $phpcsFile->findNext(
PHP_CodeSniffer_Tokens::$scopeOpeners,
($prevAssignment + 1)
);
 
if ($nextOpener !== false && $nextOpener < $lineEnd) {
break;
}
 
if ($tokens[$lineEnd]['line'] !== ($lastLine - 1)) {
break;
}
 
// Make sure it is not assigned inside a condition (eg. IF, FOR).
if (isset($tokens[$prevAssignment]['nested_parenthesis']) === true) {
foreach ($tokens[$prevAssignment]['nested_parenthesis'] as $start => $end) {
if (isset($tokens[$start]['parenthesis_owner']) === true) {
break(2);
}
}
}
 
$assignments[] = $prevAssignment;
$lastLine = $tokens[$prevAssignment]['line'];
}//end while
 
$assignmentData = array();
$maxAssignmentLength = 0;
$maxVariableLength = 0;
 
foreach ($assignments as $assignment) {
$prev = $phpcsFile->findPrevious(
PHP_CodeSniffer_Tokens::$emptyTokens,
($assignment - 1),
null,
true
);
 
$endColumn = $tokens[($prev + 1)]['column'];
 
if ($maxVariableLength < $endColumn) {
$maxVariableLength = $endColumn;
}
 
if ($maxAssignmentLength < strlen($tokens[$assignment]['content'])) {
$maxAssignmentLength = strlen($tokens[$assignment]['content']);
}
 
$assignmentData[$assignment]
= array(
'variable_length' => $endColumn,
'assignment_length' => strlen($tokens[$assignment]['content']),
);
}//end foreach
 
foreach ($assignmentData as $assignment => $data) {
if ($data['assignment_length'] === $maxAssignmentLength) {
if ($data['variable_length'] === $maxVariableLength) {
// The assignment is the longest possible, so the column that
// everything has to align to is based on it.
$column = ($maxVariableLength + 1);
break;
} else {
// The assignment token is the longest out of all of the
// assignments, but the variable name is not, so the column
// the start at can go back more to cover the space
// between the variable name and the assigment operator.
$column = ($maxVariableLength - ($maxAssignmentLength - 1) + 1);
}
}
}
 
// Determine the actual position that each equals sign should be in.
foreach ($assignments as $assignment) {
// Actual column takes into account the length of the assignment operator.
$actualColumn = ($column + $maxAssignmentLength - strlen($tokens[$assignment]['content']));
if ($tokens[$assignment]['column'] !== $actualColumn) {
$prev = $phpcsFile->findPrevious(
PHP_CodeSniffer_Tokens::$emptyTokens,
($assignment - 1),
null,
true
);
 
$expected = ($actualColumn - $tokens[($prev + 1)]['column']);
 
if ($tokens[$assignment]['line'] !== $tokens[$prev]['line']) {
// Instead of working out how many spaces there are
// across new lines, the error message becomes more
// generic below.
$found = null;
} else {
$found = ($tokens[$assignment]['column'] - $tokens[($prev + 1)]['column']);
}
 
// If the expected number of spaces for alignment exceeds the
// maxPadding rule, we can ignore this assignment.
if ($expected > $this->maxPadding) {
continue;
}
 
// Skip multi-line assignments if required.
if ($found === null && $this->ignoreMultiLine === true) {
continue;
}
 
$expected .= ($expected === 1) ? ' space' : ' spaces';
if ($found === null) {
$found = 'a new line';
} else {
$found .= ($found === 1) ? ' space' : ' spaces';
}
 
if (count($assignments) === 1) {
$error = "Equals sign not aligned correctly; expected $expected but found $found";
} else {
$error = "Equals sign not aligned with surrounding assignments; expected $expected but found $found";
}
 
if ($this->error === true) {
$phpcsFile->addError($error, $assignment);
} else {
$phpcsFile->addWarning($error, $assignment);
}
}//end if
}//end foreach
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Formatting/DisallowMultipleStatementsSniff.php
New file
0,0 → 1,84
<?php
/**
* Generic_Sniffs_Formatting_DisallowMultipleStatementsSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: DisallowMultipleStatementsSniff.php,v 1.1 2008/06/24 06:37:54 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_Formatting_DisallowMultipleStatementsSniff.
*
* Ensures each statement is on a line by itself.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Formatting_DisallowMultipleStatementsSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_SEMICOLON);
 
}//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();
 
$prev = $phpcsFile->findPrevious(T_SEMICOLON, ($stackPtr - 1));
if ($prev === false) {
return;
}
 
// Ignore multiple statements in a FOR condition.
if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
foreach ($tokens[$stackPtr]['nested_parenthesis'] as $bracket) {
$owner = $tokens[$bracket]['parenthesis_owner'];
if ($tokens[$owner]['code'] === T_FOR) {
return;
}
}
}
 
if ($tokens[$prev]['line'] === $tokens[$stackPtr]['line']) {
$error = 'Each PHP statement must be on a line by itself';
$phpcsFile->addError($error, $stackPtr);
return;
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php
New file
0,0 → 1,311
<?php
/**
* Generic_Sniffs_Whitespace_ScopeIndentSniff.
*
* 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: ScopeIndentSniff.php,v 1.12 2008/12/02 02:38:34 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_Whitespace_ScopeIndentSniff.
*
* Checks that control structures are structured correctly, and their content
* is indented correctly. This sniff will throw errors if tabs are used
* for indentation rather than spaces.
*
* @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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_WhiteSpace_ScopeIndentSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* The number of spaces code should be indented.
*
* @var int
*/
protected $indent = 4;
 
/**
* Does the indent need to be exactly right.
*
* If TRUE, indent needs to be exactly $ident spaces. If FALSE,
* indent needs to be at least $ident spaces (but can be more).
*
* @var bool
*/
protected $exact = false;
 
/**
* Any scope openers that should not cause an indent.
*
* @var array(int)
*/
protected $nonIndentingScopes = array();
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return PHP_CodeSniffer_Tokens::$scopeOpeners;
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document.
* @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 this is an inline condition (ie. there is no scope opener), then
// return, as this is not a new scope.
if (isset($tokens[$stackPtr]['scope_opener']) === false) {
return;
}
 
if ($tokens[$stackPtr]['code'] === T_ELSE) {
$next = $phpcsFile->findNext(
PHP_CodeSniffer_Tokens::$emptyTokens,
($stackPtr + 1),
null,
true
);
 
// We will handle the T_IF token in another call to process.
if ($tokens[$next]['code'] === T_IF) {
return;
}
}
 
// Find the first token on this line.
$firstToken = $stackPtr;
for ($i = $stackPtr; $i >= 0; $i--) {
// Record the first code token on the line.
if (in_array($tokens[$i]['code'], PHP_CodeSniffer_Tokens::$emptyTokens) === false) {
$firstToken = $i;
}
 
// It's the start of the line, so we've found our first php token.
if ($tokens[$i]['column'] === 1) {
break;
}
}
 
// Based on the conditions that surround this token, determine the
// indent that we expect this current content to be.
$expectedIndent = $this->calculateExpectedIndent($tokens, $firstToken);
 
if ($tokens[$firstToken]['column'] !== $expectedIndent) {
$error = 'Line indented incorrectly; expected ';
$error .= ($expectedIndent - 1).' spaces, found ';
$error .= ($tokens[$firstToken]['column'] - 1);
$phpcsFile->addError($error, $stackPtr);
}
 
$scopeOpener = $tokens[$stackPtr]['scope_opener'];
$scopeCloser = $tokens[$stackPtr]['scope_closer'];
 
// Some scopes are expected not to have indents.
if (in_array($tokens[$firstToken]['code'], $this->nonIndentingScopes) === false) {
$indent = ($expectedIndent + $this->indent);
} else {
$indent = $expectedIndent;
}
 
$newline = false;
$commentOpen = false;
$inHereDoc = false;
 
// Only loop over the content beween the opening and closing brace, not
// the braces themselves.
for ($i = ($scopeOpener + 1); $i < $scopeCloser; $i++) {
 
// If this token is another scope, skip it as it will be handled by
// another call to this sniff.
if (in_array($tokens[$i]['code'], PHP_CodeSniffer_Tokens::$scopeOpeners) === true) {
if (isset($tokens[$i]['scope_opener']) === true) {
$i = $tokens[$i]['scope_closer'];
} else {
// If this token does not have a scope_opener indice, then
// it's probably an inline scope, so let's skip to the next
// semicolon. Inline scopes include inline if's, abstract
// methods etc.
$nextToken = $phpcsFile->findNext(T_SEMICOLON, $i, $scopeCloser);
if ($nextToken !== false) {
$i = $nextToken;
}
}
 
continue;
}
 
// If this is a HEREDOC then we need to ignore it as the
// whitespace before the contents within the HEREDOC are
// considered part of the content.
if ($tokens[$i]['code'] === T_START_HEREDOC) {
$inHereDoc = true;
continue;
} else if ($inHereDoc === true) {
if ($tokens[$i]['code'] === T_END_HEREDOC) {
$inHereDoc = false;
}
 
continue;
}
 
if ($tokens[$i]['column'] === 1) {
// We started a newline.
$newline = true;
}
 
if ($newline === true && $tokens[$i]['code'] !== T_WHITESPACE) {
// If we started a newline and we find a token that is not
// whitespace, then this must be the first token on the line that
// must be indented.
$newline = false;
$firstToken = $i;
 
$column = $tokens[$firstToken]['column'];
 
// Special case for non-PHP code.
if ($tokens[$firstToken]['code'] === T_INLINE_HTML) {
$trimmedContentLength
= strlen(ltrim($tokens[$firstToken]['content']));
if ($trimmedContentLength === 0) {
continue;
}
 
$contentLength = strlen($tokens[$firstToken]['content']);
$column = ($contentLength - $trimmedContentLength + 1);
}
 
// Check to see if this constant string spans multiple lines.
// If so, then make sure that the strings on lines other than the
// first line are indented appropriately, based on their whitespace.
if (in_array($tokens[$firstToken]['code'], PHP_CodeSniffer_Tokens::$stringTokens) === true) {
if (in_array($tokens[($firstToken - 1)]['code'], PHP_CodeSniffer_Tokens::$stringTokens) === true) {
// If we find a string that directly follows another string
// then its just a string that spans multiple lines, so we
// don't need to check for indenting.
continue;
}
}
 
// This is a special condition for T_DOC_COMMENT and C-style
// comments, which contain whitespace between each line.
$comments = array(
T_COMMENT,
T_DOC_COMMENT
);
 
if (in_array($tokens[$firstToken]['code'], $comments) === true) {
$content = trim($tokens[$firstToken]['content']);
if (preg_match('|^/\*|', $content) !== 0) {
// Check to see if the end of the comment is on the same line
// as the start of the comment. If it is, then we don't
// have to worry about opening a comment.
if (preg_match('|\*/$|', $content) === 0) {
// We don't have to calculate the column for the
// start of the comment as there is a whitespace
// token before it.
$commentOpen = true;
}
} else if ($commentOpen === true) {
if ($content === '') {
// We are in a comment, but this line has nothing on it
// so let's skip it.
continue;
}
 
$contentLength = strlen($tokens[$firstToken]['content']);
$trimmedContentLength
= strlen(ltrim($tokens[$firstToken]['content']));
 
$column = ($contentLength - $trimmedContentLength + 1);
if (preg_match('|\*/$|', $content) !== 0) {
$commentOpen = false;
}
}//end if
}//end if
 
// The token at the start of the line, needs to have its' column
// greater than the relative indent we set above. If it is less,
// an error should be shown.
if ($column !== $indent) {
if ($this->exact === true || $column < $indent) {
$error = 'Line indented incorrectly; expected ';
if ($this->exact === false) {
$error .= 'at least ';
}
 
$error .= ($indent - 1).' spaces, found ';
$error .= ($column - 1);
$phpcsFile->addError($error, $firstToken);
}
}
}//end if
}//end for
 
}//end process()
 
 
/**
* Calculates the expected indent of a token.
*
* @param array $tokens The stack of tokens for this file.
* @param int $stackPtr The position of the token to get indent for.
*
* @return int
*/
protected function calculateExpectedIndent(array $tokens, $stackPtr)
{
$conditionStack = array();
 
// Empty conditions array (top level structure).
if (empty($tokens[$stackPtr]['conditions']) === true) {
return 1;
}
 
$tokenConditions = $tokens[$stackPtr]['conditions'];
foreach ($tokenConditions as $id => $condition) {
// If it's an indenting scope ie. it's not in our array of
// scopes that don't indent, add it to our condition stack.
if (in_array($condition, $this->nonIndentingScopes) === false) {
$conditionStack[$id] = $condition;
}
}
 
return ((count($conditionStack) * $this->indent) + 1);
 
}//end calculateExpectedIndent()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/WhiteSpace/DisallowTabIndentSniff.php
New file
0,0 → 1,87
<?php
/**
* Generic_Sniffs_WhiteSpace_DisallowTabIndentSniff.
*
* 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: DisallowTabIndentSniff.php,v 1.3 2008/10/28 04:43:57 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_WhiteSpace_DisallowTabIndentSniff.
*
* Throws errors if tabs are used for indentation.
*
* @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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_WhiteSpace_DisallowTabIndentSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
'JS',
'CSS',
);
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_WHITESPACE);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document.
* @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 whitespace used for indentation.
$line = $tokens[$stackPtr]['line'];
if ($stackPtr > 0 && $tokens[($stackPtr - 1)]['line'] === $line) {
return;
}
 
if (strpos($tokens[$stackPtr]['content'], "\t") !== false) {
$error = 'Spaces must be used to indent lines; tabs are not allowed';
$phpcsFile->addError($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Classes/DuplicateClassNameSniff.php
New file
0,0 → 1,74
<?php
/**
* Reports errors if the same class or interface name is used in multiple files.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: DuplicateClassNameSniff.php,v 1.1 2008/07/25 04:24:10 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Reports errors if the same class or interface name is used in multiple files.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Classes_DuplicateClassNameSniff implements PHP_CodeSniffer_MultiFileSniff
{
 
 
/**
* Called once per script run to allow for processing of this sniff.
*
* @param array(PHP_CodeSniffer_File) $files The PHP_CodeSniffer files processed
* during the script run.
*
* @return void
*/
public function process(array $files)
{
$foundClasses = array();
 
foreach ($files as $phpcsFile) {
$tokens = $phpcsFile->getTokens();
 
$stackPtr = $phpcsFile->findNext(array(T_CLASS, T_INTERFACE), 0);
while ($stackPtr !== false) {
$nameToken = $phpcsFile->findNext(T_STRING, $stackPtr);
$name = $tokens[$nameToken]['content'];
$compareName = strtolower($name);
if (isset($foundClasses[$compareName]) === true) {
$type = strtolower($tokens[$stackPtr]['content']);
$file = $foundClasses[$compareName]['file'];
$line = $foundClasses[$compareName]['line'];
$error = "Duplicate $type name \"$name\" found; first defined in $file on line $line";
$phpcsFile->addWarning($error, $stackPtr);
} else {
$foundClasses[$compareName] = array(
'file' => $phpcsFile->getFilename(),
'line' => $tokens[$stackPtr]['line'],
);
}
 
$stackPtr = $phpcsFile->findNext(array(T_CLASS, T_INTERFACE), ($stackPtr + 1));
}//end while
 
}//end foreach
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UselessOverridingMethodSniff.php
New file
0,0 → 1,181
<?php
/**
* This file is part of the CodeAnalysis addon for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: UselessOverridingMethodSniff.php,v 1.2 2008/10/01 06:08:49 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Detects unnecessary overriden methods that simply call their parent.
*
* This rule is based on the PMD rule catalog. The Useless Overriding Method
* sniff detects the use of methods that only call their parent classes's method
* with the same name and arguments. These methods are not required.
*
* <code>
* class FooBar {
* public function __construct($a, $b) {
* parent::__construct($a, $b);
* }
* }
* </code>
*
* @category PHP
* @package PHP_CodeSniffer
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_CodeAnalysis_UselessOverridingMethodSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Registers the tokens that this sniff wants to listen for.
*
* @return array(integer)
*/
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();
$token = $tokens[$stackPtr];
 
// Skip function without body.
if (isset($token['scope_opener']) === false) {
return;
}
 
// Get function name.
$methodName = $phpcsFile->getDeclarationName($stackPtr);
 
// Get all parameters from method signature.
$signature = array();
foreach ($phpcsFile->getMethodParameters($stackPtr) as $param) {
$signature[] = $param['name'];
}
 
$next = ++$token['scope_opener'];
$end = --$token['scope_closer'];
 
for (; $next <= $end; ++$next) {
$code = $tokens[$next]['code'];
 
if (in_array($code, PHP_CodeSniffer_Tokens::$emptyTokens) === true) {
continue;
} else if ($code === T_RETURN) {
continue;
}
 
break;
}
 
// Any token except 'parent' indicates correct code.
if ($tokens[$next]['code'] !== T_PARENT) {
return;
}
 
// Find next non empty token index, should be double colon.
$next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($next + 1), null, true);
 
// Skip for invalid code.
if ($next === false || $tokens[$next]['code'] !== T_DOUBLE_COLON) {
return;
}
 
// Find next non empty token index, should be the function name.
$next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($next + 1), null, true);
 
// Skip for invalid code or other method.
if ($next === false || $tokens[$next]['content'] !== $methodName) {
return;
}
 
// Find next non empty token index, should be the open parenthesis.
$next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($next + 1), null, true);
 
// Skip for invalid code.
if ($next === false || $tokens[$next]['code'] !== T_OPEN_PARENTHESIS) {
return;
}
 
$validParameterTypes = array(
T_VARIABLE,
T_LNUMBER,
T_CONSTANT_ENCAPSED_STRING,
);
 
$parameters = array('');
$parenthesisCount = 1;
$count = count($tokens);
for (++$next; $next < $count; ++$next) {
$code = $tokens[$next]['code'];
 
if ($code === T_OPEN_PARENTHESIS) {
++$parenthesisCount;
} else if ($code === T_CLOSE_PARENTHESIS) {
--$parenthesisCount;
} else if ($parenthesisCount === 1 && $code === T_COMMA) {
$parameters[] = '';
} else if (in_array($code, PHP_CodeSniffer_Tokens::$emptyTokens) === false) {
$parameters[(count($parameters) - 1)] .= $tokens[$next]['content'];
}
 
if ($parenthesisCount === 0) {
break;
}
}//end for
 
$next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($next + 1), null, true);
if ($next === false || $tokens[$next]['code'] !== T_SEMICOLON) {
return;
}
 
// Check rest of the scope.
for (++$next; $next <= $end; ++$next) {
$code = $tokens[$next]['code'];
// Skip for any other content.
if (in_array($code, PHP_CodeSniffer_Tokens::$emptyTokens) === false) {
return;
}
}
 
$parameters = array_map('trim', $parameters);
$parameters = array_filter($parameters);
 
if (count($parameters) === count($signature) && $parameters === $signature) {
$phpcsFile->addWarning('Useless method overriding detected', $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/ForLoopWithTestFunctionCallSniff.php
New file
0,0 → 1,114
<?php
/**
* This file is part of the CodeAnalysis addon for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: ForLoopWithTestFunctionCallSniff.php,v 1.1 2008/02/06 02:38:36 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Detects for-loops that use a function call in the test expression.
*
* This rule is based on the PMD rule catalog. Detects for-loops that use a
* function call in the test expression.
*
* <code>
* class Foo
* {
* public function bar($x)
* {
* $a = array(1, 2, 3, 4);
* for ($i = 0; $i < count($a); $i++) {
* $a[$i] *= $i;
* }
* }
* }
* </code>
*
* @category PHP
* @package PHP_CodeSniffer
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_CodeAnalysis_ForLoopWithTestFunctionCallSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Registers the tokens that this sniff wants to listen for.
*
* @return array(integer)
*/
public function register()
{
return array(T_FOR);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$token = $tokens[$stackPtr];
 
// Skip invalid statement.
if (isset($token['parenthesis_opener']) === false) {
return;
}
 
$next = ++$token['parenthesis_opener'];
$end = --$token['parenthesis_closer'];
 
$position = 0;
 
for (; $next <= $end; ++$next) {
$code = $tokens[$next]['code'];
if ($code === T_SEMICOLON) {
++$position;
}
 
if ($position < 1) {
continue;
} else if ($position > 1) {
break;
} else if ($code !== T_VARIABLE && $code !== T_STRING) {
continue;
}
 
// Find next non empty token, if it is a open curly brace we have a
// function call.
$index = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($next + 1), null, true);
 
if ($tokens[$index]['code'] === T_OPEN_PARENTHESIS) {
$error = 'Avoid function calls in a FOR loop test part';
$phpcsFile->addWarning($error, $stackPtr);
break;
}
}//end for
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/JumbledIncrementerSniff.php
New file
0,0 → 1,148
<?php
/**
* This file is part of the CodeAnalysis addon for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: JumbledIncrementerSniff.php,v 1.1 2008/02/06 02:38:36 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Detects incrementer jumbling in for loops.
*
* This rule is based on the PMD rule catalog. The jumbling incrementer sniff
* detects the usage of one and the same incrementer into an outer and an inner
* loop. Even it is intended this is confusing code.
*
* <code>
* class Foo
* {
* public function bar($x)
* {
* for ($i = 0; $i < 10; $i++)
* {
* for ($k = 0; $k < 20; $i++)
* {
* echo 'Hello';
* }
* }
* }
* }
* </code>
*
* @category PHP
* @package PHP_CodeSniffer
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_CodeAnalysis_JumbledIncrementerSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Registers the tokens that this sniff wants to listen for.
*
* @return array(integer)
*/
public function register()
{
return array(T_FOR);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$token = $tokens[$stackPtr];
 
// Skip for-loop without body.
if (isset($token['scope_opener']) === false) {
return;
}
 
// Find incrementors for outer loop.
$outer = $this->findIncrementers($tokens, $token);
 
// Skip if empty.
if (count($outer) === 0) {
return;
}
 
// Find nested for loops.
$start = ++$token['scope_opener'];
$end = --$token['scope_closer'];
 
for (; $start <= $end; ++$start) {
if ($tokens[$start]['code'] !== T_FOR) {
continue;
}
 
$inner = $this->findIncrementers($tokens, $tokens[$start]);
$diff = array_intersect($outer, $inner);
 
if (count($diff) !== 0) {
$error = sprintf('Loop incrementor (%s) jumbling with inner loop', join(', ', $diff));
$phpcsFile->addWarning($error, $stackPtr);
}
}
 
}//end process()
 
 
/**
* Get all used variables in the incrementer part of a for statement.
*
* @param array(integer=>array) $tokens Array with all code sniffer tokens.
* @param array(string=>mixed) $token Current for loop token
*
* @return array(string) List of all found incrementer variables.
*/
protected function findIncrementers(array $tokens, array $token)
{
// Skip invalid statement.
if (isset($token['parenthesis_opener']) === false) {
return array();
}
 
$start = ++$token['parenthesis_opener'];
$end = --$token['parenthesis_closer'];
 
$incrementers = array();
$semicolons = 0;
for ($next = $start; $next <= $end; ++$next) {
$code = $tokens[$next]['code'];
if ($code === T_SEMICOLON) {
++$semicolons;
} else if ($semicolons === 2 && $code === T_VARIABLE) {
$incrementers[] = $tokens[$next]['content'];
}
}
 
return $incrementers;
 
}//end findIncrementers()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/EmptyStatementSniff.php
New file
0,0 → 1,129
<?php
/**
* This file is part of the CodeAnalysis addon for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: EmptyStatementSniff.php,v 1.1 2008/02/06 02:38:36 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* This sniff class detected empty statement.
*
* This sniff implements the common algorithm for empty statement body detection.
* A body is considered as empty if it is completely empty or it only contains
* whitespace characters and|or comments.
*
* <code>
* stmt {
* // foo
* }
* stmt (conditions) {
* // foo
* }
* </code>
*
* Statements covered by this sniff are <b>catch</b>, <b>do</b>, <b>else</b>,
* <b>elsif</b>, <b>for</b>, <b>foreach<b>, <b>if</b>, <b>switch</b>, <b>try</b>
* and <b>while</b>.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_CodeAnalysis_EmptyStatementSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* List of block tokens that this sniff covers.
*
* The key of this hash identifies the required token while the boolean
* value says mark an error or mark a warning.
*
* @type array<boolean>
* @var array(integer=>boolean) $_tokens
*/
private $_tokens = array(
T_CATCH => true,
T_DO => false,
T_ELSE => false,
T_ELSEIF => false,
T_FOR => false,
T_FOREACH => false,
T_IF => false,
T_SWITCH => false,
T_TRY => false,
T_WHILE => false,
);
 
 
/**
* Registers the tokens that this sniff wants to listen for.
*
* @return array(integer)
*/
public function register()
{
return array_keys($this->_tokens);
 
}//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();
$token = $tokens[$stackPtr];
 
// Skip for-statements without body.
if (isset($token['scope_opener']) === false) {
return;
}
 
$next = ++$token['scope_opener'];
$end = --$token['scope_closer'];
 
$emptyBody = true;
for (; $next <= $end; ++$next) {
if (in_array($tokens[$next]['code'], PHP_CodeSniffer_Tokens::$emptyTokens) === false) {
$emptyBody = false;
break;
}
}
 
if ($emptyBody === true) {
// Get token identifier.
$name = $phpcsFile->getTokensAsString($stackPtr, 1);
$error = sprintf('Empty %s statement detected', strtoupper($name));
if ($this->_tokens[$token['code']] === true) {
$phpcsFile->addError($error, $stackPtr);
} else {
$phpcsFile->addWarning($error, $stackPtr);
}
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UnnecessaryFinalModifierSniff.php
New file
0,0 → 1,99
<?php
/**
* This file is part of the CodeAnalysis addon for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: UnnecessaryFinalModifierSniff.php,v 1.1 2008/02/06 02:38:36 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Detects unnecessary final modifiers inside of final classes.
*
* This rule is based on the PMD rule catalog. The Unnecessary Final Modifier
* sniff detects the use of the final modifier inside of a final class which
* is unnecessary.
*
* <code>
* final class Foo
* {
* public final function bar()
* {
* }
* }
* </code>
*
* @category PHP
* @package PHP_CodeSniffer
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_CodeAnalysis_UnnecessaryFinalModifierSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Registers the tokens that this sniff wants to listen for.
*
* @return array(integer)
*/
public function register()
{
return array(T_CLASS);
 
}//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();
$token = $tokens[$stackPtr];
 
// Skip for-statements without body.
if (isset($token['scope_opener']) === false) {
return;
}
 
// Fetch previous token.
$prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
 
// Skip for non final class.
if ($prev === false || $tokens[$prev]['code'] !== T_FINAL) {
return;
}
 
$next = ++$token['scope_opener'];
$end = --$token['scope_closer'];
 
for (; $next <= $end; ++$next) {
if ($tokens[$next]['code'] === T_FINAL) {
$error = 'Unnecessary FINAL modifier in FINAL class';
$phpcsFile->addWarning($error, $next);
}
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/ForLoopShouldBeWhileLoopSniff.php
New file
0,0 → 1,101
<?php
/**
* This file is part of the CodeAnalysis addon for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: ForLoopShouldBeWhileLoopSniff.php,v 1.1 2008/02/06 02:38:36 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Detects for-loops that can be simplified to a while-loop.
*
* This rule is based on the PMD rule catalog. Detects for-loops that can be
* simplified as a while-loop.
*
* <code>
* class Foo
* {
* public function bar($x)
* {
* for (;true;) true; // No Init or Update part, may as well be: while (true)
* }
* }
* </code>
*
* @category PHP
* @package PHP_CodeSniffer
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_CodeAnalysis_ForLoopShouldBeWhileLoopSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Registers the tokens that this sniff wants to listen for.
*
* @return array(integer)
*/
public function register()
{
return array(T_FOR);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$token = $tokens[$stackPtr];
 
// Skip invalid statement.
if (isset($token['parenthesis_opener']) === false) {
return;
}
 
$next = ++$token['parenthesis_opener'];
$end = --$token['parenthesis_closer'];
 
$parts = array(0, 0, 0);
$index = 0;
 
for (; $next <= $end; ++$next) {
$code = $tokens[$next]['code'];
if ($code === T_SEMICOLON) {
++$index;
} else if (in_array($code, PHP_CodeSniffer_Tokens::$emptyTokens) === false) {
++$parts[$index];
}
}
 
if ($parts[0] === 0 && $parts[2] === 0 && $parts[1] > 0) {
$error = 'This FOR loop can be simplified to a WHILE loop';
$phpcsFile->addWarning($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UnconditionalIfStatementSniff.php
New file
0,0 → 1,107
<?php
/**
* This file is part of the CodeAnalysis addon for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: UnconditionalIfStatementSniff.php,v 1.1 2008/02/06 02:38:36 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Detects unconditional if- and elseif-statements.
*
* This rule is based on the PMD rule catalog. The Unconditional If Statment
* sniff detects statement conditions that are only set to one of the constant
* values <b>true</b> or <b>false</b>
*
* <code>
* class Foo
* {
* public function close()
* {
* if (true)
* {
* // ...
* }
* }
* }
* </code>
*
* @category PHP
* @package PHP_CodeSniffer
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_CodeAnalysis_UnconditionalIfStatementSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Registers the tokens that this sniff wants to listen for.
*
* @return array(integer)
*/
public function register()
{
return array(
T_IF,
T_ELSEIF,
);
 
}//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();
$token = $tokens[$stackPtr];
 
// Skip for-loop without body.
if (isset($token['parenthesis_opener']) === false) {
return;
}
 
$next = ++$token['parenthesis_opener'];
$end = --$token['parenthesis_closer'];
 
$goodCondition = false;
for (; $next <= $end; ++$next) {
$code = $tokens[$next]['code'];
 
if (in_array($code, PHP_CodeSniffer_Tokens::$emptyTokens) === true) {
continue;
} else if ($code !== T_TRUE && $code !== T_FALSE) {
$goodCondition = true;
}
}
 
if ($goodCondition === false) {
$error = 'Avoid IF statements that are always true or false';
$phpcsFile->addWarning($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UnusedFunctionParameterSniff.php
New file
0,0 → 1,141
<?php
/**
* This file is part of the CodeAnalysis addon for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: UnusedFunctionParameterSniff.php,v 1.1 2008/02/06 02:38:36 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Checks the for unused function parameters.
*
* This sniff checks that all function parameters are used in the function body.
* One exception is made for empty function bodies or function bodies that only
* contain comments. This could be usefull for the classes that implement an
* interface that defines multiple methods but the implementation only needs some
* of them.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_CodeAnalysis_UnusedFunctionParameterSniff 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();
$token = $tokens[$stackPtr];
 
// Skip broken function declarations.
if (isset($token['scope_opener']) === false || isset($token['parenthesis_opener']) === false) {
return;
}
 
$params = array();
foreach ($phpcsFile->getMethodParameters($stackPtr) as $param) {
$params[$param['name']] = $stackPtr;
}
 
$next = ++$token['scope_opener'];
$end = --$token['scope_closer'];
 
$emptyBody = true;
 
for (; $next <= $end; ++$next) {
$token = $tokens[$next];
$code = $token['code'];
 
// Ingorable tokens.
if (in_array($code, PHP_CodeSniffer_Tokens::$emptyTokens) === true) {
continue;
} else if ($code === T_THROW && $emptyBody === true) {
// Throw statement and an empty body indicate an interface method.
return;
} else if ($code === T_RETURN && $emptyBody === true) {
// Return statement and an empty body indicate an interface method.
$tmp = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($next + 1), null, true);
if ($tmp === false) {
return;
}
 
// There is a return.
if ($tokens[$tmp] === T_SEMICOLON) {
return;
}
 
$tmp = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($tmp + 1), null, true);
 
// There is a return <token>.
if ($tmp !== false && $tokens[$tmp] === T_SEMICOLON) {
return;
}
}//end if
 
$emptyBody = false;
 
if ($code === T_VARIABLE && isset($params[$token['content']]) === true) {
unset($params[$token['content']]);
} else if ($code === T_DOUBLE_QUOTED_STRING) {
// Tokenize double quote string.
$strTokens = token_get_all(sprintf('<?php %s;?>', $token['content']));
 
foreach ($strTokens as $tok) {
if (is_array($tok) === false || $tok[0] !== T_VARIABLE ) {
continue;
}
 
if (isset($params[$tok[1]]) === true) {
unset($params[$tok[1]]);
}
}
}//end if
}//end for
 
if ($emptyBody === false && count($params) > 0) {
foreach ($params as $paramName => $position) {
$error = 'The method parameter '.$paramName.' is never used';
$phpcsFile->addWarning($error, $position);
}
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php
New file
0,0 → 1,151
<?php
/**
* Generic_Sniffs_NamingConventions_UpperCaseConstantNameSniff.
*
* 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: UpperCaseConstantNameSniff.php,v 1.10 2008/05/07 23:13:49 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_NamingConventions_UpperCaseConstantNameSniff.
*
* 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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_NamingConventions_UpperCaseConstantNameSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_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();
$constName = $tokens[$stackPtr]['content'];
 
// If this token is in a heredoc, ignore it.
if ($phpcsFile->hasCondition($stackPtr, T_START_HEREDOC) === true) {
return;
}
 
// If the next non-whitespace token after this token
// is not an opening parenthesis then it is not a function call.
$openBracket = $phpcsFile->findNext(array(T_WHITESPACE), ($stackPtr + 1), null, true);
if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
$functionKeyword = $phpcsFile->findPrevious(array(T_WHITESPACE, T_COMMA, T_COMMENT, T_STRING), ($stackPtr - 1), null, true);
 
$declarations = array(
T_FUNCTION,
T_CLASS,
T_INTERFACE,
T_IMPLEMENTS,
T_EXTENDS,
T_INSTANCEOF,
T_NEW,
);
if (in_array($tokens[$functionKeyword]['code'], $declarations) === true) {
// This is just a declaration; no constants here.
return;
}
 
if ($tokens[$functionKeyword]['code'] === T_CONST) {
// This is a class constant.
if (strtoupper($constName) !== $constName) {
$error = 'Class constants must be uppercase; expected '.strtoupper($constName)." but found $constName";
$phpcsFile->addError($error, $stackPtr);
}
 
return;
}
 
// Is this a class name?
$nextPtr = $phpcsFile->findNext(array(T_WHITESPACE), ($stackPtr + 1), null, true);
if ($tokens[$nextPtr]['code'] === T_DOUBLE_COLON) {
return;
}
 
// Is this a type hint?
if ($tokens[$nextPtr]['code'] === T_VARIABLE) {
return;
} else if ($phpcsFile->isReference($nextPtr) === true) {
return;
}
 
// Is this a member var name?
$prevPtr = $phpcsFile->findPrevious(array(T_WHITESPACE), ($stackPtr - 1), null, true);
if ($tokens[$prevPtr]['code'] === T_OBJECT_OPERATOR) {
return;
}
 
// Is this an instance of declare()
$prevPtr = $phpcsFile->findPrevious(array(T_WHITESPACE, T_OPEN_PARENTHESIS), ($stackPtr - 1), null, true);
if ($tokens[$prevPtr]['code'] === T_DECLARE) {
return;
}
 
// This is a real constant.
if (strtoupper($constName) !== $constName) {
$error = 'Constants must be uppercase; expected '.strtoupper($constName)." but found $constName";
$phpcsFile->addError($error, $stackPtr);
}
 
} else if (strtolower($constName) === 'define' || strtolower($constName) === 'constant') {
 
/*
This may be a "define" or "constant" function call.
*/
 
// The next non-whitespace token must be the constant name.
$constPtr = $phpcsFile->findNext(array(T_WHITESPACE), ($openBracket + 1), null, true);
if ($tokens[$constPtr]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
return;
}
 
$constName = $tokens[$constPtr]['content'];
if (strtoupper($constName) !== $constName) {
$error = 'Constants must be uppercase; expected '.strtoupper($constName)." but found $constName";
$phpcsFile->addError($error, $stackPtr);
}
}//end if
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/NamingConventions/ConstructorNameSniff.php
New file
0,0 → 1,102
<?php
/**
* Generic_Sniffs_NamingConventions_ConstructorNameSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Leif Wickland <lwickland@rightnow.com>
* @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: ConstructorNameSniff.php,v 1.2 2009/02/24 04:43:44 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false) {
$error = 'Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
/**
* Generic_Sniffs_NamingConventions_ConstructorNameSniff.
*
* Favor PHP 5 constructor syntax, which uses "function __construct()".
* Avoid PHP 4 constructor syntax, which uses "function ClassName()".
*
* @category PHP
* @package PHP_CodeSniffer
* @author Leif Wickland <lwickland@rightnow.com>
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_NamingConventions_ConstructorNameSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff
{
 
 
/**
* Constructs the test with the tokens it wishes to listen for.
*
* @return void
*/
public function __construct()
{
parent::__construct(array(T_CLASS, T_INTERFACE), array(T_FUNCTION), true);
 
}//end __construct()
 
 
/**
* Processes this test when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The current file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
* @param int $currScope A pointer to the start of the scope.
*
* @return void
*/
protected function processTokenWithinScope(
PHP_CodeSniffer_File $phpcsFile,
$stackPtr,
$currScope
) {
$className = $phpcsFile->getDeclarationName($currScope);
$methodName = $phpcsFile->getDeclarationName($stackPtr);
 
if (strcasecmp($methodName, $className) === 0) {
$error = 'PHP4 style constructors are not allowed; use "__construct()" instead';
$phpcsFile->addError($error, $stackPtr);
} else if (strcasecmp($methodName, '__construct') !== 0) {
// Not a constructor.
return;
}
 
$tokens = $phpcsFile->getTokens();
 
$parentClassName = $phpcsFile->findExtendedClassName($currScope);
if ($parentClassName === false) {
return;
}
 
$endFunctionIndex = $tokens[$stackPtr]['scope_closer'];
$startIndex = $stackPtr;
while ($doubleColonIndex = $phpcsFile->findNext(array(T_DOUBLE_COLON), $startIndex, $endFunctionIndex)) {
if ($tokens[($doubleColonIndex + 1)]['code'] === T_STRING
&& $tokens[($doubleColonIndex + 1)]['content'] === $parentClassName
) {
$error = 'PHP4 style calls to parent constructors are not allowed; use "parent::__construct()" instead';
$phpcsFile->addError($error, ($doubleColonIndex + 1));
}
 
$startIndex = ($doubleColonIndex + 1);
}
 
}//end processTokenWithinScope()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/EmptyStatementUnitTest.php
New file
0,0 → 1,81
<?php
/**
* Unit test class for the EmptyStatement sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: EmptyStatementUnitTest.php,v 1.1 2008/02/06 02:38:36 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the EmptyStatement 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 Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_CodeAnalysis_EmptyStatementUnitTest 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(
64 => 1,
68 => 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(
3 => 1,
15 => 1,
17 => 1,
19 => 1,
30 => 1,
35 => 1,
41 => 1,
47 => 1,
52 => 1,
55 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/UnnecessaryFinalModifierUnitTest.php
New file
0,0 → 1,71
<?php
/**
* Unit test class for the UnnecessaryFinalModifier sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: UnnecessaryFinalModifierUnitTest.php,v 1.1 2008/02/06 02:38:37 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the UnnecessaryFinalModifier 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 Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_CodeAnalysis_UnnecessaryFinalModifierUnitTest 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(
11 => 1,
14 => 1,
17 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/ForLoopShouldBeWhileLoopUnitTest.php
New file
0,0 → 1,70
<?php
/**
* Unit test class for the ForLoopShouldBeWhileLoop sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: ForLoopShouldBeWhileLoopUnitTest.php,v 1.1 2008/02/06 02:38:36 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ForLoopShouldBeWhileLoop 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 Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_CodeAnalysis_ForLoopShouldBeWhileLoopUnitTest 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(
6 => 1,
10 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/UnconditionalIfStatementUnitTest.inc
New file
0,0 → 1,13
<?php
 
if (true) {
 
} else if (false) {
} elseif (true) {
}
 
if (file_exists(__FILE__) === true) {
}
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/UnusedFunctionParameterUnitTest.inc
New file
0,0 → 1,27
<?php
 
function foo($a, $b) {
return $a * 2;
}
 
function baz($a, $b) {
echo "baz({$a});";
}
 
function bar($a, $b) {
$x = $b;
for ($i = 0; $i <$a; $i++) {
$x += $a * $i;
}
return $x;
}
 
function foobar($a, &$b) {
return (preg_match('/foo/', $a, $b) !== 0);
}
 
class Foo {
function barfoo($a, $b) {
// Empty body means interface method in many cases.
}
}
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.inc
New file
0,0 → 1,25
<?php
 
class FooBar {
public function __construct($a, $b) {
parent::__construct($a, $b);
}
}
 
class BarFoo {
public function __construct($a, $b) {
parent::__construct($a, 'XML', $b);
}
}
 
class Foo {
public function export($a, $b = null) {
return parent::export($a, $b);
}
}
 
class Bar {
public function export($a, $b = null) {
return parent::export($a);
}
}
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/ForLoopWithTestFunctionCallUnitTest.inc
New file
0,0 → 1,15
<?php
 
$a = array(1, 2, 3, 4);
for ($i = 0; $i < count($a); $i++) {
$a[$i] *= $i;
}
 
for ($i = 0, $c = sizeof($a); $i < $c; ++$i) {
$a[$i] *= $i;
}
 
$it = new ArrayIterator($a);
for ($it->rewind(); $it->valid(); $it->next()) {
echo $it->current();
}
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/JumbledIncrementerUnitTest.inc
New file
0,0 → 1,25
<?php
 
for ($i = 0; $i < 20; $i++) {
for ($j = 0; $j < 5; $i += 2) {
for ($k = 0; $k > 3; $i++) {
}
}
}
 
for ($i = 0; $i < 20; $i++) {
for ($j = 0; $j < 5; $j += 2) {
for ($k = 0; $k > 3; $k++) {
}
}
}
 
for ($i = 0; $i < 20; $i++) {
for ($j = 0; $j < 5; $j += 2) {
for ($k = 0; $k > 3; $j++) {
}
}
}
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/EmptyStatementUnitTest.inc
New file
0,0 → 1,70
<?php
 
switch ($foo) {
// Empty switch statement body
}
 
switch ($foo) {
case 'bar':
break;
default:
break;
}
 
 
if ($foo) {
// Just a comment
} elseif ($bar) {
// Yet another comment
} else {
}
 
if ($foo) {
$foo = 'bar';
} else if ($bar) {
$bar = 'foo';
}
 
for ($i = 0; $i < 10; $i++) {
for ($j = 0; $j < 10; $j++) {
// Just a comment
}
}
 
foreach ($foo as $bar) {}
 
foreach ($foo as $bar) {
$bar *= 2;
}
 
do {
// Just a comment
// Just another comment
} while ($foo);
 
do {
while ($bar) {
}
} while (true);
 
while ($foo) { /* Comment in the same line */ }
 
while ($foo) {
try {
} catch (Exception $e) {
echo $e->getTraceAsString();
}
}
 
try {
throw Exception('Error...');
} catch (Exception $e) {}
 
try {
throw Exception('Error...');
} catch (Exception $e) {
// TODO: Handle this exception later :-)
}
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/UnconditionalIfStatementUnitTest.php
New file
0,0 → 1,71
<?php
/**
* Unit test class for the UnconditionalIfStatement sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: UnconditionalIfStatementUnitTest.php,v 1.1 2008/02/06 02:38:37 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the UnconditionalIfStatement 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 Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_CodeAnalysis_UnconditionalIfStatementUnitTest 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(
3 => 1,
5 => 1,
7 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/UnnecessaryFinalModifierUnitTest.inc
New file
0,0 → 1,24
<?php
 
class Foo {
public final $FOOBAR = 23;
protected final $FOO = 42;
private final $BAR = 17;
}
 
final class Foo_Bar {
public $foobar;
public final $FOOBAR = 23;
protected $foo;
protected final $FOO = 42;
private $bar;
private final $BAR = 17;
}
 
final class Bar_Foo {
public $foobar;
protected $foo;
private $bar;
}
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/UnusedFunctionParameterUnitTest.php
New file
0,0 → 1,70
<?php
/**
* Unit test class for the UnusedFunctionParameter sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: UnusedFunctionParameterUnitTest.php,v 1.1 2008/02/06 02:38:37 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the UnusedFunctionParameter 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 Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_CodeAnalysis_UnusedFunctionParameterUnitTest 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(
3 => 1,
7 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/ForLoopShouldBeWhileLoopUnitTest.inc
New file
0,0 → 1,13
<?php
for ($i = 0; $i < 10; $i++) {
// Everything is fine
}
 
for (; $it->valid();) {
$it->next();
}
 
for (;(($it1->valid() && $foo) || (!$it2->value && ($bar || false)));/*Could be ingored*/) {
$it1->next();
$it2->next();
}
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.php
New file
0,0 → 1,70
<?php
/**
* Unit test class for the UselessOverridingMethod sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: UselessOverridingMethodUnitTest.php,v 1.1 2008/02/06 02:38:37 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the UselessOverridingMethod 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 Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_CodeAnalysis_UselessOverridingMethodUnitTest 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(
4 => 1,
16 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/ForLoopWithTestFunctionCallUnitTest.php
New file
0,0 → 1,70
<?php
/**
* Unit test class for the ForLoopWithTestFunctionCall sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: ForLoopWithTestFunctionCallUnitTest.php,v 1.1 2008/02/06 02:38:37 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ForLoopWithTestFunctionCall 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 Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_CodeAnalysis_ForLoopWithTestFunctionCallUnitTest 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(
4 => 1,
13 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/JumbledIncrementerUnitTest.php
New file
0,0 → 1,71
<?php
/**
* Unit test class for the JumbledIncrementer sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: JumbledIncrementerUnitTest.php,v 1.1 2008/02/06 02:38:37 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the JumbledIncrementer 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 Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_CodeAnalysis_JumbledIncrementerUnitTest 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(
3 => 2,
4 => 1,
20 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/NamingConventions/UpperCaseConstantNameUnitTest.php
New file
0,0 → 1,79
<?php
/**
* Unit test class for the ValidConstantName 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: UpperCaseConstantNameUnitTest.php,v 1.3 2007/01/10 03:14:43 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ValidConstantName 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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_NamingConventions_UpperCaseConstantNameUnitTest 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,
6 => 1,
11 => 1,
21 => 1,
22 => 1,
23 => 1,
24 => 1,
25 => 1,
28 => 1,
31 => 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
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/NamingConventions/UpperCaseConstantNameUnitTest.inc
New file
0,0 → 1,83
<?php
 
define('VALID_NAME', true);
define('invalidName', true);
define("VALID_NAME", true);
define("invalidName", true);
 
class TestClass extends MyClass, YourClass
{
 
const const1 = 'hello';
const CONST2 = 'hello';
 
function test()
{
echo constant('VALID_NAME');
echo VALID_NAME;
print VALID_NAME;
echo(VALID_NAME);
print(VALID_NAME);
echo constant('invalidName');
echo invalidName;
print invalidName;
echo(invalidName);
print(invalidName);
 
echo constant("VALID_NAME");
echo constant("invalidName");
 
echo 'Hello', VALID_NAME;
echo 'Hello', invalidName;
 
// These might look like constants to
// poorly written code.
echo 'Hello there';
echo "HELLO";
echo 'HELLO';
print 'Hello there';
print "HELLO";
print 'HELLO';
}
 
function myFunc(PHP_CodeSniffer &$blah) {}
function myFunc(PHP_CodeSniffer $blah) {}
 
}
 
interface MyInterface
{
}
 
if (($object instanceof Some_Class) === false) {
$var = <<<EOF
This is some heredoc text.
This is some heredoc text.
This is some heredoc text.
 
This is some heredoc text.
This is some heredoc text.
This is some heredoc text.
EOF;
}
 
$var = <<<EOF
This is some heredoc text.
This is some heredoc text.
This is some heredoc text.
 
This is some heredoc text.
This is some heredoc text.
This is some heredoc text.
EOF;
 
throw new InvalidSomethingException;
 
declare(ticks = 1) {
foreach ($var as $bit) {
echo $bit;
}
}
 
$binary = (binary) $string;
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.php
New file
0,0 → 1,71
<?php
/**
* Unit test class for the ConstructorName sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ConstructorNameUnitTest.php,v 1.1 2009/02/23 05:16:22 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ConstructorName 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>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_NamingConventions_ConstructorNameUnitTest 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,
11 => 1,
20 => 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
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.inc
New file
0,0 → 1,31
<?php
class TestClass extends MyClass
{
 
function TestClass() {
parent::MyClass();
parent::__construct();
}
 
function __construct() {
parent::MyClass();
parent::__construct();
}
 
}
 
class MyClass
{
 
function MyClass() {
parent::YourClass();
parent::__construct();
}
 
function __construct() {
parent::YourClass();
parent::__construct();
}
 
}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Commenting/TodoUnitTest.php
New file
0,0 → 1,98
<?php
/**
* Unit test class for the Todo 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: TodoUnitTest.php,v 1.2 2008/08/19 05:26:35 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the Todo 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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Commenting_TodoUnitTest 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.
*
* @param string $testFile The name of the file being tested.
*
* @return array(int => int)
*/
public function getErrorList($testFile='TodoUnitTest.inc')
{
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.
*
* @param string $testFile The name of the file being tested.
*
* @return array(int => int)
*/
public function getWarningList($testFile='TodoUnitTest.inc')
{
switch ($testFile) {
case 'TodoUnitTest.inc':
return array(
3 => 1,
7 => 1,
10 => 1,
13 => 1,
16 => 1,
18 => 1,
21 => 1,
);
break;
case 'TodoUnitTest.js':
return array(
3 => 1,
7 => 1,
10 => 1,
13 => 1,
16 => 1,
18 => 1,
21 => 1,
);
break;
default:
return array();
break;
}//end switch
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Commenting/TodoUnitTest.inc
New file
0,0 → 1,22
<?php
/**
* TODO: Write this comment
*
*/
 
// TODO: remove this.
error_log('test');
 
// TODO remove this.
Debug::bam('test');
 
// todo - remove this.
 
// Extract info from the array.
// TODO: can this be done faster?
 
// Extract info from the array (todo: make it faster)
// To do this, use a function!
// notodo! NOTODO! NOtodo!
//TODO.
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Commenting/TodoUnitTest.js
New file
0,0 → 1,22
<?php
/**
* TODO: Write this comment
*
*/
 
// TODO: remove this.
alert('test');
 
// TODO remove this.
alert('test');
 
// todo - remove this.
 
// Extract info from the array.
// TODO: can this be done faster?
 
// Extract info from the array (todo: make it faster)
// To do this, use a function!
// notodo! NOTODO! NOtodo!
//TODO.
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Files/LineEndingsUnitTest.js
New file
0,0 → 1,2
alert('hi');
alert('hi');
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Files/LineLengthUnitTest.php
New file
0,0 → 1,79
<?php
/**
* Unit test class for the LineLength 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: LineLengthUnitTest.php,v 1.5 2008/06/27 01:58:38 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the LineLength 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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Files_LineLengthUnitTest 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(
31 => 1,
34 => 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(
9 => 1,
15 => 1,
21 => 1,
24 => 1,
29 => 1,
37 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Files/LineLengthUnitTest.inc
New file
0,0 → 1,55
<?php
 
// This line is okay... just!
if (($reallyLongVarName === true) || (is_array($anotherLongVarName) == false)) {
// Do something.
}
 
// This line is not okay... just!
if (($reallyLongVarName === true) || (is_array($anotherLongVarName) === false)) {
// Do something.
}
 
 
// This line is is too long.
if (($anotherReallyLongVarName === true) || (is_array($anotherReallyLongVarName) === false)) {
// Do something.
}
 
// This is a really really long comment that is going to go to exactly 80 chars.
 
// This is another really really long comment that is going to go well over 80 characters.
 
// And here is just a bunch of spaces that exceeds the line length.
 
// And here are some spaces exactly 80 chars long.
 
// This is a really really really really long long comment that is going to go to exactly 100 chars.
 
// This is another really really really really really long comment that is going to go well over 100 characters.
 
// And here is just a bunch of spaces that exceeds the max line length.
 
// And here are some spaces exactly 100 chars long.
?>
<b>Hello</b>b>
<?php
echo 'hi';
?>
 
<?php
/**
* Comments contining CVS IDs can be long, but should be ignored because
* they cannot be changed by the developer. Same with license URLs.
*
* @version CVS: $Id: LineLengthUnitTest.inc,v 1.6 2008/06/27 01:58:38 squiz Exp $
* @license http://www.freebsd.org/copyright/freebsd-license.html BSD License (2 Clause)
*/
?>
 
<?php
// This is another really long comment that is going to go well over 100 characters, with no closing php tag after it.
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Files/LineEndingsUnitTest.php
New file
0,0 → 1,70
<?php
/**
* Unit test class for the LineEndings 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: LineEndingsUnitTest.php,v 1.1 2007/06/06 23:31:35 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the LineEndings 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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Files_LineEndingsUnitTest 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
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Files/LineEndingsUnitTest.css
New file
0,0 → 1,3
#login-container {
margin-left: -225px;
}
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Files/LineEndingsUnitTest.inc
New file
0,0 → 1,7
<?php
echo 'hi';
?>
 
<?php
echo 'hi';
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.php
New file
0,0 → 1,94
<?php
/**
* Unit test class for the InlineControlStructure 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: InlineControlStructureUnitTest.php,v 1.2 2008/07/01 01:25:08 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the InlineControlStructure 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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_ControlStructures_InlineControlStructureUnitTest 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.
*
* @param string $testFile The name of the file being tested.
*
* @return array(int => int)
*/
public function getErrorList($testFile='InlineControlStructureUnitTest.inc')
{
switch ($testFile) {
case 'InlineControlStructureUnitTest.inc':
return array(
3 => 1,
7 => 1,
11 => 1,
13 => 1,
15 => 1,
17 => 1,
23 => 1,
);
break;
case 'InlineControlStructureUnitTest.js':
return array(
3 => 1,
7 => 1,
11 => 1,
13 => 1,
15 => 1,
);
break;
default:
return array();
break;
}//end switch
 
}//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
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc
New file
0,0 → 1,26
<?php
 
if ($something) echo 'hello';
 
if ($something) {
echo 'hello';
} else echo 'hi';
 
if ($something) {
echo 'hello';
} else if ($else) echo 'hi';
 
foreach ($something as $thing) echo 'hello';
 
for ($i; $i > 0; $i--) echo 'hello';
 
while ($something) echo 'hello';
 
do {
$i--;
} while ($something);
 
if(true)
$someObject->{$name};
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.js
New file
0,0 → 1,21
<?php
 
if ($something) echo 'hello';
 
if ($something) {
echo 'hello';
} else echo 'hi';
 
if ($something) {
echo 'hello';
} else if ($else) echo 'hi';
 
for ($i; $i > 0; $i--) echo 'hello';
 
while ($something) echo 'hello';
 
do {
$i--;
} while ($something);
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Metrics/NestingLevelUnitTest.inc
New file
0,0 → 1,102
<?php
 
function nestingOne()
{
if ($condition) {
echo 'hi';
}
}
 
function nestingFive()
{
if ($condition) {
echo 'hi';
switch ($condition)
{
case '1':
if ($condition === '1') {
if ($cond) {
echo 'hi';
}
}
break;
}
}
}
 
function nestingSix()
{
if ($condition) {
echo 'hi';
switch ($condition)
{
case '1':
if ($condition === '1') {
if ($cond) {
foreach ($conds as $cond) {
echo 'hi';
}
}
}
break;
}
}
}
 
function nestingTen()
{
if ($condition) {
echo 'hi';
switch ($condition)
{
case '1':
if ($condition === '1') {
if ($cond) {
switch ($cond) {
case '1':
if ($cond === '1') {
foreach ($conds as $cond) {
if ($cond === 'hi') {
echo 'hi';
}
}
}
break;
}
}
}
break;
}
}
}
 
function nestingEleven()
{
if ($condition) {
echo 'hi';
switch ($condition)
{
case '1':
if ($condition === '1') {
if ($cond) {
switch ($cond) {
case '1':
if ($cond === '1') {
foreach ($conds as $cond) {
if ($cond === 'hi') {
if ($cond !== 'bye') {
echo 'hi';
}
}
}
}
break;
}
}
}
break;
}
}
}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Metrics/CyclomaticComplexityUnitTest.php
New file
0,0 → 1,73
<?php
/**
* Unit test class for the CyclomaticComplexity 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: CyclomaticComplexityUnitTest.php,v 1.1 2007/07/30 04:55:35 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the CyclomaticComplexity 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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Metrics_CyclomaticComplexityUnitTest 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(
116 => 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(
45 => 1,
72 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Metrics/CyclomaticComplexityUnitTest.inc
New file
0,0 → 1,160
<?php
 
function complexityOne() { }
 
function comlexityFive()
{
if ($condition) {
}
 
switch ($condition) {
case '1':
break;
case '2':
break;
case '3':
break;
}
}
 
function comlexityTen()
{
while ($condition === true) {
if ($condition) {
}
}
 
switch ($condition) {
case '1':
if ($condition) {
} else if ($cond) {
}
break;
case '2':
while ($cond) {
echo 'hi';
}
break;
case '3':
break;
default:
break;
}
}
 
function comlexityEleven()
{
while ($condition === true) {
if ($condition) {
} else if ($cond) {
}
}
 
switch ($condition) {
case '1':
if ($condition) {
} else if ($cond) {
}
break;
case '2':
while ($cond) {
echo 'hi';
}
break;
case '3':
break;
default:
break;
}
}
 
 
function comlexityTwenty()
{
while ($condition === true) {
if ($condition) {
} else if ($cond) {
}
}
 
switch ($condition) {
case '1':
if ($condition) {
} else if ($cond) {
}
break;
case '2':
while ($cond) {
echo 'hi';
}
break;
case '3':
switch ($cond) {
case '1':
break;
case '2':
break;
}
break;
case '4':
do {
if ($condition) {
if ($cond) {
} else if ($con) {
}
}
} while ($cond);
break;
default:
if ($condition) {
}
break;
}
}
 
 
function comlexityTwentyOne()
{
while ($condition === true) {
if ($condition) {
} else if ($cond) {
}
}
 
switch ($condition) {
case '1':
if ($condition) {
} else if ($cond) {
}
break;
case '2':
while ($cond) {
echo 'hi';
}
break;
case '3':
switch ($cond) {
case '1':
break;
case '2':
break;
}
break;
case '4':
do {
if ($condition) {
if ($cond) {
} else if ($con) {
}
}
} while ($cond);
break;
default:
if ($condition) {
} else if ($cond) {
}
break;
}
}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Metrics/NestingLevelUnitTest.php
New file
0,0 → 1,73
<?php
/**
* Unit test class for the NestingLevel 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: NestingLevelUnitTest.php,v 1.1 2007/07/30 04:55:35 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the NestingLevel 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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Metrics_NestingLevelUnitTest 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(
73 => 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(
27 => 1,
46 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/PHP/DisallowShortOpenTagUnitTest.php
New file
0,0 → 1,77
<?php
/**
* Unit test class for the DisallowShortOpenTag 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: DisallowShortOpenTagUnitTest.php,v 1.2 2006/12/12 02:31:20 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the DisallowShortOpenTag 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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_PHP_DisallowShortOpenTagUnitTest 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()
{
$option = (boolean) ini_get('short_open_tag');
 
if ($option === false) {
return array();
}
 
return array(
4 => 1,
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
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/PHP/DisallowShortOpenTagUnitTest.inc
New file
0,0 → 1,6
<div>
<?php echo $var; ?>
Some content here.
<?= $var; ?>
<? echo $var; ?>
</div>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/PHP/LowerCaseConstantUnitTest.php
New file
0,0 → 1,102
<?php
/**
* Unit test class for the LowerCaseConstant 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: LowerCaseConstantUnitTest.php,v 1.4 2008/02/18 00:01:06 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the LowerCaseConstant 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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_PHP_LowerCaseConstantUnitTest 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.
*
* @param string $testFile The name of the file being tested.
*
* @return array(int => int)
*/
public function getErrorList($testFile='LowerCaseConstantUnitTest.inc')
{
switch ($testFile) {
case 'LowerCaseConstantUnitTest.inc':
return array(
7 => 1,
10 => 1,
15 => 1,
16 => 1,
23 => 1,
26 => 1,
31 => 1,
32 => 1,
39 => 1,
42 => 1,
47 => 1,
48 => 1,
);
break;
case 'LowerCaseConstantUnitTest.js':
return array(
2 => 1,
3 => 1,
4 => 1,
7 => 1,
8 => 1,
12 => 1,
13 => 1,
14 => 1,
);
break;
default:
return array();
break;
}
 
}//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
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/PHP/LowerCaseConstantUnitTest.inc
New file
0,0 → 1,50
<?php
 
// True
function myFunction($arg1, $arg2=true)
{
}
function myFunction($arg1, $arg2=TRUE)
{
}
function myFunction($arg1, $arg2=True)
{
}
 
if ($variable === true) { }
if ($variable === TRUE) { }
if ($variable === True) { }
 
 
// False
function myFunction($arg1, $arg2=false)
{
}
function myFunction($arg1, $arg2=FALSE)
{
}
function myFunction($arg1, $arg2=False)
{
}
 
if ($variable === false) { }
if ($variable === FALSE) { }
if ($variable === False) { }
 
 
// Null
function myFunction($arg1, $arg2=null)
{
}
function myFunction($arg1, $arg2=NULL)
{
}
function myFunction($arg1, $arg2=Null)
{
}
 
if ($variable === null) { }
if ($variable === NULL) { }
if ($variable === Null) { }
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/PHP/NoSilencedErrorsUnitTest.php
New file
0,0 → 1,68
<?php
/**
* Unit test class for the NoSilencedErrors sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: NoSilencedErrorsUnitTest.php,v 1.1 2008/12/03 04:42:07 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the NoSilencedErrors 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>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_PHP_NoSilencedErrorsUnitTest 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(
5 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/PHP/UpperCaseConstantUnitTest.php
New file
0,0 → 1,81
<?php
/**
* Unit test class for the UpperCaseConstant 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: UpperCaseConstantUnitTest.php,v 1.3 2007/01/10 03:14:43 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the UpperCaseConstant 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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_PHP_UpperCaseConstantUnitTest 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(
7 => 1,
10 => 1,
15 => 1,
16 => 1,
23 => 1,
26 => 1,
31 => 1,
32 => 1,
39 => 1,
42 => 1,
47 => 1,
48 => 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
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/PHP/NoSilencedErrorsUnitTest.inc
New file
0,0 → 1,9
<?php
/**
* @see something
*/
if (@in_array($array, $needle))
{
echo '@';
}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/PHP/LowerCaseConstantUnitTest.js
New file
0,0 → 1,14
if (variable === true) { }
if (variable === TRUE) { }
if (variable === True) { }
variable = True;
 
if (variable === false) { }
if (variable === FALSE) { }
if (variable === False) { }
variable = false;
 
if (variable === null) { }
if (variable === NULL) { }
if (variable === Null) { }
variable = NULL;
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/PHP/UpperCaseConstantUnitTest.inc
New file
0,0 → 1,50
<?php
 
// True
function myFunction($arg1, $arg2=TRUE)
{
}
function myFunction($arg1, $arg2=true)
{
}
function myFunction($arg1, $arg2=True)
{
}
 
if ($variable === TRUE) { }
if ($variable === true) { }
if ($variable === True) { }
 
 
// False
function myFunction($arg1, $arg2=FALSE)
{
}
function myFunction($arg1, $arg2=false)
{
}
function myFunction($arg1, $arg2=False)
{
}
 
if ($variable === FALSE) { }
if ($variable === false) { }
if ($variable === False) { }
 
 
// Null
function myFunction($arg1, $arg2=NULL)
{
}
function myFunction($arg1, $arg2=null)
{
}
function myFunction($arg1, $arg2=Null)
{
}
 
if ($variable === NULL) { }
if ($variable === null) { }
if ($variable === Null) { }
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/PHP/ForbiddenFunctionsUnitTest.php
New file
0,0 → 1,71
<?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:01:17 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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_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,
4 => 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
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/PHP/ForbiddenFunctionsUnitTest.inc
New file
0,0 → 1,22
<?php
$size = sizeof($array);
$size = count($array);
delete($filepath);
unset($filepath);
 
// No errors thrown for class methods.
$size = MyClass::sizeof($array);
$size = MyClass::count($array);
MyClass::delete($filepath);
MyClass::unset($filepath);
 
$size = $class->sizeof($array);
$size = $class->count($array);
$class->delete($filepath);
$class->unset($filepath);
 
function delete() {}
function unset() {}
function sizeof() {}
function count() {}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.php
New file
0,0 → 1,88
<?php
/**
* Unit test class for the OpeningFunctionBraceBsdAllman 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: OpeningFunctionBraceBsdAllmanUnitTest.php,v 1.3 2007/12/04 23:24:33 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the OpeningFunctionBraceBsdAllman 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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Functions_OpeningFunctionBraceBsdAllmanUnitTest 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,
13 => 1,
19 => 1,
24 => 1,
30 => 1,
40 => 1,
44 => 1,
50 => 1,
55 => 1,
67 => 1,
78 => 1,
85 => 1,
91 => 1,
98 => 1,
110 => 1,
115 => 1,
122 => 1,
128 => 1,
155 => 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
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Functions/OpeningFunctionBraceKernighanRitchieUnitTest.php
New file
0,0 → 1,82
<?php
/**
* Unit test class for the OpeningFunctionBraceKernighanRitchie 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: OpeningFunctionBraceKernighanRitchieUnitTest.php,v 1.3 2007/12/04 23:24:33 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the OpeningFunctionBraceKernighanRitchie 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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Functions_OpeningFunctionBraceKernighanRitchieUnitTest 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(
9 => 1,
13 => 1,
17 => 1,
29 => 1,
33 => 1,
37 => 1,
53 => 1,
58 => 1,
63 => 1,
77 => 1,
82 => 1,
87 => 1,
104 => 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
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.inc
New file
0,0 → 1,157
<?php
 
// Brace should be on new line.
function myFunction() {
}
 
// Good.
function myFunction()
{
}
 
// Too many spaces.
function myFunction() {
}
 
// Too many newlines.
function myFunction()
 
{
}
 
// Space before brace.
function myFunction()
{
}
 
class myClass()
{
// Brace should be on new line.
function myFunction() {
}
// Good.
function myFunction()
{
}
 
// No aligned correctly.
function myFunction()
{
}
// Too many spaces.
function myFunction() {
}
// Too many newlines.
function myFunction()
 
{
}
// Space before brace.
function myFunction()
{
}
}
 
 
 
/* Multi-line declarations */
 
 
 
// Brace should be on new line.
function myFunction($variable1, $variable2,
$variable3, $variable4) {
}
 
// Good.
function myFunction($variable1, $variable2,
$variable3, $variable4)
{
}
 
// Too many spaces.
function myFunction($variable1, $variable2,
$variable3, $variable4) {
}
 
// Too many newlines.
function myFunction($variable1, $variable2,
$variable3, $variable4)
 
{
}
 
// Space before brace.
function myFunction($variable1, $variable2,
$variable3, $variable4)
{
}
 
class myClass()
{
// Brace should be on new line.
function myFunction($variable1, $variable2,
$variable3, $variable4) {
}
// Good.
function myFunction($variable1, $variable2,
$variable3, $variable4)
{
}
 
// No aligned correctly.
function myFunction($variable1, $variable2,
$variable3, $variable4)
{
}
// Too many spaces.
function myFunction($variable1, $variable2,
$variable3, $variable4) {
}
// Too many newlines.
function myFunction($variable1, $variable2,
$variable3, $variable4)
 
{
}
// Space before brace.
function myFunction($variable1, $variable2,
$variable3, $variable4)
{
}
}
 
interface MyInterface()
{
function myFunction();
}
 
function myFunction(
$arg1,
$arg2,
$arg3,
$arg4,
$arg5,
$arg6
)
{
}
 
function myFunction(
$arg1,
$arg2,
$arg3,
$arg4,
$arg5,
$arg6
) {
}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Functions/OpeningFunctionBraceKernighanRitchieUnitTest.inc
New file
0,0 → 1,117
<?php
 
// Good.
function myFunction() {
}
 
// Brace should be on same line.
function myFunction()
{
}
 
// Too many spaces.
function myFunction() {
}
 
// Uses tab.
function myFunction() {
}
 
 
class myClass()
{
// Good.
function myFunction() {
}
// Brace should be on same line.
function myFunction()
{
}
// Too many spaces.
function myFunction() {
}
// Uses tab.
function myFunction() {
}
}
 
 
 
/* Multi-line declarations */
 
// Good.
function myFunction($variable1, $variable2,
$variable3, $variable4) {
}
 
// Brace should be on same line.
function myFunction($variable1, $variable2,
$variable3, $variable4)
{
}
 
// Too many spaces.
function myFunction($variable1, $variable2,
$variable3, $variable4) {
}
 
// Uses tab.
function myFunction($variable1, $variable2,
$variable3, $variable4) {
}
 
 
class myClass()
{
// Good.
function myFunction($variable1, $variable2,
$variable3, $variable4) {
}
// Brace should be on same line.
function myFunction($variable1, $variable2,
$variable3, $variable4)
{
}
// Too many spaces.
function myFunction($variable1, $variable2,
$variable3, $variable4) {
}
// Uses tab.
function myFunction($variable1, $variable2,
$variable3, $variable4) {
}
}
 
interface MyInterface()
{
function myFunction();
}
 
function myFunction(
$arg1,
$arg2,
$arg3,
$arg4,
$arg5,
$arg6
)
{
}
 
function myFunction(
$arg1,
$arg2,
$arg3,
$arg4,
$arg5,
$arg6
) {
}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Strings/UnnecessaryStringConcatUnitTest.inc
New file
0,0 → 1,10
<?php
$x = 'My '.'string';
$x = 'My '.1234;
$x = 'My '.$y.' test';
 
echo $data['my'.'index'];
echo $data['my'.4];
echo $data['my'.$x];
echo $data[$x.$y.'My'.'String'];
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Strings/UnnecessaryStringConcatUnitTest.js
New file
0,0 → 1,11
var x = 'My ' + 'string';
var x = 'My ' + 1234;
var x = 'My ' + y + ' test';
 
this.errors['test'] = x;
this.errors['test' + 10] = x;
this.errors['test' + y] = x;
this.errors['test' + 'blah'] = x;
this.errors[y] = x;
this.errors[y + z] = x;
this.errors[y + z + 'My' + 'String'] = x;
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Strings/UnnecessaryStringConcatUnitTest.php
New file
0,0 → 1,86
<?php
/**
* Unit test class for the UnnecessaryStringConcat sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: UnnecessaryStringConcatUnitTest.php,v 1.1 2008/12/05 04:39:00 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the UnnecessaryStringConcat 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>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Strings_UnnecessaryStringConcatUnitTest 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.
*
* @param string $testFile The name of the file being tested.
*
* @return array(int => int)
*/
public function getErrorList($testFile='UnnecessaryStringConcatUnitTest.inc')
{
switch ($testFile) {
case 'UnnecessaryStringConcatUnitTest.inc':
return array(
2 => 1,
6 => 1,
9 => 1,
);
break;
case 'UnnecessaryStringConcatUnitTest.js':
return array(
1 => 1,
8 => 1,
11 => 1,
);
break;
default:
return array();
break;
}
 
}//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
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Formatting/NoSpaceAfterCastUnitTest.inc
New file
0,0 → 1,47
<?php
 
$var = (int) $var2;
$var = (int)$var2;
$var = (int) $var2;
 
$var = (integer) $var2;
$var = (integer)$var2;
$var = (integer) $var2;
 
$var = (string) $var2;
$var = (string)$var2;
$var = (string) $var2;
 
$var = (float) $var2;
$var = (float)$var2;
$var = (float) $var2;
 
$var = (double) $var2;
$var = (double)$var2;
$var = (double) $var2;
 
$var = (real) $var2;
$var = (real)$var2;
$var = (real) $var2;
 
$var = (array) $var2;
$var = (array)$var2;
$var = (array) $var2;
 
$var = (bool) $var2;
$var = (bool)$var2;
$var = (bool) $var2;
 
$var = (boolean) $var2;
$var = (boolean)$var2;
$var = (boolean) $var2;
 
$var = (object) $var2;
$var = (object)$var2;
$var = (object) $var2;
 
$var = (unset) $var2;
$var = (unset)$var2;
$var = (unset) $var2;
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.php
New file
0,0 → 1,91
<?php
/**
* Unit test class for the SpaceAfterCast 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: SpaceAfterCastUnitTest.php,v 1.1 2007/06/29 00:57:37 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the SpaceAfterCast 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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Formatting_SpaceAfterCastUnitTest 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,
8 => 1,
9 => 1,
12 => 1,
13 => 1,
16 => 1,
17 => 1,
20 => 1,
21 => 1,
24 => 1,
25 => 1,
28 => 1,
29 => 1,
32 => 1,
33 => 1,
36 => 1,
37 => 1,
40 => 1,
41 => 1,
44 => 1,
45 => 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
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.inc
New file
0,0 → 1,47
<?php
 
$var = (int) $var2;
$var = (int)$var2;
$var = (int) $var2;
 
$var = (integer) $var2;
$var = (integer)$var2;
$var = (integer) $var2;
 
$var = (string) $var2;
$var = (string)$var2;
$var = (string) $var2;
 
$var = (float) $var2;
$var = (float)$var2;
$var = (float) $var2;
 
$var = (double) $var2;
$var = (double)$var2;
$var = (double) $var2;
 
$var = (real) $var2;
$var = (real)$var2;
$var = (real) $var2;
 
$var = (array) $var2;
$var = (array)$var2;
$var = (array) $var2;
 
$var = (bool) $var2;
$var = (bool)$var2;
$var = (bool) $var2;
 
$var = (boolean) $var2;
$var = (boolean)$var2;
$var = (boolean) $var2;
 
$var = (object) $var2;
$var = (object)$var2;
$var = (object) $var2;
 
$var = (unset) $var2;
$var = (unset)$var2;
$var = (unset) $var2;
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.php
New file
0,0 → 1,135
<?php
/**
* Unit test class for the MultipleStatementAlignment 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: MultipleStatementAlignmentUnitTest.php,v 1.9 2008/02/21 05:21:12 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the MultipleStatementAlignment 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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Formatting_MultipleStatementAlignmentUnitTest 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.
*
* @param string $testFile The name of the file being tested.
*
* @return array(int => int)
*/
public function getWarningList($testFile='MultipleStatementAlignmentUnitTest.inc')
{
switch ($testFile) {
case 'MultipleStatementAlignmentUnitTest.inc':
return array(
11 => 1,
12 => 1,
23 => 1,
24 => 1,
26 => 1,
27 => 1,
37 => 1,
38 => 1,
48 => 1,
50 => 1,
61 => 1,
62 => 1,
64 => 1,
65 => 1,
71 => 1,
78 => 1,
79 => 1,
86 => 1,
92 => 1,
93 => 1,
94 => 1,
95 => 1,
123 => 1,
124 => 1,
126 => 1,
129 => 1,
154 => 1,
161 => 1,
178 => 1,
179 => 1,
182 => 1,
);
break;
case 'MultipleStatementAlignmentUnitTest.js':
return array(
11 => 1,
12 => 1,
23 => 1,
24 => 1,
26 => 1,
27 => 1,
37 => 1,
38 => 1,
48 => 1,
50 => 1,
61 => 1,
62 => 1,
64 => 1,
65 => 1,
71 => 1,
78 => 1,
79 => 1,
81 => 1,
82 => 1,
83 => 1,
85 => 1,
86 => 1,
);
break;
default:
return array();
break;
}
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.inc
New file
0,0 → 1,198
<?php
 
// Valid
$var1 = 'var1';
$var10 = 'var1';
$var100 = 'var1';
$var1000 = 'var1';
 
// Invalid
$var1 = 'var1';
$var10 = 'var1';
$var100 = 'var1';
$var1000 = 'var1';
 
// Valid
$var1 = 'var1';
$var10 = 'var1';
 
$var100 = 'var1';
$var1000 = 'var1';
 
// Invalid
$var1 = 'var1';
$var10 = 'var1';
 
$var100 = 'var1';
$var1000 = 'var1';
 
// Valid
$var1 .= 'var1';
$var10 .= 'var1';
$var100 .= 'var1';
$var1000 .= 'var1';
 
// Invalid
$var1 .= 'var1';
$var10 .= 'var1';
$var100 .= 'var1';
$var1000 .= 'var1';
 
// Valid
$var1 = 'var1';
$var10 .= 'var1';
$var100 = 'var1';
$var1000 .= 'var1';
 
// Invalid
$var1 = 'var1';
$var10 .= 'var1';
$var100 = 'var1';
$var1000 .= 'var1';
 
// Valid
$var1 .= 'var1';
$var10 .= 'var1';
 
$var100 .= 'var1';
$var1000 .= 'var1';
 
// Invalid
$var1 .= 'var1';
$var10 .= 'var1';
 
$var100 .= 'var1';
$var1000 .= 'var1';
 
// Valid
$var = 100;
 
// InValid
$var = 100;
 
$commentStart = $phpcsFile->findPrevious();
$commentEnd = $this->_phpcsFile;
$expected .= '...';
 
// Invalid
$this->okButton = new Button();
$content = new MyClass();
 
 
$GLOBALS['_PEAR_ERRORSTACK_SINGLETON'] = array();
 
class MyClass
{
const MODE_DEBUG = 'debug';
const MODE_DEBUG2 = 'debug';
 
$array[$test] = 'anything';
$var = 'anything';
 
const MODE_DEBUG2 = 'debug';
$array[$test] = 'anything';
$var = 'anything';
$array[($test + 1)] = 'anything';
$array[($blah + (10 - $test))] = 'anything';
}
 
function myFunction($var=true)
{
if ($strict === true) {
$length = strlen($string);
$lastCharWasCaps = ($classFormat === false) ? false : true;
 
for ($i = 1; $i < $length; $i++) {
$isCaps = (strtoupper($string{$i}) === $string{$i}) ? true : false;
if ($isCaps === true && $lastCharWasCaps === true) {
return false;
}
 
$lastCharWasCaps = $isCaps;
}
}
}
 
// Valid
for ($i = 0; $i < 10; $i += 2) {
$i = ($i - 1);
}
 
// Invalid
foreach ($files as $file) {
$saves[$file] = array();
$contents = stripslashes(file_get_contents($file));
list($assetid, $time, $content) = explode("\n", $contents);
$saves[$file]['assetid'] = $assetid;
}
 
$i = ($i - 10);
$ip = ($i - 10);
for ($i = 0; $i < 10; $i += 2) {
$i = ($i - 10);
}
 
// Valid
$variable = 12;
$var = a_very(long_line('that', 'contains'),
a_bunch('of long', 'parameters'),
'that_need to be aligned with the equal sign');
$var2 = 12;
 
// Valid
$variable = 12;
$var = 'a very long line of text that contains '
.$someVar
.' and some other stuff that is too long to fit on one line';
$var2 = 12;
 
// Invalid
$variable = 12;
$var = a_very(long_line('that', 'contains'),
a_bunch('of long', 'parameters'),
'that_need to be aligned with the equal sign');
$var2 = 12;
 
// Invalid
$variable = 12;
$var = 'a very long line of text that contains '
.$someVar
.' and some other stuff that is too long to fit on one line';
$var2 = 12;
 
// Valid
$variable = 12;
$var .= 'a very long line of text that contains '
.$someVar
.' and some other stuff that is too long to fit on one line';
$var2 = 12;
 
// Valid
$variable += 12;
$var .= 'a very long line of text that contains '
.$someVar
.' and some other stuff that is too long to fit on one line';
$var2 = 12;
 
// Invalid
$variable = 12;
$var .= 'a very long line of text that contains '
.$someVar
.' and some other stuff that is too long to fit on one line';
$var2 = 12;
 
// Valid
$error = false;
while (list($h, $f) = each($handle)) {
$error = true;
}
 
// Valid
$value = false;
function blah ($value = true) {
$value = false;
if ($value === true) {
$value = false;
}
}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Formatting/DisallowMultipleStatementsUnitTest.php
New file
0,0 → 1,73
<?php
/**
* Unit test class for the DisallowMultipleStatements 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: DisallowMultipleStatementsUnitTest.php,v 1.1 2008/06/24 06:37:54 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the DisallowMultipleStatements 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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Formatting_DisallowMultipleStatementsUnitTest 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,
6 => 1,
7 => 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
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Formatting/DisallowMultipleStatementsUnitTest.inc
New file
0,0 → 1,9
<?php
$y = 2;;
echo $y;
for ($i = 1; $i < $length; $i++) {}
for (; $i < $length; $i++) {}
echo 'x'; echo $y;
$x = 10; echo $y;
$this->wizardid = 10; $this->paint(); echo 'x';
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.js
New file
0,0 → 1,93
 
 
// Valid
var1 = 'var1';
var10 = 'var1';
var100 = 'var1';
var1000 = 'var1';
 
// Invalid
var1 = 'var1';
var10 = 'var1';
var100 = 'var1';
var1000 = 'var1';
 
// Valid
var1 = 'var1';
var10 = 'var1';
 
var100 = 'var1';
var1000 = 'var1';
 
// Invalid
var1 = 'var1';
var10 = 'var1';
 
var100 = 'var1';
var1000 = 'var1';
 
// Valid
var1 += 'var1';
var10 += 'var1';
var100 += 'var1';
var1000 += 'var1';
 
// Invalid
var1 += 'var1';
var10 += 'var1';
var100 += 'var1';
var1000 += 'var1';
 
// Valid
var1 = 'var1';
var10 += 'var1';
var100 = 'var1';
var1000 += 'var1';
 
// Invalid
var1 = 'var1';
var10 += 'var1';
var100 = 'var1';
var1000 += 'var1';
 
// Valid
var1 += 'var1';
var10 += 'var1';
 
var100 += 'var1';
var1000 += 'var1';
 
// Invalid
var1 += 'var1';
var10 += 'var1';
 
var100 += 'var1';
var1000 += 'var1';
 
// Valid
var test = 100;
 
// InValid
var test = 100;
 
commentStart = phpcsFile.findPrevious();
commentEnd = this._phpcsFile;
expected += '...';
 
// Invalid
this.okButton = {};
content = {};
 
var buttonid = [this.id, '-positionFormats-add'].join('');
var buttonWidget = WidgetStore.get(buttonid);
var spinButtonid = [this.id, '-positionFormats-spinButton'].join('');
var spinButtonWidget = WidgetStore.get(spinButtonid);
var position = spinButtonWidget.getValue();
var posForamatsList = WidgetStore.get([self.id, '-positionFormats-list'].join(''));
 
dfx.stripTags = function(content, allowedTags)
{
var match;
var re = 'blah';
};
 
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Formatting/NoSpaceAfterCastUnitTest.php
New file
0,0 → 1,91
<?php
/**
* Unit test class for the NoSpaceAfterCast 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: NoSpaceAfterCastUnitTest.php,v 1.1 2007/06/29 00:57:37 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the NoSpaceAfterCast 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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Formatting_NoSpaceAfterCastUnitTest 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,
7 => 1,
9 => 1,
11 => 1,
13 => 1,
15 => 1,
17 => 1,
19 => 1,
21 => 1,
23 => 1,
25 => 1,
27 => 1,
29 => 1,
31 => 1,
33 => 1,
35 => 1,
37 => 1,
39 => 1,
41 => 1,
43 => 1,
45 => 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
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/WhiteSpace/DisallowTabIndentUnitTest.php
New file
0,0 → 1,92
<?php
/**
* Unit test class for the DisallowTabIndent 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: DisallowTabIndentUnitTest.php,v 1.4 2008/10/28 04:43:57 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the DisallowTabIndent 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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_WhiteSpace_DisallowTabIndentUnitTest 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.
*
* @param string $testFile The name of the file being tested.
*
* @return array(int => int)
*/
public function getErrorList($testFile='DisallowTabIndentUnitTest.inc')
{
switch ($testFile) {
case 'DisallowTabIndentUnitTest.inc':
return array(
5 => 1,
9 => 1,
15 => 1,
);
break;
case 'DisallowTabIndentUnitTest.js':
return array(
3 => 1,
6 => 1,
);
break;
case 'DisallowTabIndentUnitTest.css':
return array(
2 => 1,
);
break;
default:
return array();
break;
}//end switch
 
}//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
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/WhiteSpace/DisallowTabIndentUnitTest.css
New file
0,0 → 1,4
#login-container {
margin-left: -225px;
width: 450px;
}
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/WhiteSpace/DisallowTabIndentUnitTest.inc
New file
0,0 → 1,17
<?php
 
class ExampleClass
{
function exampleFunction() {}
 
}
 
$o = <<<EOF
this is some text
this is some text
EOF;
 
$correctVar = true;
$correctVar = false;
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.php
New file
0,0 → 1,88
<?php
/**
* Unit test class for the ScopeIndent 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: ScopeIndentUnitTest.php,v 1.5 2007/06/07 06:04:30 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ScopeIndent 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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_WhiteSpace_ScopeIndentUnitTest 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(
7 => 1,
10 => 1,
17 => 1,
20 => 1,
24 => 1,
27 => 1,
28 => 1,
58 => 1,
123 => 1,
126 => 1,
224 => 1,
225 => 1,
279 => 1,
280 => 1,
281 => 1,
282 => 1,
283 => 1,
284 => 1,
311 => 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
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/WhiteSpace/DisallowTabIndentUnitTest.js
New file
0,0 → 1,9
var x = {
abc: 1,
zyz: 2,
abc: 5,
mno: {
abc: 4
},
abc: 5
}
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.inc
New file
0,0 → 1,329
<?php
 
class Test
{
function __construct()
{
$this->hello(); // error here
}
 
function hello() // error here
{ // no error here as brackets can be put anywhere in the pear standard
echo 'hello';
}
 
function hello2()
{
if (TRUE) { // error here
echo 'hello'; // no error here as its more than 4 spaces.
} else {
echo 'bye'; // error here
}
 
while (TRUE) {
echo 'hello'; // error here
}// no error here as its handled by another test.
 
do { // error here
echo 'hello'; // error here
} while (TRUE); // no error here as its aligned with the do.
}// no error here as its handled by another test.
 
function hello3()
{
switch ($hello) {
case 'hello':
break;
}
}
 
}
 
?>
<pre>
</head>
<body>
<?php
if ($form->validate()) {
$safe = $form->getSubmitValues();
}
?>
</pre>
<?php
 
class Test2
{
function __construct()
{
// $this->open(); // error here
}
 
public function open()
{
// Some inline stuff that shouldn't error
if (TRUE) echo 'hello';
foreach ($tokens as $token) echo $token;
}
 
/**
* This is a comment 1.
* This is a comment 2.
* This is a comment 3.
* This is a comment 4.
*/
public function close()
{
// All ok.
if (TRUE) {
if (TRUE) {
} else if (FALSE) {
foreach ($tokens as $token) {
switch ($token) {
case '1':
case '2':
if (true) {
if (false) {
if (false) {
if (false) {
echo 'hello';
}
}
}
}
break;
case '5':
break;
}
do {
while (true) {
foreach ($tokens as $token) {
for ($i = 0; $i < $token; $i++) {
echo 'hello';
}
}
}
} while (true);
}
}
}
}
 
/*
This is another c style comment 1.
This is another c style comment 2.
This is another c style comment 3.
This is another c style comment 4.
This is another c style comment 5.
*/
 
/*
*
*
*
*/
 
/**
*/
 
/*
This comment has a newline in it.
 
*/
 
public function read()
{
echo 'hello';
 
// no errors below.
$array = array(
'this',
'that' => array(
'hello',
'hello again' => array(
'hello',
),
),
);
}
}
 
abstract class Test3
{
public function parse()
{
 
foreach ($t as $ndx => $token) {
if (is_array($token)) {
echo 'here';
} else {
$ts[] = array("token" => $token, "value" => '');
 
$last = count($ts) - 1;
 
switch ($token) {
case '(':
 
if ($last >= 3 &&
$ts[0]['token'] != T_CLASS &&
$ts[$last - 2]['token'] == T_OBJECT_OPERATOR &&
$ts[$last - 3]['token'] == T_VARIABLE ) {
 
 
if (true) {
echo 'hello';
}
}
array_push($braces, $token);
break;
}
}
}
}
}
 
public function test()
{
$o = <<<EOF
this is some text
this is some text
this is some text
this is some text
this is some text
this is some text
EOF;
 
return $o;
}
 
if ($a === true || $a === true || $a === true || $a === true ||
$a === true || $a === true || $a === true || $a === true) {
 
echo 'hello';
}
 
if ($true) {
/* First comment line
*
* Comment test here
* Comment test here
*
*/
/* First comment line
*
* Comment test here
* Comment test here
*
this si something */
}
 
function test()
{
/* taken from http://de3.php.net/manual/en/reserved.php */
# $m[] = 'declare';
/* taken from http://de3.php.net/manual/en/reserved.php */
# $m[] = 'declare';
}
 
foreach ($elements as $element) {
if ($something) {
// Do IF.
} else if ($somethingElse) {
// Do ELSE.
}
}
 
if ($condition) {
echo "This is a long
string that spans $numLines lines
without indenting.
";
}
 
if ($condition) {
echo 'This is a long
string that spans nultiple lines
with indenting.
';
}
 
if ($condition) {
echo 'This is a long
string that spans nultiple lines
with indenting.';
}
 
switch ($foo) {
case 1:
switch ($bar) {
default:
echo $string{1};
}
break;
}
 
function temp($foo, $bar) {
switch ($foo) {
case 1:
switch ($bar) {
default:
return $foo;
}
break;
}
}
 
switch ($foo) {
case 1:
switch ($bar) {
default:
if ($something) {
echo $string{1};
} else if ($else) {
switch ($else) {
default:
}
}
}
break;
}
 
switch ($name) {
case "1":
case "2":
case "3":
return true;
}
 
switch ($name) {
case "1":
case "2":
case "3":
default :
return true;
}
 
function myFunction()
{
?>
<dynamic_content>
 
</dynamic_content>
<?php
 
}
 
switch ($name) {
case "1":
switch ($name2) {
case "1":
break;
case "2":
break;
}
break;
case "2":
break;
}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.php
New file
0,0 → 1,82
<?php
/**
* Unit test class for the DuplicateClassName multi-file sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: DuplicateClassNameUnitTest.php,v 1.1 2008/07/25 04:24:10 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the DuplicateClassName multi-file sniff.
*
* A multi-file sniff unit test checks a .1.inc and a .2.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>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Classes_DuplicateClassNameUnitTest 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($testFile='')
{
switch ($testFile) {
case 'DuplicateClassNameUnitTest.1.inc':
return array(
6 => 1,
7 => 1,
);
break;
case 'DuplicateClassNameUnitTest.2.inc':
return array(
2 => 1,
3 => 1,
);
break;
default:
return array();
break;
}//end switch
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.1.inc
New file
0,0 → 1,8
<?php
class MyClass {}
class YourClass {}
interface MyInterface {}
interface YourInterface {}
class MyClass {}
interface MyInterface {}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.2.inc
New file
0,0 → 1,4
<?php
class MyClass {}
interface MyInterface {}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/GenericCodingStandard.php
New file
0,0 → 1,39
<?php
/**
* Generic Coding Standard.
*
* 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: GenericCodingStandard.php,v 1.5 2008/02/01 03:19:54 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_Standards_CodingStandard', true) === false) {
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_CodingStandard not found');
}
 
/**
* Generic Coding Standard.
*
* @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: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_Standards_Generic_GenericCodingStandard extends PHP_CodeSniffer_Standards_CodingStandard
{
 
 
}//end class
 
?>