Subversion Repositories Applications.framework

Compare Revisions

Ignore whitespace Rev 4 → Rev 5

/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/AbstractPatternSniff.php
New file
0,0 → 1,867
<?php
/**
* Processes pattern strings and checks that the code conforms to the pattern.
*
* 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: AbstractPatternSniff.php,v 1.26 2008/12/11 06:08:10 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_Standards_IncorrectPatternException', true) === false) {
$error = 'Class PHP_CodeSniffer_Standards_IncorrectPatternException not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
/**
* Processes pattern strings and checks that the code conforms to the pattern.
*
* This test essentially checks that code is correctly formatted with whitespace.
*
* @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
*/
abstract class PHP_CodeSniffer_Standards_AbstractPatternSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* The parsed patterns array.
*
* @var array
*/
private $_parsedPatterns = array();
 
/**
* Tokens that wish this sniff wishes to process outside of the patterns.
*
* @var array(int)
* @see registerSupplementary()
* @see processSupplementary()
*/
private $_supplementaryTokens = array();
 
/**
* If true, comments will be ignored if they are found in the code.
*
* @var boolean
*/
private $_ignoreComments = false;
 
/**
* Positions in the stack where errors have occured.
*
* @var array()
*/
private $_errorPos = array();
 
 
/**
* Constructs a PHP_CodeSniffer_Standards_AbstractPatternSniff.
*
* @param boolean $ignoreComments If true, comments will be ignored.
*/
public function __construct($ignoreComments=false)
{
$this->_ignoreComments = $ignoreComments;
$this->_supplementaryTokens = $this->registerSupplementary();
 
}//end __construct()
 
 
/**
* Registers the tokens to listen to.
*
* Classes extending <i>AbstractPatternTest</i> should implement the
* <i>getPatterns()</i> method to register the patterns they wish to test.
*
* @return array(int)
* @see process()
*/
public final function register()
{
$listenTypes = array();
$patterns = $this->getPatterns();
 
foreach ($patterns as $pattern) {
 
$parsedPattern = $this->_parse($pattern);
 
// Find a token position in the pattern that we can use for a listener
// token.
$pos = $this->_getListenerTokenPos($parsedPattern);
$tokenType = $parsedPattern[$pos]['token'];
$listenTypes[] = $tokenType;
 
$patternArray = array(
'listen_pos' => $pos,
'pattern' => $parsedPattern,
'pattern_code' => $pattern,
);
 
if (isset($this->_parsedPatterns[$tokenType]) === false) {
$this->_parsedPatterns[$tokenType] = array();
}
 
$this->_parsedPatterns[$tokenType][] = $patternArray;
 
}//end foreach
 
return array_unique(array_merge($listenTypes, $this->_supplementaryTokens));
 
}//end register()
 
 
/**
* Returns the token types that the specified pattern is checking for.
*
* Returned array is in the format:
* <code>
* array(
* T_WHITESPACE => 0, // 0 is the position where the T_WHITESPACE token
* // should occur in the pattern.
* );
* </code>
*
* @param array $pattern The parsed pattern to find the acquire the token
* types from.
*
* @return array(int => int)
*/
private function _getPatternTokenTypes($pattern)
{
$tokenTypes = array();
foreach ($pattern as $pos => $patternInfo) {
if ($patternInfo['type'] === 'token') {
if (isset($tokenTypes[$patternInfo['token']]) === false) {
$tokenTypes[$patternInfo['token']] = $pos;
}
}
}
 
return $tokenTypes;
 
}//end _getPatternTokenTypes()
 
 
/**
* Returns the position in the pattern that this test should register as
* a listener for the pattern.
*
* @param array $pattern The pattern to acquire the listener for.
*
* @return int The postition in the pattern that this test should register
* as the listener.
* @throws PHP_CodeSniffer_Exception If we could not determine a token
* to listen for.
*/
private function _getListenerTokenPos($pattern)
{
$tokenTypes = $this->_getPatternTokenTypes($pattern);
$tokenCodes = array_keys($tokenTypes);
$token = PHP_CodeSniffer_Tokens::getHighestWeightedToken($tokenCodes);
 
// If we could not get a token.
if ($token === false) {
$error = 'Could not determine a token to listen for';
throw new PHP_CodeSniffer_Exception($error);
}
 
return $tokenTypes[$token];
 
}//end _getListenerTokenPos()
 
 
/**
* Processes the test.
*
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where the
* token occured.
* @param int $stackPtr The postion in the tokens stack
* where the listening token type was
* found.
*
* @return void
* @see register()
*/
public final function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
if (in_array($tokens[$stackPtr]['code'], $this->_supplementaryTokens) === true) {
$this->processSupplementary($phpcsFile, $stackPtr);
}
 
$type = $tokens[$stackPtr]['code'];
 
// If the type is not set, then it must have been a token registered
// with registerSupplementary().
if (isset($this->_parsedPatterns[$type]) === false) {
return;
}
 
$allErrors = array();
 
// Loop over each pattern that is listening to the current token type
// that we are processing.
foreach ($this->_parsedPatterns[$type] as $patternInfo) {
 
// If processPattern returns false, then the pattern that we are
// checking the code with must not be design to check that code.
$errors = $this->processPattern($patternInfo, $phpcsFile, $stackPtr);
if ($errors === false) {
// The pattern didn't match.
continue;
} else if (empty($errors) === true) {
// The pattern matched, but there were no errors.
break;
}
 
foreach ($errors as $stackPtr => $error) {
if (isset($this->_errorPos[$stackPtr]) === false) {
$this->_errorPos[$stackPtr] = true;
$allErrors[$stackPtr] = $error;
}
}
}
 
foreach ($allErrors as $stackPtr => $error) {
$phpcsFile->addError($error, $stackPtr);
}
 
}//end process()
 
 
/**
* Processes the pattern and verifies the code at $stackPtr.
*
* @param array $patternInfo Information about the pattern used
* for checking, which includes are
* parsed token representation of the
* pattern.
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where the
* token occured.
* @param int $stackPtr The postion in the tokens stack where
* the listening token type was found.
*
* @return array(errors)
*/
protected function processPattern(
$patternInfo,
PHP_CodeSniffer_File $phpcsFile,
$stackPtr
) {
$tokens = $phpcsFile->getTokens();
$pattern = $patternInfo['pattern'];
$patternCode = $patternInfo['pattern_code'];
$errors = array();
$found = '';
 
$ignoreTokens = array(T_WHITESPACE);
 
if ($this->_ignoreComments === true) {
$ignoreTokens
= array_merge($ignoreTokens, PHP_CodeSniffer_Tokens::$commentTokens);
}
 
$origStackPtr = $stackPtr;
$hasError = false;
 
if ($patternInfo['listen_pos'] > 0) {
$stackPtr--;
 
for ($i = ($patternInfo['listen_pos'] - 1); $i >= 0; $i--) {
 
if ($pattern[$i]['type'] === 'token') {
 
if ($pattern[$i]['token'] === T_WHITESPACE) {
 
if ($tokens[$stackPtr]['code'] === T_WHITESPACE) {
$found = $tokens[$stackPtr]['content'].$found;
}
 
// Only check the size of the whitespace if this is not
// not the first token. We don't care about the size of
// leading whitespace, just that there is some.
if ($i !== 0) {
if ($tokens[$stackPtr]['content'] !== $pattern[$i]['value']) {
$hasError = true;
}
}
 
} else {
 
// Check to see if this important token is the same as the
// previous important token in the pattern. If it is not,
// then the pattern cannot be for this piece of code.
$prev = $phpcsFile->findPrevious(
$ignoreTokens,
$stackPtr,
null,
true
);
 
if ($prev === false
|| $tokens[$prev]['code'] !== $pattern[$i]['token']
) {
return false;
}
 
// If we skipped past some whitespace tokens, then add them
// to the found string.
if (($stackPtr - $prev) > 1) {
for ($j = ($stackPtr - 1); $j > $prev; $j--) {
$found = $tokens[$j]['content'].$found;
}
}
 
$found = $tokens[$prev]['content'].$found;
 
if (isset($pattern[($i - 1)]) === true
&& $pattern[($i - 1)]['type'] === 'skip'
) {
$stackPtr = $prev;
} else {
$stackPtr = ($prev - 1);
}
 
}//end if
} else if ($pattern[$i]['type'] === 'skip') {
// Skip to next piece of relevant code.
if ($pattern[$i]['to'] === 'parenthesis_closer') {
$to = 'parenthesis_opener';
} else {
$to = 'scope_opener';
}
 
// Find the previous opener.
$next = $phpcsFile->findPrevious(
$ignoreTokens,
$stackPtr,
null,
true
);
 
if ($next === false || isset($tokens[$next][$to]) === false) {
// If there was not opener, then we must be
// using the wrong pattern.
return false;
}
 
if ($to === 'parenthesis_opener') {
$found = '{'.$found;
} else {
$found = '('.$found;
}
 
$found = '...'.$found;
 
// Skip to the opening token.
$stackPtr = ($tokens[$next][$to] - 1);
} else if ($pattern[$i]['type'] === 'string') {
$found = 'abc';
} else if ($pattern[$i]['type'] === 'newline') {
$found = 'EOL';
}//end if
}//end for
}//end if
 
$stackPtr = $origStackPtr;
$lastAddedStackPtr = null;
$patternLen = count($pattern);
 
for ($i = $patternInfo['listen_pos']; $i < $patternLen; $i++) {
if ($pattern[$i]['type'] === 'token') {
if ($pattern[$i]['token'] === T_WHITESPACE) {
if ($this->_ignoreComments === true) {
// If we are ignoring comments, check to see if this current
// token is a comment. If so skip it.
if (in_array($tokens[$stackPtr]['code'], PHP_CodeSniffer_Tokens::$commentTokens) === true) {
continue;
}
 
// If the next token is a comment, the we need to skip the
// current token as we should allow a space before a
// comment for readability.
if (in_array($tokens[($stackPtr + 1)]['code'], PHP_CodeSniffer_Tokens::$commentTokens) === true) {
continue;
}
}
 
$tokenContent = '';
if ($tokens[$stackPtr]['code'] === T_WHITESPACE) {
if (isset($pattern[($i + 1)]) === false) {
// This is the last token in the pattern, so just compare
// the next token of content.
$tokenContent = $tokens[$stackPtr]['content'];
} else {
// Get all the whitespace to the next token.
$next = $phpcsFile->findNext(
PHP_CodeSniffer_Tokens::$emptyTokens,
$stackPtr,
null,
true
);
 
$tokenContent = $phpcsFile->getTokensAsString(
$stackPtr,
($next - $stackPtr)
);
 
$lastAddedStackPtr = $stackPtr;
$stackPtr = $next;
}
 
if ($stackPtr !== $lastAddedStackPtr) {
$found .= $tokenContent;
}
} else {
if ($stackPtr !== $lastAddedStackPtr) {
$found .= $tokens[$stackPtr]['content'];
$lastAddedStackPtr = $stackPtr;
}
}//end if
 
if (isset($pattern[($i + 1)]) === true
&& $pattern[($i + 1)]['type'] === 'skip'
) {
// The next token is a skip token, so we just need to make
// sure the whitespace we found has *at least* the
// whitespace required.
if (strpos($tokenContent, $pattern[$i]['value']) !== 0) {
$hasError = true;
}
} else {
if ($tokenContent !== $pattern[$i]['value']) {
$hasError = true;
}
}
 
} else {
// Check to see if this important token is the same as the
// next important token in the pattern. If it is not, then
// the pattern cannot be for this piece of code.
$next = $phpcsFile->findNext(
$ignoreTokens,
$stackPtr,
null,
true
);
 
if ($next === false
|| $tokens[$next]['code'] !== $pattern[$i]['token']
) {
return false;
}
 
// If we skipped past some whitespace tokens, then add them
// to the found string.
if (($next - $stackPtr) > 0) {
$hasComment = false;
for ($j = $stackPtr; $j < $next; $j++) {
$found .= $tokens[$j]['content'];
if (in_array($tokens[$j]['code'], PHP_CodeSniffer_Tokens::$commentTokens) === true) {
$hasComment = true;
}
}
 
// If we are not ignoring comments, this additional
// whitespace or comment is not allowed. If we are
// ignoring comments, there needs to be at least one
// comment for this to be allowed.
if ($this->_ignoreComments === false
|| ($this->_ignoreComments === true
&& $hasComment === false)
) {
$hasError = true;
}
 
// Even when ignoring comments, we are not allowed to include
// newlines without the pattern specifying them, so
// everything should be on the same line.
if ($tokens[$next]['line'] !== $tokens[$stackPtr]['line']) {
$hasError = true;
}
}//end if
 
if ($next !== $lastAddedStackPtr) {
$found .= $tokens[$next]['content'];
$lastAddedStackPtr = $next;
}
 
if (isset($pattern[($i + 1)]) === true
&& $pattern[($i + 1)]['type'] === 'skip'
) {
$stackPtr = $next;
} else {
$stackPtr = ($next + 1);
}
}//end if
 
} else if ($pattern[$i]['type'] === 'skip') {
if ($pattern[$i]['to'] === 'unknown') {
$next = $phpcsFile->findNext(
$pattern[($i + 1)]['token'],
$stackPtr
);
 
if ($next === false) {
// Couldn't find the next token, sowe we must
// be using the wrong pattern.
return false;
}
 
$found .= '...';
$stackPtr = $next;
} else {
// Find the previous opener.
$next = $phpcsFile->findPrevious(
PHP_CodeSniffer_Tokens::$blockOpeners,
$stackPtr
);
 
if ($next === false
|| isset($tokens[$next][$pattern[$i]['to']]) === false
) {
// If there was not opener, then we must
// be using the wrong pattern.
return false;
}
 
$found .= '...';
if ($pattern[$i]['to'] === 'parenthesis_closer') {
$found .= ')';
} else {
$found .= '}';
}
 
// Skip to the closing token.
$stackPtr = ($tokens[$next][$pattern[$i]['to']] + 1);
}
} else if ($pattern[$i]['type'] === 'string') {
if ($tokens[$stackPtr]['code'] !== T_STRING) {
$hasError = true;
}
 
if ($stackPtr !== $lastAddedStackPtr) {
$found .= 'abc';
$lastAddedStackPtr = $stackPtr;
}
 
$stackPtr++;
} else if ($pattern[$i]['type'] === 'newline') {
// Find the next token that contains a newline character.
$newline = 0;
for ($j = $stackPtr; $j < $phpcsFile->numTokens; $j++) {
if (strpos($tokens[$j]['content'], $phpcsFile->eolChar) !== false) {
$newline = $j;
break;
}
}
 
if ($newline === 0) {
// We didn't find a newline character in the rest of the file.
$next = ($phpcsFile->numTokens - 1);
$hasError = true;
} else {
if ($this->_ignoreComments === false) {
// The newline character cannot be part of a comment.
if (in_array($tokens[$newline]['code'], PHP_CodeSniffer_Tokens::$commentTokens) === true) {
$hasError = true;
}
}
 
if ($newline === $stackPtr) {
$next = ($stackPtr + 1);
} else {
// Check that there were no significant tokens that we
// skipped over to find our newline character.
$next = $phpcsFile->findNext(
$ignoreTokens,
$stackPtr,
null,
true
);
 
if ($next < $newline) {
// We skipped a non-ignored token.
$hasError = true;
} else {
$next = ($newline + 1);
}
}
}//end if
 
if ($stackPtr !== $lastAddedStackPtr) {
$found .= $phpcsFile->getTokensAsString(
$stackPtr,
($next - $stackPtr)
);
 
$diff = ($next - $stackPtr);
$lastAddedStackPtr = ($next - 1);
}
 
$stackPtr = $next;
}//end if
}//end for
 
if ($hasError === true) {
$error = $this->prepareError($found, $patternCode);
$errors[$origStackPtr] = $error;
}
 
return $errors;
 
}//end processPattern()
 
 
/**
* Prepares an error for the specified patternCode.
*
* @param string $found The actual found string in the code.
* @param string $patternCode The expected pattern code.
*
* @return string The error message.
*/
protected function prepareError($found, $patternCode)
{
$found = str_replace("\r\n", '\n', $found);
$found = str_replace("\n", '\n', $found);
$found = str_replace("\r", '\n', $found);
$found = str_replace('EOL', '\n', $found);
$expected = str_replace('EOL', '\n', $patternCode);
 
$error = "Expected \"$expected\"; found \"$found\"";
 
return $error;
 
}//end prepareError()
 
 
/**
* Returns the patterns that should be checked.
*
* @return array(string)
*/
protected abstract function getPatterns();
 
 
/**
* Registers any supplementary tokens that this test might wish to process.
*
* A sniff may wish to register supplementary tests when it wishes to group
* an arbitary validation that cannot be performed using a pattern, with
* other pattern tests.
*
* @return array(int)
* @see processSupplementary()
*/
protected function registerSupplementary()
{
return array();
 
}//end registerSupplementary()
 
 
/**
* Processes any tokens registered with registerSupplementary().
*
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where to
* process the skip.
* @param int $stackPtr The position in the tokens stack to
* process.
*
* @return void
* @see registerSupplementary()
*/
protected function processSupplementary(
PHP_CodeSniffer_File $phpcsFile,
$stackPtr
) {
return;
 
}//end processSupplementary()
 
 
/**
* Parses a pattern string into an array of pattern steps.
*
* @param string $pattern The pattern to parse.
*
* @return array The parsed pattern array.
* @see _createSkipPattern()
* @see _createTokenPattern()
*/
private function _parse($pattern)
{
$patterns = array();
$length = strlen($pattern);
$lastToken = 0;
$firstToken = 0;
 
for ($i = 0; $i < $length; $i++) {
 
$specialPattern = false;
$isLastChar = ($i === ($length - 1));
$oldFirstToken = $firstToken;
 
if (substr($pattern, $i, 3) === '...') {
// It's a skip pattern. The skip pattern requires the
// content of the token in the "from" position and the token
// to skip to.
$specialPattern = $this->_createSkipPattern($pattern, ($i - 1));
$lastToken = ($i - $firstToken);
$firstToken = ($i + 3);
$i = ($i + 3);
 
if ($specialPattern['to'] !== 'unknown') {
$firstToken++;
}
} else if (substr($pattern, $i, 3) === 'abc') {
$specialPattern = array('type' => 'string');
$lastToken = ($i - $firstToken);
$firstToken = ($i + 3);
$i = ($i + 2);
} else if (substr($pattern, $i, 3) === 'EOL') {
$specialPattern = array('type' => 'newline');
$lastToken = ($i - $firstToken);
$firstToken = ($i + 3);
$i = ($i + 2);
}
 
if ($specialPattern !== false || $isLastChar === true) {
 
// If we are at the end of the string, don't worry about a limit.
if ($isLastChar === true) {
// Get the string from the end of the last skip pattern, if any,
// to the end of the pattern string.
$str = substr($pattern, $oldFirstToken);
} else {
// Get the string from the end of the last special pattern,
// if any, to the start of this special pattern.
$str = substr($pattern, $oldFirstToken, $lastToken);
}
 
$tokenPatterns = $this->_createTokenPattern($str);
 
// Make sure we don't skip the last token.
if ($isLastChar === false && $i === ($length - 1)) {
$i--;
}
 
foreach ($tokenPatterns as $tokenPattern) {
$patterns[] = $tokenPattern;
}
}//end if
 
// Add the skip pattern *after* we have processed
// all the tokens from the end of the last skip pattern
// to the start of this skip pattern.
if ($specialPattern !== false) {
$patterns[] = $specialPattern;
}
 
}//end for
 
return $patterns;
 
}//end _parse()
 
 
/**
* Creates a skip pattern.
*
* @param string $pattern The pattern being parsed.
* @param string $from The token content that the skip pattern starts from.
*
* @return array The pattern step.
* @see _createTokenPattern()
* @see _parse()
*/
private function _createSkipPattern($pattern, $from)
{
$skip = array('type' => 'skip');
 
$nestedParenthesis = 0;
for ($start = $from; $start >= 0; $start--) {
switch ($pattern[$start]) {
case '(':
if ($nestedParenthesis === 0) {
$skip['to'] = 'parenthesis_closer';
}
 
$nestedParenthesis--;
break;
case '{':
$skip['to'] = 'scope_closer';
break;
case ')':
$nestedParenthesis++;
break;
}
 
if (isset($skip['to']) === true) {
break;
}
}
 
if (isset($skip['to']) === false) {
$skip['to'] = 'unknown';
}
 
return $skip;
 
}//end _createSkipPattern()
 
 
/**
* Creates a token pattern.
*
* @param string $str The tokens string that the pattern should match.
*
* @return array The pattern step.
* @see _createSkipPattern()
* @see _parse()
*/
private function _createTokenPattern($str)
{
// Don't add a space after the closing php tag as it will add a new
// whitespace token.
$tokens = token_get_all('<?php '.$str.'?>');
 
// Remove the <?php tag from the front and the end php tag from the back.
$tokens = array_slice($tokens, 1, (count($tokens) - 2));
 
foreach ($tokens as &$token) {
$token = PHP_CodeSniffer::standardiseToken($token);
}
 
$patterns = array();
foreach ($tokens as $patternInfo) {
$patterns[] = array(
'type' => 'token',
'token' => $patternInfo['code'],
'value' => $patternInfo['content'],
);
}
 
return $patterns;
 
}//end _createTokenPattern()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PHPCS/PHPCSCodingStandard.php
New file
0,0 → 1,85
<?php
/**
* PHP_CodeSniffer 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: PHPCSCodingStandard.php,v 1.10 2008/12/12 04:06:01 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');
}
 
/**
* PHP_CodeSniffer 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_PHPCS_PHPCSCodingStandard extends PHP_CodeSniffer_Standards_CodingStandard
{
 
 
/**
* Return a list of external sniffs to include with this standard.
*
* The PHP_CodeSniffer standard combines the PEAR and Squiz standards
* but removes some sniffs from the Squiz standard that clash with
* those in the PEAR standard.
*
* @return array
*/
public function getIncludedSniffs()
{
return array(
'PEAR',
'Squiz',
);
 
}//end getIncludedSniffs()
 
 
/**
* Return a list of external sniffs to exclude from this standard.
*
* The PHP_CodeSniffer standard combines the PEAR and Squiz standards
* but removes some sniffs from the Squiz standard that clash with
* those in the PEAR standard.
*
* @return array
*/
public function getExcludedSniffs()
{
return array(
'Squiz/Sniffs/Classes/ClassFileNameSniff.php',
'Squiz/Sniffs/Classes/ValidClassNameSniff.php',
'Squiz/Sniffs/Commenting/ClassCommentSniff.php',
'Squiz/Sniffs/Commenting/FileCommentSniff.php',
'Squiz/Sniffs/Commenting/FunctionCommentSniff.php',
'Squiz/Sniffs/Commenting/VariableCommentSniff.php',
'Squiz/Sniffs/ControlStructures/SwitchDeclarationSniff.php',
'Squiz/Sniffs/Files/FileExtensionSniff.php',
'Squiz/Sniffs/Files/LineLengthSniff.php',
'Squiz/Sniffs/NamingConventions/ConstantCaseSniff.php',
'Squiz/Sniffs/WhiteSpace/ScopeIndentSniff.php',
);
 
}//end getExcludedSniffs()
 
 
}//end class
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/AbstractVariableSniff.php
New file
0,0 → 1,236
<?php
/**
* A class to find T_VARIABLE tokens.
*
* 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: AbstractVariableSniff.php,v 1.15 2008/12/01 05:41:28 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);
}
 
/**
* A class to find T_VARIABLE tokens.
*
* This class can distingush between normal T_VARIABLE tokens, and those tokens
* that represent class members. If a class member is encountered, then then
* processMemberVar method is called so the extending class can process it. If
* the token is found to be a normal T_VARIABLE token, then processVariable is
* called.
*
* @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
*/
abstract class PHP_CodeSniffer_Standards_AbstractVariableSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff
{
 
/**
* The end token of the current function that we are in.
*
* @var int
*/
private $_endFunction = -1;
 
/**
* true if a function is currently open.
*
* @var boolean
*/
private $_functionOpen = false;
 
/**
* The current PHP_CodeSniffer file that we are processing.
*
* @var PHP_CodeSniffer_File
*/
protected $currentFile = null;
 
 
/**
* Constructs an AbstractVariableTest.
*/
public function __construct()
{
$listen = array(
T_CLASS,
T_INTERFACE,
);
 
$scopes = array(
T_FUNCTION,
T_VARIABLE,
T_DOUBLE_QUOTED_STRING,
);
 
parent::__construct($listen, $scopes, true);
 
}//end __construct()
 
 
/**
* Processes the token in the specified PHP_CodeSniffer_File.
*
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this
* token was found.
* @param int $stackPtr The position where the token was found.
* @param array $currScope The current scope opener token.
*
* @return void
*/
protected final function processTokenWithinScope(
PHP_CodeSniffer_File $phpcsFile,
$stackPtr,
$currScope
) {
if ($this->currentFile !== $phpcsFile) {
$this->currentFile = $phpcsFile;
$this->_functionOpen = false;
$this->_endFunction = -1;
}
 
$tokens = $phpcsFile->getTokens();
 
if ($stackPtr > $this->_endFunction) {
$this->_functionOpen = false;
}
 
if ($tokens[$stackPtr]['code'] === T_FUNCTION
&& $this->_functionOpen === false
) {
$this->_functionOpen = true;
 
$methodProps = $phpcsFile->getMethodProperties($stackPtr);
 
// If the function is abstract, or is in an interface,
// then set the end of the function to it's closing semicolon.
if ($methodProps['is_abstract'] === true
|| $tokens[$currScope]['code'] === T_INTERFACE
) {
$this->_endFunction
= $phpcsFile->findNext(array(T_SEMICOLON), $stackPtr);
} else {
if (isset($tokens[$stackPtr]['scope_closer']) === false) {
$error = 'Possible parse error: non-abstract method defined as abstract';
$phpcsFile->addWarning($error, $stackPtr);
return;
}
 
$this->_endFunction = $tokens[$stackPtr]['scope_closer'];
}
 
}
 
if ($this->_functionOpen === true) {
if ($tokens[$stackPtr]['code'] === T_VARIABLE) {
$this->processVariable($phpcsFile, $stackPtr);
} else if ($tokens[$stackPtr]['code'] === T_DOUBLE_QUOTED_STRING) {
// Check to see if this string has a variable in it.
$pattern = '|[^\\\]\$[a-zA-Z0-9_]+|';
if (preg_match($pattern, $tokens[$stackPtr]['content']) !== 0) {
$this->processVariableInString($phpcsFile, $stackPtr);
}
}
 
return;
} else {
// What if we assign a member variable to another?
// ie. private $_count = $this->_otherCount + 1;.
$this->processMemberVar($phpcsFile, $stackPtr);
}
 
}//end processTokenWithinScope()
 
 
/**
* Processes the token outside the scope in the file.
*
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this
* token was found.
* @param int $stackPtr The position where the token was found.
*
* @return void
*/
protected final function processTokenOutsideScope(
PHP_CodeSniffer_File $phpcsFile,
$stackPtr
) {
$tokens = $phpcsFile->getTokens();
// These variables are not member vars.
if ($tokens[$stackPtr]['code'] === T_VARIABLE) {
$this->processVariable($phpcsFile, $stackPtr);
} else {
$this->processVariableInString($phpcsFile, $stackPtr);
}
 
}//end processTokenOutsideScope()
 
 
/**
* Called to process class member vars.
*
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this
* token was found.
* @param int $stackPtr The position where the token was found.
*
* @return void
*/
abstract protected function processMemberVar(
PHP_CodeSniffer_File $phpcsFile,
$stackPtr
);
 
 
/**
* Called to process normal member vars.
*
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this
* token was found.
* @param int $stackPtr The position where the token was found.
*
* @return void
*/
abstract protected function processVariable(
PHP_CodeSniffer_File $phpcsFile,
$stackPtr
);
 
 
/**
* Called to process variables found in duoble quoted strings.
*
* Note that there may be more than one variable in the string, which will
* result only in one call for the string.
*
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this
* token was found.
* @param int $stackPtr The position where the double quoted
* string was found.
*
* @return void
*/
abstract protected function processVariableInString(
PHP_CodeSniffer_File
$phpcsFile,
$stackPtr
);
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/PEARCodingStandard.php
New file
0,0 → 1,57
<?php
/**
* PEAR 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: PEARCodingStandard.php,v 1.8 2008/11/17 05:04:07 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');
}
 
/**
* PEAR 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_PEAR_PEARCodingStandard extends PHP_CodeSniffer_Standards_CodingStandard
{
 
 
/**
* Return a list of external sniffs to include with this standard.
*
* The PEAR standard uses some generic sniffs.
*
* @return array
*/
public function getIncludedSniffs()
{
return array(
'Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php',
'Generic/Sniffs/PHP/LowerCaseConstantSniff.php',
'Generic/Sniffs/PHP/DisallowShortOpenTagSniff.php',
'Generic/Sniffs/WhiteSpace/DisallowTabIndentSniff.php',
);
 
}//end getIncludedSniffs()
 
 
}//end class
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Functions/FunctionCallArgumentSpacingUnitTest.php
New file
0,0 → 1,80
<?php
/**
* Unit test class for the FunctionCallArgumentSpacing 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: FunctionCallArgumentSpacingUnitTest.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 FunctionCallArgumentSpacing 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 PEAR_Tests_Functions_FunctionCallArgumentSpacingUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
5 => 1,
6 => 1,
7 => 2,
8 => 1,
11 => 2,
12 => 2,
13 => 3,
42 => 3,
43 => 3,
45 => 1,
46 => 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/PEAR/Tests/Functions/FunctionCallArgumentSpacingUnitTest.inc
New file
0,0 → 1,54
<?php
 
$result = myFunction();
$result = myFunction($arg1, $arg2);
$result = myFunction($arg1,$arg2);
$result = myFunction($arg1 , $arg2);
$result = myFunction($arg1 , $arg2);
$result = myFunction($arg1, $arg2, $arg3,$arg4, $arg5);
$result = myFunction($arg1, $arg2, $arg3, $arg4, $arg5);
$result = myFunction($arg1, $arg2 = array());
$result = myFunction($arg1 , $arg2 =array());
$result = myFunction($arg1 , $arg2= array());
$result = myFunction($arg1 , $arg2=array());
 
$result = myFunction($arg1,
$arg2 = array(),
$arg3,
$arg4,
$arg5);
 
throw new Exception("This is some massive string for a message",
$cause);
 
// Function definitions are ignored
function myFunction($arg1,$arg2)
{
}
 
function myFunction ($arg1,$arg2)
{
}
 
function myFunction($arg1=1,$arg2=2)
{
}
 
 
function myFunction($arg1 = 1,$arg2 = 2)
{
}
 
$key = array_search($this->getArray($one, $two,$three),$this->arrayMap);
$this->error($obj->getCode(),$obj->getMessage(),$obj->getFile(),$obj->getLine());
 
make_foo($string /*the string*/ , true /*test*/);
make_foo($string/*the string*/ , /*test*/ true);
make_foo($string /*the string*/, /*test*/ true);
 
class MyClass {
function myFunction() {
blah($foo, "{{$config['host']}}", "{$config}", "hi there{}{}{{{}{}{}}");
}
}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.php
New file
0,0 → 1,78
<?php
/**
* Unit test class for the FunctionDeclaration sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: FunctionDeclarationUnitTest.php,v 1.2 2008/12/01 05:45:50 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the FunctionDeclaration sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Tests_Functions_FunctionDeclarationUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
3 => 1,
4 => 1,
5 => 1,
9 => 1,
10 => 1,
11 => 1,
14 => 1,
27 => 1,
46 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc
New file
0,0 → 1,50
<?php
public function someFunctionWithAVeryLongName($firstParameter='something',
$secondParameter='booooo', $third=null, $fourthParameter=false,
$fifthParameter=123.12, $sixthParam=true
){
}
 
function someFunctionWithAVeryLongName2($firstParameter='something',
$secondParameter='booooo', $third=null, $fourthParameter=false,
$fifthParameter=123.12, $sixthParam=true
) {
}
 
function blah() {
}
 
function blah()
{
}
 
class MyClass
{
 
public function someFunctionWithAVeryLongName($firstParameter='something',
$secondParameter='booooo', $third=null, $fourthParameter=false,
$fifthParameter=123.12, $sixthParam=true
) /** w00t */ {
}
 
public function someFunctionWithAVeryLongName2(
$firstParameter='something', $secondParameter='booooo', $third=null
) {
}
 
protected abstract function processTokenWithinScope(
PHP_CodeSniffer_File $phpcsFile,
$stackPtr,
$currScope
);
 
}
 
function getInstalledStandards(
$includeGeneric=false,
$standardsDir=''
)
{
}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Functions/ValidDefaultValueUnitTest.php
New file
0,0 → 1,75
<?php
/**
* Unit test class for the ValidDefaultValue 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: ValidDefaultValueUnitTest.php,v 1.1 2006/12/27 23:19:18 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ValidDefaultValue 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 PEAR_Tests_Functions_ValidDefaultValueUnitTest 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(
29 => 1,
34 => 1,
39 => 1,
71 => 1,
76 => 1,
81 => 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/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.php
New file
0,0 → 1,83
<?php
/**
* Unit test class for the FunctionCallSignature 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: FunctionCallSignatureUnitTest.php,v 1.4 2008/12/05 02:45:08 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the FunctionCallSignature 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 PEAR_Tests_Functions_FunctionCallSignatureUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
5 => 1,
6 => 1,
7 => 1,
8 => 1,
9 => 2,
10 => 3,
17 => 1,
18 => 1,
31 => 1,
34 => 1,
57 => 1,
59 => 1,
63 => 1,
64 => 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/PEAR/Tests/Functions/ValidDefaultValueUnitTest.inc
New file
0,0 → 1,86
<?php
 
// No args.
function myFunction()
{
}
 
// No default args.
function myFunction($arg1)
{
}
 
// Valid
function myFunction($arg1, $arg2='hello')
{
}
 
// Valid with lots of args
function myFunction($arg1, $arg2, $arg3, $arg4='hello', $arg5=array(), $arg6='hello')
{
}
 
// Valid type hints
function myFunction(array $arg1, array $arg2=array())
{
}
 
// Invalid
function myFunction($arg2='hello', $arg1)
{
}
 
// Invalid with lots of args
function myFunction($arg1, $arg2, $arg3, $arg4='hello', $arg5, $arg6='hello')
{
}
 
// Invalid type hints
function myFunction(array $arg2=array(), array $arg1)
{
}
 
class myClass()
{
// No args.
function myFunction()
{
}
 
// No default args.
function myFunction($arg1)
{
}
 
// Valid
function myFunction($arg1, $arg2='hello')
{
}
 
// Valid with lots of args
function myFunction($arg1, $arg2, $arg3, $arg4='hello', $arg5=array(), $arg6='hello')
{
}
 
// Valid type hints
function myFunction(array $arg1, array $arg2=array())
{
}
 
// Invalid
function myFunction($arg2='hello', $arg1)
{
}
 
// Invalid with lots of args
function myFunction($arg1, $arg2, $arg3, $arg4='hello', $arg5, $arg6='hello')
{
}
 
// Invalid type hints
function myFunction(array $arg2=array(), array $arg1)
{
}
}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc
New file
0,0 → 1,65
<?php
 
test();
test($arg, $arg2);
test ();
test( );
test() ;
test( $arg);
test( $arg );
test ( $arg );
 
if (is_array($arg) === true) {
 
}
 
$something = get($arg1, $arg2);
$something = get($arg1, $arg2) ;
$something = get($arg1, $arg2) ;
 
// No errors as this test only checks for function calls.
class TestClass extends MyClass
{
 
const const1 = 'hello';
const CONST2 = 'hello';
 
public function test () { }
}
 
make_foo($string/*the string*/, true/*test*/);
make_foo($string/*the string*/, true/*test*/ );
make_foo($string /*the string*/, true /*test*/);
make_foo(/*the string*/$string, /*test*/true);
make_foo( /*the string*/$string, /*test*/true);
 
// No errors should be throw here because
// this is not a function call per se.
throw new Exception(
'Exception text'
);
 
// Or here.
$obj = new TestClass( );
 
// Heredocs dont need to be indented.
method_call(
<<<EOH
Anyone want to recomment parse errors?
 
EOH
);
 
fputs(
STDOUT,
'Examples:
$ {$app} --all
$ {$app} --all');
 
fputs(STDOUT,
"Examples:
$ {$app} --all
$ {$app} --all",
$something
);
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Formatting/MultiLineAssignmentUnitTest.php
New file
0,0 → 1,70
<?php
/**
* Unit test class for the MultiLineAssignment 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: MultiLineAssignmentUnitTest.php,v 1.1 2008/11/17 05:59:24 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the MultiLineAssignment 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 PEAR_Tests_Formatting_MultiLineAssignmentUnitTest 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,
6 => 1,
8 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Formatting/MultiLineAssignmentUnitTest.inc
New file
0,0 → 1,22
<?php
$GLOBALS['TSFE']->additionalHeaderData[$this->strApplicationName]
= $this->xajax->getJavascript(t3lib_extMgm::siteRelPath('nr_xajax'));
 
$GLOBALS['TSFE']->additionalHeaderData[$this->strApplicationName]
= $this->xajax->getJavascript(t3lib_extMgm::siteRelPath('nr_xajax'));
 
$GLOBALS['TSFE']->additionalHeaderData[$this->strApplicationName] =
$this->xajax->getJavascript(t3lib_extMgm::siteRelPath('nr_xajax'));
 
$GLOBALS['TSFE']->additionalHeaderData[$this->strApplicationName]
= $this->xajax->getJavascript(t3lib_extMgm::siteRelPath('nr_xajax'));
$GLOBALS['TSFE']->additionalHeaderData[$this->strApplicationName] = 'boo'
 
$var='string';
 
function getInstalledStandards(
$includeGeneric=false,
$standardsDir=''
) {
}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/WhiteSpace/ScopeClosingBraceUnitTest.php
New file
0,0 → 1,74
<?php
/**
* Unit test class for the ScopeClosingBrace 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: ScopeClosingBraceUnitTest.php,v 1.4 2006/12/12 02:57:38 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ScopeClosingBrace 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 PEAR_Tests_WhiteSpace_ScopeClosingBraceUnitTest 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(
11 => 1,
13 => 1,
24 => 1,
61 => 1,
65 => 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/PEAR/Tests/WhiteSpace/ObjectOperatorIndentUnitTest.inc
New file
0,0 → 1,31
<?php
$someObject->someFunction("some", "parameter")
->someOtherFunc(23, 42)->
someOtherFunc2($one, $two)
 
->someOtherFunc3(23, 42)
->andAThirdFunction();
 
$someObject->someFunction("some", "parameter")
->someOtherFunc(23, 42);
 
$someObject->someFunction("some", "parameter")->someOtherFunc(23, 42);
 
$someObject->someFunction("some", "parameter")
->someOtherFunc(23, 42);
 
func(
$bar->foo()
)
->bar();
 
func(
$bar->foo()
)
->bar(
$bar->foo()
->bar()
->func()
);
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/WhiteSpace/ScopeClosingBraceUnitTest.inc
New file
0,0 → 1,71
<?php
 
class Test
{
public function __construct()
{
}
 
function test1()
{
}
 
function test2() {}
 
private function _test3()
{
}
 
}
 
 
class Test2
{
}
 
 
public function test2()
{
if ($str{0}) {
$chr = $str{0};
}
if (!class_exists($class_name)) {
echo $error;
}
$this->{$property} =& new $class_name($this->db_index);
$this->modules[$module] =& $this->{$property};
}
 
foreach ($elements as $element) {
if ($something) {
// Do IF.
} else if ($somethingElse) {
// Do ELSE.
}
}
 
switch ($foo) {
case 1:
switch ($bar) {
default:
if ($something) {
echo $string{1};
} else if ($else) {
switch ($else) {
case 1:
// Do something.
break;
default:
// Do something.
break;
}
}
}
break;
case 2:
// Do something;
break;
}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/WhiteSpace/ScopeIndentUnitTest.php
New file
0,0 → 1,83
<?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 2006/12/12 02:57:38 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 PEAR_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,
284 => 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/PEAR/Tests/WhiteSpace/ScopeIndentUnitTest.inc
New file
0,0 → 1,306
<?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': // no error here as switch statements shouldn't be indented ???
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;
}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/WhiteSpace/ObjectOperatorIndentUnitTest.php
New file
0,0 → 1,71
<?php
/**
* Unit test class for the ObjectOperatorIndent 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: ObjectOperatorIndentUnitTest.php,v 1.2 2009/02/20 00:26:47 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ObjectOperatorIndent 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 PEAR_Tests_WhiteSpace_ObjectOperatorIndentUnitTest 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 => 2,
6 => 1,
15 => 1,
27 => 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/PEAR/Tests/Classes/ClassDeclarationUnitTest.php
New file
0,0 → 1,76
<?php
/**
* Unit test class for the ClassDeclaration 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: ClassDeclarationUnitTest.php,v 1.3 2007/12/04 23:23:33 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ClassDeclaration 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 PEAR_Tests_Classes_ClassDeclarationUnitTest 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(
21 => 1,
22 => 1,
23 => 1,
27 => 1,
33 => 1,
38 => 1,
49 => 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/PEAR/Tests/Classes/ClassDeclarationUnitTest.inc
New file
0,0 → 1,63
<?php
 
// Correct declarations.
class CorrectClassDeclaration
{
 
}
 
abstract class CorrectClassDeclarationWithExtends extends correctClassDeclaration
{
 
}
 
final class CorrectClassDeclarationWithImplements implements correctClassDeclaration
{
 
}
 
 
// Incorrect placement of opening braces
class IncorrectBracePlacement {}
class IncorrectBracePlacementWithExtends extends correctClassDeclaration {}
class IncorrectBracePlacementWithImplements implements correctClassDeclaration {}
 
// Incorrect code placement for opening brace.
class IncorrectCodeAfterOpeningBrace
{ echo phpinfo();
 
}//end class
 
class IncorrectClassDeclarationWithExtends extends correctClassDeclaration
 
{
 
}
 
class IncorrectBracePlacement
{
}
 
abstract class CodeSnifferFail
extends
ArrayObject
implements
Serializable,
Iterator,
Countable,
OuterIterator,
RecursiveIterator {
}
 
abstract class CodeSnifferFail
extends
ArrayObject
implements
Serializable,
Iterator,
Countable,
OuterIterator,
RecursiveIterator
{
}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/NamingConventions/ValidClassNameUnitTest.php
New file
0,0 → 1,81
<?php
/**
* Unit test class for the ValidClassName 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: ValidClassNameUnitTest.php,v 1.5 2008/04/28 01:02:28 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ValidClassName 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 PEAR_Tests_NamingConventions_ValidClassNameUnitTest 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,
7 => 2,
9 => 1,
19 => 1,
24 => 1,
26 => 2,
28 => 1,
38 => 1,
40 => 2,
42 => 2,
44 => 1,
46 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/NamingConventions/ValidFunctionNameUnitTest.php
New file
0,0 → 1,176
<?php
/**
* Unit test class for the ValidFunctionName sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ValidFunctionNameUnitTest.php,v 1.7 2008/01/22 23:50:23 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ValidFunctionName sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Tests_NamingConventions_ValidFunctionNameUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
11 => 1,
12 => 1,
13 => 1,
14 => 1,
15 => 1,
16 => 1,
17 => 1,
18 => 1,
19 => 1,
20 => 1,
24 => 1,
25 => 1,
26 => 1,
27 => 1,
28 => 1,
29 => 1,
30 => 1,
31 => 1,
32 => 1,
33 => 1,
35 => 1,
36 => 1,
37 => 1,
38 => 1,
39 => 1,
40 => 1,
43 => 1,
44 => 1,
45 => 1,
46 => 1,
50 => 1,
51 => 1,
52 => 1,
53 => 1,
56 => 1,
57 => 1,
58 => 1,
59 => 1,
67 => 1,
68 => 1,
69 => 1,
70 => 1,
71 => 1,
72 => 1,
73 => 1,
74 => 1,
75 => 1,
76 => 1,
80 => 1,
81 => 1,
82 => 1,
83 => 1,
84 => 1,
85 => 1,
86 => 1,
87 => 1,
88 => 1,
89 => 1,
91 => 1,
92 => 1,
93 => 1,
94 => 1,
95 => 1,
96 => 1,
99 => 1,
100 => 1,
101 => 1,
102 => 1,
106 => 1,
107 => 1,
108 => 1,
109 => 1,
112 => 1,
113 => 1,
114 => 1,
115 => 1,
121 => 1,
122 => 1,
123 => 1,
124 => 1,
125 => 1,
126 => 1,
127 => 1,
128 => 1,
129 => 1,
130 => 1,
149 => 1,
150 => 1,
151 => 1,
154 => 1,
155 => 1,
156 => 1,
157 => 1,
158 => 1,
159 => 1,
160 => 1,
161 => 1,
162 => 1,
163 => 1,
164 => 1,
165 => 1,
166 => 1,
168 => 1,
169 => 1,
171 => 1,
172 => 1,
173 => 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/PEAR/Tests/NamingConventions/ValidVariableNameUnitTest.php
New file
0,0 → 1,70
<?php
/**
* Unit test class for the ValidVariableName 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: ValidVariableNameUnitTest.php,v 1.1 2008/01/31 22:17:02 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ValidVariableName sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @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 PEAR_Tests_NamingConventions_ValidVariableNameUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
12 => 1,
17 => 1,
22 => 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/PEAR/Tests/NamingConventions/ValidClassNameUnitTest.inc
New file
0,0 → 1,48
<?php
 
class Valid_Name {}
 
class invalid_Name {}
 
class invalid_name {}
 
class Invalid_name {}
 
class VALID_Name {}
 
class VALID_NAME {}
 
class VALID_Name {}
 
class ValidName {}
 
class _Invalid_Name {}
 
 
interface Valid_Name {}
 
interface invalid_Name {}
 
interface invalid_name {}
 
interface Invalid_name {}
 
interface VALID_Name {}
 
interface VALID_NAME {}
 
interface VALID_Name {}
 
interface ValidName {}
 
interface _Invalid_Name {}
 
class ___ {}
 
interface ___ {}
 
class Invalid__Name {}
 
interface Invalid__Name {}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/NamingConventions/ValidFunctionNameUnitTest.inc
New file
0,0 → 1,175
<?php
 
abstract class My_Class {
 
public function __construct() {}
public function My_Class() {}
public function _My_Class() {}
 
public function getSomeValue() {}
public function parseMyDSN() {}
public function get_some_value() {}
public function GetSomeValue() {}
public function getSomeValue_Again() {}
public function My_Package_getSomeValue() {}
public function _getSomeValue() {}
public function _parseMyDSN() {}
public function _get_some_value() {}
public function _GetSomeValue() {}
public function _getSomeValue_Again() {}
public function _My_Package_getSomeValue() {}
 
protected function getSomeValue() {}
protected function parseMyDSN() {}
protected function get_some_value() {}
protected function GetSomeValue() {}
protected function getSomeValue_Again() {}
protected function My_Package_getSomeValue() {}
protected function _getSomeValue() {}
protected function _parseMyDSN() {}
protected function _get_some_value() {}
protected function _GetSomeValue() {}
protected function _getSomeValue_Again() {}
protected function _My_Package_getSomeValue() {}
 
private function getSomeValue() {}
private function parseMyDSN() {}
private function get_some_value() {}
private function GetSomeValue() {}
private function getSomeValue_Again() {}
private function My_Package_getSomeValue() {}
private function _getSomeValue() {}
private function _parseMyDSN() {}
private function _get_some_value() {}
private function _GetSomeValue() {}
private function _getSomeValue_Again() {}
private function _My_Package_getSomeValue() {}
 
function getSomeValue() {}
function parseMyDSN() {}
function get_some_value() {}
function GetSomeValue() {}
function getSomeValue_Again() {}
function My_Package_getSomeValue() {}
function _getSomeValue() {}
function _parseMyDSN() {}
function _get_some_value() {}
function _GetSomeValue() {}
function _getSomeValue_Again() {}
function _My_Package_getSomeValue() {}
 
}//end class
 
interface My_Interface {
 
public function getSomeValue() {}
public function parseMyDSN() {}
public function get_some_value() {}
public function GetSomeValue() {}
public function getSomeValue_Again() {}
public function My_Package_getSomeValue() {}
public function _getSomeValue() {}
public function _parseMyDSN() {}
public function _get_some_value() {}
public function _GetSomeValue() {}
public function _getSomeValue_Again() {}
public function _My_Package_getSomeValue() {}
 
protected function getSomeValue() {}
protected function parseMyDSN() {}
protected function get_some_value() {}
protected function GetSomeValue() {}
protected function getSomeValue_Again() {}
protected function My_Package_getSomeValue() {}
protected function _getSomeValue() {}
protected function _parseMyDSN() {}
protected function _get_some_value() {}
protected function _GetSomeValue() {}
protected function _getSomeValue_Again() {}
protected function _My_Package_getSomeValue() {}
 
private function getSomeValue() {}
private function parseMyDSN() {}
private function get_some_value() {}
private function GetSomeValue() {}
private function getSomeValue_Again() {}
private function My_Package_getSomeValue() {}
private function _getSomeValue() {}
private function _parseMyDSN() {}
private function _get_some_value() {}
private function _GetSomeValue() {}
private function _getSomeValue_Again() {}
private function _My_Package_getSomeValue() {}
 
function getSomeValue() {}
function parseMyDSN() {}
function get_some_value() {}
function GetSomeValue() {}
function getSomeValue_Again() {}
function My_Package_getSomeValue() {}
function _getSomeValue() {}
function _parseMyDSN() {}
function _get_some_value() {}
function _GetSomeValue() {}
function _getSomeValue_Again() {}
function _My_Package_getSomeValue() {}
 
}//end interface
 
function My_Package_getSomeValue() {}
function My_Package_parseMyDSN() {}
function My_Package_get_some_value() {}
function My_PackagegetSomeValue() {}
function My_Package_getSomeValue_Again() {}
function My_Package() {}
function _My_Package_getSomeValue() {}
function _My_Package_parseMyDSN() {}
function _My_Package_get_some_value() {}
function _My_PackagegetSomeValue() {}
function _My_Package_getSomeValue_Again() {}
function _My_Package() {}
 
 
/* Test for magic functions */
 
class Magic_Test {
function __construct() {}
function __destruct() {}
function __call() {}
function __callStatic() {}
function __get() {}
function __set() {}
function __isset() {}
function __unset() {}
function __sleep() {}
function __wakeup() {}
function __toString() {}
function __set_state() {}
function __clone() {}
function __autoload() {}
function __myFunction() {}
function __my_function() {}
}
 
function __construct() {}
function __destruct() {}
function __call() {}
function __callStatic() {}
function __get() {}
function __set() {}
function __isset() {}
function __unset() {}
function __sleep() {}
function __wakeup() {}
function __toString() {}
function __set_state() {}
function __clone() {}
function __autoload() {}
function __myFunction() {}
function __my_function() {}
 
function my_package_function() {}
function Package_() {}
function Package() {}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/NamingConventions/ValidVariableNameUnitTest.inc
New file
0,0 → 1,60
<?php
class MyClass
{
$varName = 'hello';
$var_name = 'hello';
$varname = 'hello';
$_varName = 'hello';
 
public $varName = 'hello';
public $var_name = 'hello';
public $varname = 'hello';
public $_varName = 'hello';
 
protected $varName = 'hello';
protected $var_name = 'hello';
protected $varname = 'hello';
protected $_varName = 'hello';
 
private $_varName = 'hello';
private $_var_name = 'hello';
private $_varname = 'hello';
private $varName = 'hello';
}
 
class MyClass
{
function func1()
{
function func2()
{
return $a;
}
return $data;
}
}
 
class MyClass
{
public function prepare() {}
public function paint() {}
}
 
if (true) {
class MyClass
{
$varName = 'hello';
$var_name = 'hello';
}
}
 
class MyClass {
function myFunction($cc, $cv) {
$req = "delete from blah
where not (POP_{$cc}_A =
'{$this->def["POP_{$cc}_A"]}'
and POP_{$cc}_B =
'{$this->def["POP_{$cc}_B"]}')";
}
}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Commenting/InlineCommentUnitTest.php
New file
0,0 → 1,72
<?php
/**
* Unit test class for the InlineComment 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: InlineCommentUnitTest.php,v 1.2 2006/12/12 02:57:38 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the InlineComment 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 PEAR_Tests_Commenting_InlineCommentUnitTest 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(
15 => 1,
24 => 1,
25 => 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/PEAR/Tests/Commenting/FileCommentUnitTest.php
New file
0,0 → 1,98
<?php
/**
* Unit test class for FunctionCommentSniff.
*
* 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: FileCommentUnitTest.php,v 1.9 2007/11/05 03:00:12 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for FunctionCommentSniff.
*
* Verifies that :
* <ul>
* <li>A doc comment exists.</li>
* <li>Short description must start with a capital letter and end with a period.</li>
* <li>There must be one blank newline after the short description.</li>
* <li>A PHP version is specified.</li>
* <li>Check the order of the tags.</li>
* <li>Check the indentation of each tag.</li>
* <li>Check required and optional tags and the format of their content.</li>
* </ul>
*
* @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 PEAR_Tests_Commenting_FileCommentUnitTest 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(
6 => 1,
8 => 1,
21 => 2,
23 => 2,
24 => 1,
26 => 2,
27 => 1,
28 => 1,
29 => 1,
30 => 1,
31 => 2,
32 => 1,
34 => 1,
35 => 1,
36 => 1,
39 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array(
28 => 1,
29 => 1,
33 => 1,
39 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Commenting/InlineCommentUnitTest.inc
New file
0,0 → 1,27
<?php
 
// Some code goes here.
 
// This comment contains # multiple
// hash signs (#).
 
/*
* Here is a small function comment.
*/
function test()
{
// Some code goes here.
 
# This comment is banned.
 
}//end test()
 
/*
A longer comment goes here.
It spans multiple lines.
*/
 
# This is a long comment
# that is banned.
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Commenting/FileCommentUnitTest.inc
New file
0,0 → 1,48
<?php
declare(encoding='utf-8');
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
 
/**
*
* Short description for fileasdasd.
*
*
* asdasd
* long description for file (if any)
* asdasdadada
*
* PHP versio
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category _wrong_category
* @package PHP_CodeSniffer
* @package ADDITIONAL PACKAGE TAG
* @subpackage SUBPACKAGE TAG
* @author Antônio Carlos Venâncio Júnior <foreign@character.net>
* @author Rayn Ong rong@squiz.net
* @author
* @copyright 1997~1994 The PHP Group
* @copyright 1997~1994 The PHP Group
* @license http://www.php.net/license/3_0.txt
* @see
* @see
* @version INVALID VERSION CONTENT
* @see Net_Sample::Net_Sample()
* @see Net_Other
* @deprecated asd
* @since Class available since Release 1.2.0
* @summary An unknown summary tag
*/
?>
<?php
/**
* This bit here is not qualified as file comment
*
* as it is not after the first open tag
*
*/
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Commenting/ClassCommentUnitTest.php
New file
0,0 → 1,91
<?php
/**
* Unit test class for ClassCommentSniff.
*
* 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: ClassCommentUnitTest.php,v 1.12 2008/02/06 02:54:57 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for ClassCommentSniff.
*
* @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 PEAR_Tests_Commenting_ClassCommentUnitTest 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,
15 => 1,
22 => 1,
25 => 1,
28 => 1,
46 => 1,
51 => 1,
63 => 1,
65 => 2,
66 => 1,
68 => 2,
69 => 1,
70 => 1,
71 => 1,
73 => 2,
74 => 1,
76 => 1,
77 => 1,
78 => 1,
84 => 1,
92 => 1,
102 => 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(
70 => 1,
72 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.php
New file
0,0 → 1,92
<?php
/**
* Unit test class for FunctionCommentSniff.
*
* 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: FunctionCommentUnitTest.php,v 1.16 2007/11/06 09:14:05 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for FunctionCommentSniff.
*
* @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 PEAR_Tests_Commenting_FunctionCommentUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
10 => 1,
12 => 2,
13 => 2,
14 => 1,
15 => 1,
28 => 1,
35 => 1,
38 => 1,
41 => 1,
53 => 1,
103 => 1,
109 => 1,
112 => 1,
122 => 1,
123 => 3,
124 => 3,
125 => 5,
126 => 6,
139 => 1,
155 => 1,
165 => 1,
172 => 1,
183 => 1,
193 => 2,
204 => 1,
234 => 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/PEAR/Tests/Commenting/ClassCommentUnitTest.inc
New file
0,0 → 1,110
<?php
define('OK', 1);
 
class No_Comment
{
 
}//end class
 
 
//
// Sample class comment
//
//
//
class Invalid_Comment_Style1
{
 
}//end class
 
 
/**
*
*
* Sample class comment
*
*
* Long description with extra blank line before and after
*
*
* @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.0
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Extra_Description_Newlines
{
 
}//end class
 
 
/**
* Sample class comment
* @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
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Missing_Newlines_Before_Tags
{
 
}//end class
 
 
/**
* Simple class comment
*
* @category _wrong_category
* @package PHP_CodeSniffer
* @package ADDITIONAL PACKAGE TAG
* @subpackage SUBPACKAGE TAG
* @author Original Author <author@example.com>
* @author Rayn Ong rong@squiz.net
* @author
* @copyright 1997~1994 The PHP Group
* @license http://www.php.net/license/3_0.txt
* @version INVALID VERSION CONTENT
* @see
* @see
* @link sdfsdf
* @see Net_Sample::Net_Sample()
* @see Net_Other
* @deprecated asd
* @unknown Unknown tag
* @since Class available since Release 1.2.0
*/
class Checking_Tags
{
class Sub_Class {
 
}//end class
 
 
}//end class
 
 
/**
*
*
*/
class Empty_Class_Doc
{
 
}//end class
 
 
/**
*
*
*/
interface Empty_Interface_Doc
{
 
}//end interface
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.inc
New file
0,0 → 1,254
<?php
class PHP_CodeSniffer_File
{
 
/**
* A simple function comment.
*
* long desc here
*
* @param int $stackPtr The position in @ @unknown the stack of the token
* that opened the scope
* @param int $detph How many scope levels down we are.
* @param int $index The index
* @return
* @throws
*/
private function _functionCall($stackPtr, $depth=1, $index)
{
return $stackPtr;
 
}//end _functionCall()
 
//
// Sample function comment
//
//
//
public function invalidCommentStyle()
{
 
}//end invalidCommentStyle()
 
 
/**
*
*
* A simple function comment
*
*
* Long description with extra blank line before and after
*
*
* @return void
*/
public function extraDescriptionNewlines()
{
 
}//end extraDescriptionNewlines()
 
 
/**
* A simple function comment
* @return void
*/
public function missingNewlinesBeforeTags()
{
 
}//end missingNewlinesBeforeTags()
 
 
/**
* Access tag should not be treated as a long description
*
* @access public
* @return void
*/
public function accessTag()
{
 
}//end accessTag()
 
/**
* Constructor
*
* No return tag
*/
function PHP_CodeSniffer_File()
{
return;
}
 
 
/**
* Destructor
*
* No return tag too
*/
function _PHP_CodeSniffer_File()
{
return;
}
 
 
/**
* Destructor PHP5
*/
function __destruct()
{
return;
}
 
 
function missingComment()
{
return;
}
 
 
/**
* no return tag
*
*/
public function noReturn($one)
{
 
}//end noReturn()
 
 
/**
* Param not immediate
*
* @return
* @param int $threeSpaces
* @param int $superfluous
* @param missing
* @param
*/
public function missingDescroption($threeSpaces)
{
 
}//end missingDescroption()
 
 
/**
* Param not immediate
*
* @param int $one comment
* @param int $two comment
* @param string $three comment
*
* @return void
*/
public function oneSpaceAfterLongestVar($one, $two, $three)
{
 
}//end oneSpaceAfterLongestVar()
 
 
}//end class
 
 
/**
* A simple function comment
*
* @param string $str The string passed in by reference
*
* @return void
*/
public function functionOutsideClass(&$str)
{
return;
}//end functionOutsideClass()
 
 
function missingCommentOutsideClass()
{
return;
}//end missingCommentOutsideClass()
 
 
?><?php
function tagBeforeComment()
{
return;
}//end tagBeforeComment()
 
 
/**
* no return tag
*
*
*
*/
public function noReturnOutsideClass()
{
 
}//end noReturnOutsideClass()
 
 
/**
* Missing param comment
*
* @param int $one comment
*
* @return void
* @fine Unknown tag
*/
public function missingTwoParamComment($one, $two, $three)
{
 
}//end missingTwoParamComment()
 
 
/**
*
*/
function emptyFunctionDocComment()
{
}//end emptyFunctionDocComment()
 
 
/**
* Test function.
*
* @param string $arg1 An argument
*
* @access public
* @return bool
*/
function myFunction($arg1) {}
 
 
/**
* Test function.
*
* @param string $arg1 An argument
*
* @access public
* @return bool
*/
 
echo $blah;
 
function myFunction($arg1) {}
 
/**
* Test function.
*
* @access public
* @return bool
* @throws MyException
* @throws MyException When I feel like it
*/
function myFunction() {}
 
class MyClass() {
/**
* An abstract function.
*
* @return array(string)
*/
abstract final protected function myFunction();
}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Files/IncludingFileUnitTest.php
New file
0,0 → 1,85
<?php
/**
* Unit test class for the IncludingFile 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: IncludingFileUnitTest.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 IncludingFile 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 PEAR_Tests_Files_IncludingFileUnitTest 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,
11 => 1,
12 => 1,
16 => 1,
17 => 1,
33 => 1,
34 => 1,
47 => 1,
48 => 1,
64 => 1,
65 => 1,
73 => 1,
74 => 1,
85 => 1,
86 => 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/PEAR/Tests/Files/IncludingFileUnitTest.inc
New file
0,0 → 1,98
<?php
 
// These are statements and should not have brackets.
require_once('blank.inc');
require('blank.inc');
 
$test = true;
 
// Conditionally including a class file: use include_once
if ($test) {
require_once 'blank.inc';
require 'blank.inc';
}
 
// Unconditionally including a class file: use require_once
include_once 'blank.inc';
include 'blank.inc';
 
 
// These are ok
if ($test) {
include_once 'blank.inc';
include 'blank.inc';
}
 
require_once 'blank.inc';
require 'blank.inc';
 
?>
<pre>
Some content goes here.
<?php
include_once 'blank.inc';
include 'blank.inc';
require_once 'blank.inc';
require 'blank.inc';
?>
</pre>
<?php
 
if (include_once 'blank.inc') {
$var = include_once 'blank.inc';
if ($var === true) {
}
}
 
if (require_once 'blank.inc') {
$var = require_once 'blank.inc';
if ($var === true) {
}
}
 
function get_some_value()
{
include_once 'blank.inc';
include 'blank.inc';
 
// These are ok
if ($test) {
include_once 'blank.inc';
include 'blank.inc';
}
 
require_once 'blank.inc';
require 'blank.inc';
 
?>
<pre>
Some content goes here.
<?php
include_once 'blank.inc';
include 'blank.inc';
require_once 'blank.inc';
require 'blank.inc';
?>
</pre>
<?php
 
if (include_once 'blank.inc') {
$var = include_once 'blank.inc';
if ($var === true) {
}
}
if (require_once 'blank.inc') {
$var = require_once 'blank.inc';
if ($var === true) {
}
}
}
 
 
$var = include_once 'blank.inc';
if ($var == false) {
 
}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/ControlStructures/ControlSignatureUnitTest.php
New file
0,0 → 1,90
<?php
/**
* Unit test class for the ControlSignature 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: ControlSignatureUnitTest.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 ControlSignature 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 PEAR_Tests_ControlStructures_ControlSignatureUnitTest 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,
14 => 1,
20 => 1,
22 => 1,
32 => 1,
36 => 1,
44 => 1,
48 => 1,
56 => 1,
60 => 1,
68 => 1,
72 => 1,
84 => 1,
88 => 2,
100 => 1,
104 => 2,
122 => 2,
128 => 1,
132 => 3,
133 => 2,
147 => 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/PEAR/Tests/ControlStructures/ControlSignatureUnitTest.inc
New file
0,0 → 1,155
<?php
 
// do ... while
$i = 0;
do {
echo $i;
} while ($i > 0);
 
do
{
echo $i;
} while ($i > 0);
 
do
{
echo $i;
}
while ($i > 0);
 
do { echo $i; } while ($i > 0);
 
do{
echo $i;
}while($i > 0);
 
 
// while
while ($i < 1) {
echo $i;
}
 
while($i < 1){
echo $i;
}
 
while ($i < 1) { echo $i; }
 
 
// for
for ($i = 1; $i < 1; $i++) {
echo $i;
}
 
for($i = 1; $i < 1; $i++){
echo $i;
}
 
for ($i = 1; $i < 1; $i++) { echo $i; }
 
 
// foreach
foreach ($items as $item) {
echo $item;
}
 
foreach($items as $item){
echo $item;
}
 
for ($items as $item) { echo $item; }
 
 
// if
if ($i == 0) {
$i = 1;
}
 
if($i == 0){
$i = 1;
}
 
if ($i == 0) { $i = 1; }
 
 
// else
if ($i == 0) {
$i = 1;
} else {
$i = 0;
}
 
if ($i == 0) {
$i = 1;
}else{
$i = 0;
}
 
if ($i == 0) { $i = 1; } else { $i = 0; }
 
 
// else
if ($i == 0) {
$i = 1;
} else {
$i = 0;
}
 
if ($i == 0) {
$i = 1;
}else{
$i = 0;
}
 
if ($i == 0) { $i = 1; } else { $i = 0; }
 
 
// else if
if ($i == 0) {
$i = 1;
} else if ($i == 2) {
$i = 0;
}
 
if ($i == 0) {
$i = 1;
} elseif ($i == 2) {
$i = 0;
}
 
if ($i == 0) {
$i = 1;
}else if($i == 2){
$i = 0;
}
 
if ($i == 0) {
$i = 1;
}elseif($i == 2){
$i = 0;
}
 
if ($i == 0) { $i = 1; } else if ($i == 2) { $i = 0; }
if ($i == 0) { $i = 1; } elseif ($1 == 2) { $i = 0; }
 
if ($i == 0) { // this is ok because comments are allowed
$i = 1;
}
 
if ($i == 0) {// this is ok because comments are allowed
$i = 1;
}
 
if ($i == 0) { /* this is ok because comments are allowed*/
$i = 1;
}
 
if ($i == 0)
{ // this is not ok
$i = 1;
}
 
if ($i == 0) /* this is ok */ {
}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/ControlStructures/MultiLineConditionUnitTest.php
New file
0,0 → 1,84
<?php
/**
* Unit test class for the MultiLineCondition 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: MultiLineConditionUnitTest.php,v 1.2 2008/12/07 22:25:02 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the MultiLineCondition 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 PEAR_Tests_ControlStructures_MultiLineConditionUnitTest 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(
19 => 1,
32 => 1,
37 => 1,
38 => 1,
39 => 1,
40 => 1,
46 => 1,
51 => 1,
55 => 1,
56 => 1,
58 => 1,
85 => 1,
86 => 1,
87 => 1,
93 => 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/PEAR/Tests/ControlStructures/MultiLineConditionUnitTest.inc
New file
0,0 → 1,100
<?php
if (($condition1
|| $condition2)
&& $condition3
&& $condition4
&& $condition5
) {
}
 
if (($condition1 || $condition2) && $condition3 && $condition4 && $condition5) {
}
 
if (($condition1 || $condition2)
&& $condition3
) {
}
 
if (
($condition1 || $condition2)
&& $condition3
) {
}
 
if (($condition1
|| $condition2)
) {
}
 
if (($condition1
|| $condition2)
&& $condition3 &&
$condition4
) {
}
 
if (($condition1
|| $condition2)
&& $condition3
&& $condition4
&& $condition5
) {
}
 
if (($condition1
|| $condition2)
) {
}
 
if (($condition1
|| $condition2)
) {
}
 
if (
(
$condition1
|| $condition2
)
&& $condition3
) {
}
 
 
if ( $condition1
|| $condition2
|| $condition3
) {
}
 
if ($condition1
|| $condition2
|| $condition3
) {
} else if ($condition1
|| $condition2
|| $condition3
) {
}
 
if ($condition1
|| $condition2
|| $condition3
) {
} else if (
$condition1
|| $condition2 &&
$condition3
) {
}
 
if ($condition1
|| $condition2
|| $condition3) {
}
 
if ($condition1
|| $condition2 || $condition3
) {
}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Docs/NamingConventions/ValidClassNameStandard.xml
New file
0,0 → 1,23
<documentation title="Class Names">
<standard>
<![CDATA[
Classes should be given descriptive names. Avoid using abbreviations where possible. Class names should always begin with an uppercase letter. The PEAR class hierarchy is also reflected in the class name, each level of the hierarchy separated with a single underscore.
]]>
</standard>
<code_comparison>
<code title="Examples of valid class names">
<![CDATA[
Log
Net_Finger
HTML_Upload_Error
]]>
</code>
<code title="Examples of invalid class names">
<![CDATA[
log
NetFinger
HTML-Upload-Error
]]>
</code>
</code_comparison>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Docs/NamingConventions/ValidFunctionNameStandard.xml
New file
0,0 → 1,23
<documentation title="Function and Method Names">
<standard>
<![CDATA[
Functions and methods should be named using the "studly caps" style (also referred to as "bumpy case" or "camel caps"). Functions should in addition have the package name as a prefix, to avoid name collisions between packages. The initial letter of the name (after the prefix) is lowercase, and each letter that starts a new "word" is capitalized.
]]>
</standard>
<code_comparison>
<code title="Examples of valid function names">
<![CDATA[
connect()
getData()
buildSomeWidget()
XML_RPC_serializeData()
]]>
</code>
<code title="Examples of invalid function names">
<![CDATA[
Connect()
get_data()
]]>
</code>
</code_comparison>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Docs/Files/LineLengthStandard.xml
New file
0,0 → 1,7
<documentation title="Line Length">
<standard>
<![CDATA[
It is recommended to keep lines at approximately 85 characters long for better code readability.
]]>
</standard>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Docs/Files/IncludingFileStandard.xml
New file
0,0 → 1,24
<documentation title="Including Code">
<standard>
<![CDATA[
Anywhere you are unconditionally including a class file, use <em>require_once</em>. Anywhere you are conditionally including a class file (for example, factory methods), use <em>include_once</em>. Either of these will ensure that class files are included only once. They share the same file list, so you don't need to worry about mixing them - a file included with <em>require_once</em> will not be included again by <em>include_once</em>.
]]>
</standard>
<standard>
<![CDATA[
Note that <em>include_once</em> and <em>require_once</em> are statements, not functions. Parentheses should not surround the subject filename.
]]>
</standard>
<code_comparison>
<code title="Valid: used as statement">
<![CDATA[
require_once 'PHP/CodeSniffer.php';
]]>
</code>
<code title="Invalid: used as function">
<![CDATA[
require_once<em>(</em>'PHP/CodeSniffer.php'<em>)</em>;
]]>
</code>
</code_comparison>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Docs/Functions/ValidDefaultValueStandard.xml
New file
0,0 → 1,25
<documentation title="Default Values in Function Declarations">
<standard>
<![CDATA[
Arguments with default values go at the end of the argument list.
]]>
</standard>
<code_comparison>
<code title="Valid: argument with default value at end of declaration">
<![CDATA[
function connect($dsn, <em>$persistent = false</em>)
{
...
}
]]>
</code>
<code title="Invalid: argument with default value at start of declaration">
<![CDATA[
function connect(<em>$persistent = false</em>, $dsn)
{
...
}
]]>
</code>
</code_comparison>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Docs/Functions/FunctionCallSignatureStandard.xml
New file
0,0 → 1,19
<documentation title="Function Calls">
<standard>
<![CDATA[
Functions should be called with no spaces between the function name, the opening parenthesis, and the first parameter; and no space between the last parameter, the closing parenthesis, and the semicolon.
]]>
</standard>
<code_comparison>
<code title="Valid: spaces between parameters">
<![CDATA[
$var = foo($bar, $baz, $quux);
]]>
</code>
<code title="Invalid: additional spaces used">
<![CDATA[
$var = foo<em> </em>(<em> </em>$bar, $baz, $quux<em> </em>)<em> </em>;
]]>
</code>
</code_comparison>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Docs/Functions/FunctionCallArgumentSpacingStandard.xml
New file
0,0 → 1,19
<documentation title="Parameter Spacing in Function Calls">
<standard>
<![CDATA[
There must be one space between a comma and a parameter in a function call.
]]>
</standard>
<code_comparison>
<code title="Valid: spaces between parameters">
<![CDATA[
$var = foo($bar<em>, </em>$baz<em>, </em>$quux);
]]>
</code>
<code title="Invalid: no space between commas and parameters">
<![CDATA[
$var = foo($bar<em>,</em>$baz<em>,</em>$quux);
]]>
</code>
</code_comparison>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionCallArgumentSpacingSniff.php
New file
0,0 → 1,135
<?php
/**
* PEAR_Sniffs_Functions_FunctionCallArgumentSpacingSniff.
*
* 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: FunctionCallArgumentSpacingSniff.php,v 1.8 2007/07/23 01:47:53 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* PEAR_Sniffs_Functions_FunctionCallArgumentSpacingSniff.
*
* Checks that calls to methods and functions are spaced correctly.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_Functions_FunctionCallArgumentSpacingSniff 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();
 
// Skip tokens that are the names of functions or classes
// within their definitions. For example:
// function myFunction...
// "myFunction" is T_STRING but we should skip because it is not a
// function or method *call*.
$functionName = $stackPtr;
$functionKeyword = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
if ($tokens[$functionKeyword]['code'] === T_FUNCTION || $tokens[$functionKeyword]['code'] === T_CLASS) {
return;
}
 
// If the next non-whitespace token after the function or method call
// is not an opening parenthesis then it cant really be a *call*.
$openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($functionName + 1), null, true);
if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
return;
}
 
$closeBracket = $tokens[$openBracket]['parenthesis_closer'];
 
$nextSeperator = $openBracket;
while (($nextSeperator = $phpcsFile->findNext(array(T_COMMA, T_VARIABLE), ($nextSeperator + 1), $closeBracket)) !== false) {
// Make sure the comma or variable belongs directly to this function call,
// and is not inside a nested function call or array.
$brackets = $tokens[$nextSeperator]['nested_parenthesis'];
$lastBracket = array_pop($brackets);
if ($lastBracket !== $closeBracket) {
continue;
}
 
if ($tokens[$nextSeperator]['code'] === T_COMMA) {
if ($tokens[($nextSeperator - 1)]['code'] === T_WHITESPACE) {
$error = 'Space found before comma in function call';
$phpcsFile->addError($error, $stackPtr);
}
 
if ($tokens[($nextSeperator + 1)]['code'] !== T_WHITESPACE) {
$error = 'No space found after comma in function call';
$phpcsFile->addError($error, $stackPtr);
} else {
// If there is a newline in the space, then the must be formatting
// each argument on a newline, which is valid, so ignore it.
if (strpos($tokens[($nextSeperator + 1)]['content'], $phpcsFile->eolChar) === false) {
$space = strlen($tokens[($nextSeperator + 1)]['content']);
if ($space > 1) {
$error = 'Expected 1 space after comma in function call; ';
$error .= $space.' found';
$phpcsFile->addError($error, $stackPtr);
}
}
}
} else {
// Token is a variable.
$nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($nextSeperator + 1), $closeBracket, true);
if ($nextToken !== false) {
if ($tokens[$nextToken]['code'] === T_EQUAL) {
if (($tokens[($nextToken - 1)]['code']) !== T_WHITESPACE) {
$error = 'Expected 1 space before = sign of default value';
$phpcsFile->addError($error, $stackPtr);
}
 
if ($tokens[($nextToken + 1)]['code'] !== T_WHITESPACE) {
$error = 'Expected 1 space after = sign of default value';
$phpcsFile->addError($error, $stackPtr);
}
}
}
}//end if
}//end while
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php
New file
0,0 → 1,196
<?php
/**
* PEAR_Sniffs_Functions_FunctionDeclarationSniff.
*
* 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: FunctionDeclarationSniff.php,v 1.4 2008/12/01 05:45:49 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* PEAR_Sniffs_Functions_FunctionDeclarationSniff.
*
* Ensure single and multi-line function declarations are defined correctly.
*
* @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 PEAR_Sniffs_Functions_FunctionDeclarationSniff 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();
 
// Check if this is a single line or multi-line declaration.
$openBracket = $tokens[$stackPtr]['parenthesis_opener'];
$closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
if ($tokens[$openBracket]['line'] === $tokens[$closeBracket]['line']) {
$this->processSingleLineDeclaration($phpcsFile, $stackPtr, $tokens);
} else {
$this->processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens);
}
 
}//end process()
 
 
/**
* Processes single-line declarations.
*
* Just uses the Generic BSD-Allman brace sniff.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
* @param array $tokens The stack of tokens that make up
* the file.
*
* @return void
*/
public function processSingleLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens)
{
if (class_exists('Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff', true) === false) {
throw new PHP_CodeSniffer_Exception('Class Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff not found');
}
 
$sniff = new Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff();
$sniff->process($phpcsFile, $stackPtr);
 
}//end processSingleLineDeclaration()
 
 
/**
* Processes mutli-line declarations.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
* @param array $tokens The stack of tokens that make up
* the file.
*
* @return void
*/
public function processMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens)
{
// We need to work out how far indented the function
// declaration itself is, so we can work out how far to
// indent parameters.
$functionIndent = 0;
for ($i = ($stackPtr - 1); $i >= 0; $i--) {
if ($tokens[$i]['line'] !== $tokens[$stackPtr]['line']) {
$i++;
break;
}
}
 
if ($tokens[$i]['code'] === T_WHITESPACE) {
$functionIndent = strlen($tokens[$i]['content']);
}
 
// Each line between the parenthesis should be indented 4 spaces.
$openBracket = $tokens[$stackPtr]['parenthesis_opener'];
$closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
$lastLine = $tokens[$openBracket]['line'];
for ($i = ($openBracket + 1); $i < $closeBracket; $i++) {
if ($tokens[$i]['line'] !== $lastLine) {
if ($tokens[$i]['line'] === $tokens[$closeBracket]['line']) {
// Closing brace needs to be indented to the same level
// as the function.
$expectedIndent = $functionIndent;
} else {
$expectedIndent = ($functionIndent + 4);
}
 
// We changed lines, so this should be a whitespace indent token.
if ($tokens[$i]['code'] !== T_WHITESPACE) {
$foundIndent = 0;
} else {
$foundIndent = strlen($tokens[$i]['content']);
}
 
if ($expectedIndent !== $foundIndent) {
$error = "Multi-line function declaration not indented correctly; expected $expectedIndent spaces but found $foundIndent";
$phpcsFile->addError($error, $i);
}
 
$lastLine = $tokens[$i]['line'];
}
}
 
if (isset($tokens[$stackPtr]['scope_opener']) === true) {
// The openning brace needs to be one space away
// from the closing parenthesis.
$next = $tokens[($closeBracket + 1)];
if ($next['code'] !== T_WHITESPACE) {
$length = 0;
} else if ($next['content'] === $phpcsFile->eolChar) {
$length = -1;
} else {
$length = strlen($next['content']);
}
 
if ($length !== 1) {
$error = 'There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found ';
if ($length === -1) {
$error .= 'newline';
} else {
$error .= "$length spaces";
}
 
$phpcsFile->addError($error, ($closeBracket + 1));
return;
}
 
// And just in case they do something funny before the brace...
$next = $phpcsFile->findNext(
T_WHITESPACE,
($closeBracket + 1),
null,
true
);
 
if ($next !== false && $tokens[$next]['code'] !== T_OPEN_CURLY_BRACKET) {
$error = 'There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration';
$phpcsFile->addError($error, $next);
}
}
 
}//end processMultiLineDeclaration()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Functions/ValidDefaultValueSniff.php
New file
0,0 → 1,110
<?php
/**
* PEAR_Sniffs_Functions_ValidDefaultValueSniff.
*
* 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: ValidDefaultValueSniff.php,v 1.5 2007/07/23 01:47:53 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* PEAR_Sniffs_Functions_ValidDefaultValueSniff.
*
* A Sniff to ensure that parameters defined for a function that have a default
* value come at the end of the function signature.
*
* @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 PEAR_Sniffs_Functions_ValidDefaultValueSniff 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();
 
$argStart = $tokens[$stackPtr]['parenthesis_opener'];
$argEnd = $tokens[$stackPtr]['parenthesis_closer'];
 
// Flag for when we have found a default in our arg list.
// If there is a value without a default after this, it is an error.
$defaultFound = false;
 
$nextArg = $argStart;
while (($nextArg = $phpcsFile->findNext(T_VARIABLE, ($nextArg + 1), $argEnd)) !== false) {
$argHasDefault = self::_argHasDefault($phpcsFile, $nextArg);
if (($argHasDefault === false) && ($defaultFound === true)) {
$error = 'Arguments with default values must be at the end';
$error .= ' of the argument list';
$phpcsFile->addError($error, $nextArg);
return;
}
 
if ($argHasDefault === true) {
$defaultFound = true;
}
}
 
}//end process()
 
 
/**
* Returns true if the passed argument has a default value.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $argPtr The position of the argument
* in the stack.
*
* @return bool
*/
private static function _argHasDefault(PHP_CodeSniffer_File $phpcsFile, $argPtr)
{
$tokens = $phpcsFile->getTokens();
$nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($argPtr + 1), null, true);
if ($tokens[$nextToken]['code'] !== T_EQUAL) {
return false;
}
 
return true;
 
}//end _argHasDefault()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php
New file
0,0 → 1,243
<?php
/**
* PEAR_Sniffs_Functions_FunctionCallSignatureSniff.
*
* 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: FunctionCallSignatureSniff.php,v 1.7 2008/12/05 02:45:08 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* PEAR_Sniffs_Functions_FunctionCallSignatureSniff.
*
* @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 PEAR_Sniffs_Functions_FunctionCallSignatureSniff 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();
 
// Find the next non-empty token.
$openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
 
if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
// Not a function call.
return;
}
 
if (isset($tokens[$openBracket]['parenthesis_closer']) === false) {
// Not a function call.
return;
}
 
// Find the previous non-empty token.
$previous = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
if ($tokens[$previous]['code'] === T_FUNCTION) {
// It's a function definition, not a function call.
return;
}
 
if ($tokens[$previous]['code'] === T_NEW) {
// We are creating an object, not calling a function.
return;
}
 
$closeBracket = $tokens[$openBracket]['parenthesis_closer'];
 
if (($stackPtr + 1) !== $openBracket) {
// Checking this: $value = my_function[*](...).
$error = 'Space before opening parenthesis of function call prohibited';
$phpcsFile->addError($error, $stackPtr);
}
 
$next = $phpcsFile->findNext(T_WHITESPACE, ($closeBracket + 1), null, true);
if ($tokens[$next]['code'] === T_SEMICOLON) {
if (in_array($tokens[($closeBracket + 1)]['code'], PHP_CodeSniffer_Tokens::$emptyTokens) === true) {
$error = 'Space after closing parenthesis of function call prohibited';
$phpcsFile->addError($error, $closeBracket);
}
}
 
// Check if this is a single line or multi-line function call.
if ($tokens[$openBracket]['line'] === $tokens[$closeBracket]['line']) {
$this->processSingleLineCall($phpcsFile, $stackPtr, $openBracket, $tokens);
} else {
$this->processMultiLineCall($phpcsFile, $stackPtr, $openBracket, $tokens);
}
 
}//end process()
 
 
/**
* Processes single-line calls.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
* @param int $openBracket The position of the openning bracket
* in the stack passed in $tokens.
* @param array $tokens The stack of tokens that make up
* the file.
*
* @return void
*/
public function processSingleLineCall(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $tokens)
{
if ($tokens[($openBracket + 1)]['code'] === T_WHITESPACE) {
// Checking this: $value = my_function([*]...).
$error = 'Space after opening parenthesis of function call prohibited';
$phpcsFile->addError($error, $stackPtr);
}
 
$closer = $tokens[$openBracket]['parenthesis_closer'];
 
if ($tokens[($closer - 1)]['code'] === T_WHITESPACE) {
// Checking this: $value = my_function(...[*]).
$between = $phpcsFile->findNext(T_WHITESPACE, ($openBracket + 1), null, true);
 
// Only throw an error if there is some content between the parenthesis.
// i.e., Checking for this: $value = my_function().
// If there is no content, then we would have thrown an error in the
// previous IF statement because it would look like this:
// $value = my_function( ).
if ($between !== $closer) {
$error = 'Space before closing parenthesis of function call prohibited';
$phpcsFile->addError($error, $closer);
}
}
 
}//end processSingleLineCall()
 
 
/**
* Processes multi-line calls.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
* @param int $openBracket The position of the openning bracket
* in the stack passed in $tokens.
* @param array $tokens The stack of tokens that make up
* the file.
*
* @return void
*/
public function processMultiLineCall(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $tokens)
{
// We need to work out how far indented the function
// call itself is, so we can work out how far to
// indent the arguments.
$functionIndent = 0;
for ($i = ($stackPtr - 1); $i >= 0; $i--) {
if ($tokens[$i]['line'] !== $tokens[$stackPtr]['line']) {
$i++;
break;
}
}
 
if ($tokens[$i]['code'] === T_WHITESPACE) {
$functionIndent = strlen($tokens[$i]['content']);
}
 
// Each line between the parenthesis should be indented 4 spaces.
$closeBracket = $tokens[$openBracket]['parenthesis_closer'];
$lastLine = $tokens[$openBracket]['line'];
for ($i = ($openBracket + 1); $i < $closeBracket; $i++) {
// Skip nested function calls.
if ($tokens[$i]['code'] === T_OPEN_PARENTHESIS) {
$i = $tokens[$i]['parenthesis_closer'];
$lastLine = $tokens[$i]['line'];
continue;
}
 
if ($tokens[$i]['line'] !== $lastLine) {
$lastLine = $tokens[$i]['line'];
 
// We changed lines, so this should be a whitespace indent token.
if (in_array($tokens[$i]['code'], PHP_CodeSniffer_Tokens::$heredocTokens) === true) {
// Ignore heredoc indentation.
continue;
}
 
if (in_array($tokens[$i]['code'], PHP_CodeSniffer_Tokens::$stringTokens) === true) {
if ($tokens[$i]['code'] === $tokens[($i - 1)]['code']) {
// Ignore multi-line string indentation.
continue;
}
}
 
if ($tokens[$i]['line'] === $tokens[$closeBracket]['line']) {
// Closing brace needs to be indented to the same level
// as the function call.
$expectedIndent = $functionIndent;
} else {
$expectedIndent = ($functionIndent + 4);
}
 
if ($tokens[$i]['code'] !== T_WHITESPACE) {
$foundIndent = 0;
} else {
$foundIndent = strlen($tokens[$i]['content']);
}
 
if ($expectedIndent !== $foundIndent) {
$error = "Multi-line function call not indented correctly; expected $expectedIndent spaces but found $foundIndent";
$phpcsFile->addError($error, $i);
}
}//end if
}//end for
 
if ($tokens[($openBracket + 1)]['content'] !== $phpcsFile->eolChar) {
$error = 'Opening parenthesis of a multi-line function call must be the last content on the line';
$phpcsFile->addError($error, $stackPtr);
}
 
$prev = $phpcsFile->findPrevious(T_WHITESPACE, ($closeBracket - 1), null, true);
if ($tokens[$prev]['line'] === $tokens[$closeBracket]['line']) {
$error = 'Closing parenthesis of a multi-line function call must be on a line by itself';
$phpcsFile->addError($error, $closeBracket);
}
 
}//end processMultiLineCall()
 
 
}//end class
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Formatting/MultiLineAssignmentSniff.php
New file
0,0 → 1,110
<?php
/**
* PEAR_Sniffs_Functions_FunctionDeclarationSniff.
*
* 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: MultiLineAssignmentSniff.php,v 1.2 2008/12/01 05:02:12 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* PEAR_Sniffs_Formatting_MultiLineAssignmentSniff.
*
* If an assignment goes over two lines, ensure the equal sign is indented.
*
* @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 PEAR_Sniffs_Formatting_MultiLineAssignmentSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_EQUAL);
 
}//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();
 
// Equal sign can't be the last thing on the line.
$next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
if ($next === false) {
// Bad assignment.
return;
}
 
if ($tokens[$next]['line'] !== $tokens[$stackPtr]['line']) {
$error = 'Multi-line assignments must have the equal sign on the second line';
$phpcsFile->addError($error, $stackPtr);
return;
}
 
// Make sure it is the first thing on the line, otherwise we ignore it.
$prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), false, true);
if ($prev === false) {
// Bad assignment.
return;
}
 
if ($tokens[$prev]['line'] === $tokens[$stackPtr]['line']) {
return;
}
 
// Find the required indent based on the ident of the previous line.
$assignmentIndent = 0;
$prevLine = $tokens[$prev]['line'];
for ($i = ($prev - 1); $i >= 0; $i--) {
if ($tokens[$i]['line'] !== $prevLine) {
$i++;
break;
}
}
 
if ($tokens[$i]['code'] === T_WHITESPACE) {
$assignmentIndent = strlen($tokens[$i]['content']);
}
 
// Find the actual indent.
$prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1));
 
$expectedIndent = ($assignmentIndent + 4);
$foundIndent = strlen($tokens[$prev]['content']);
if ($foundIndent !== $expectedIndent) {
$error = "Multi-line assignment not indented correctly; expected $expectedIndent spaces but found $foundIndent";
$phpcsFile->addError($error, $stackPtr);
}
 
}//end process()
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/WhiteSpace/ScopeIndentSniff.php
New file
0,0 → 1,49
<?php
/**
* PEAR_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/03/03 02:51:39 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('Generic_Sniffs_WhiteSpace_ScopeIndentSniff', true) === false) {
$error = 'Class Generic_Sniffs_WhiteSpace_ScopeIndentSniff not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
/**
* PEAR_Sniffs_Whitespace_ScopeIndentSniff.
*
* Checks that control structures are structured correctly, and their content
* is indented correctly.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_WhiteSpace_ScopeIndentSniff extends Generic_Sniffs_WhiteSpace_ScopeIndentSniff
{
 
/**
* Any scope openers that should not cause an indent.
*
* @var array(int)
*/
protected $nonIndentingScopes = array(T_SWITCH);
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/WhiteSpace/ObjectOperatorIndentSniff.php
New file
0,0 → 1,158
<?php
/**
* PEAR_Sniffs_WhiteSpace_ObjectOperatorIndentSniff.
*
* 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: ObjectOperatorIndentSniff.php,v 1.2 2009/02/20 00:26:47 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* PEAR_Sniffs_WhiteSpace_ObjectOperatorIndentSniff.
*
* Checks that object operators are indented 4 spaces if they are the first
* thing on a line.
*
* @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 PEAR_Sniffs_WhiteSpace_ObjectOperatorIndentSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_OBJECT_OPERATOR);
 
}//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 the first object operator in a chain of them.
$prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
if ($prev === false || $tokens[$prev]['code'] !== T_VARIABLE) {
return;
}
 
// Make sure this is a chained call.
$next = $phpcsFile->findNext(
T_OBJECT_OPERATOR,
($stackPtr + 1),
null,
false,
null,
true
);
 
if ($next === false) {
// Not a chained call.
return;
}
 
// Determine correct indent.
for ($i = ($stackPtr - 1); $i >= 0; $i--) {
if ($tokens[$i]['line'] !== $tokens[$stackPtr]['line']) {
$i++;
break;
}
}
 
$requiredIndent = 0;
if ($tokens[$i]['code'] === T_WHITESPACE) {
$requiredIndent = strlen($tokens[$i]['content']);
}
 
$requiredIndent += 4;
 
// Determine the scope of the original object operator.
$origBrackets = null;
if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
$origBrackets = $tokens[$stackPtr]['nested_parenthesis'];
}
 
$origConditions = null;
if (isset($tokens[$stackPtr]['conditions']) === true) {
$origConditions = $tokens[$stackPtr]['conditions'];
}
 
// Check indentation of each object operator in the chain.
while ($next !== false) {
// Make sure it is in the same scope, otherwise dont check indent.
$brackets = null;
if (isset($tokens[$next]['nested_parenthesis']) === true) {
$brackets = $tokens[$next]['nested_parenthesis'];
}
 
$conditions = null;
if (isset($tokens[$next]['conditions']) === true) {
$conditions = $tokens[$next]['conditions'];
}
 
if ($origBrackets === $brackets && $origConditions === $conditions) {
// Make sure it starts a line, otherwise dont check indent.
$indent = $tokens[($next - 1)];
if ($indent['code'] === T_WHITESPACE) {
if ($indent['line'] === $tokens[$next]['line']) {
$foundIndent = strlen($indent['content']);
} else {
$foundIndent = 0;
}
 
if ($foundIndent !== $requiredIndent) {
$error = "Object operator not indented correctly; expected $requiredIndent spaces but found $foundIndent";
$phpcsFile->addError($error, $next);
}
}
 
// It cant be the last thing on the line either.
$content = $phpcsFile->findNext(T_WHITESPACE, ($next + 1), null, true);
if ($tokens[$content]['line'] !== $tokens[$next]['line']) {
$error = 'Object operator must be at the start of the line, not the end';
$phpcsFile->addError($error, $next);
}
}//end if
 
$next = $phpcsFile->findNext(
T_OBJECT_OPERATOR,
($next + 1),
null,
false,
null,
true
);
}//end while
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php
New file
0,0 → 1,128
<?php
/**
* PEAR_Sniffs_Whitespace_ScopeClosingBraceSniff.
*
* 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: ScopeClosingBraceSniff.php,v 1.10 2008/12/08 05:59:29 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* PEAR_Sniffs_Whitespace_ScopeClosingBraceSniff.
*
* Checks that the closing braces of scopes are aligned correctly.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_WhiteSpace_ScopeClosingBraceSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* 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_closer']) === false) {
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 - 1);
for ($lineStart; $lineStart > 0; $lineStart--) {
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 + 1),
null,
true
);
 
$startColumn = $tokens[$lineStart]['column'];
$scopeStart = $tokens[$stackPtr]['scope_opener'];
$scopeEnd = $tokens[$stackPtr]['scope_closer'];
 
// Check that the closing brace is on it's own line.
$lastContent = $phpcsFile->findPrevious(
array(T_WHITESPACE),
($scopeEnd - 1),
$scopeStart,
true
);
 
if ($tokens[$lastContent]['line'] === $tokens[$scopeEnd]['line']) {
$error = 'Closing brace must be on a line by itself';
$phpcsFile->addError($error, $scopeEnd);
return;
}
 
// Check now that the closing brace is lined up correctly.
$braceIndent = $tokens[$scopeEnd]['column'];
$isBreakCloser = ($tokens[$scopeEnd]['code'] === T_BREAK);
if (in_array($tokens[$stackPtr]['code'], array(T_CASE, T_DEFAULT)) === true
&& $isBreakCloser === true
) {
// BREAK statements should be indented 4 spaces from the
// CASE or DEFAULT statement.
if ($braceIndent !== ($startColumn + 4)) {
$error = 'Break statement indented incorrectly; expected '.($startColumn + 3).' spaces, found '.($braceIndent - 1);
$phpcsFile->addError($error, $scopeEnd);
}
} else {
if ($braceIndent !== $startColumn) {
$error = 'Closing brace indented incorrectly; expected '.($startColumn - 1).' spaces, found '.($braceIndent - 1);
$phpcsFile->addError($error, $scopeEnd);
}
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Classes/ClassDeclarationSniff.php
New file
0,0 → 1,116
<?php
/**
* Class Declaration Test.
*
* 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: ClassDeclarationSniff.php,v 1.5 2008/05/19 05:59:25 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Class Declaration Test.
*
* Checks the declaration of the class is correct.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_Classes_ClassDeclarationSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_CLASS,
T_INTERFACE,
);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
if (isset($tokens[$stackPtr]['scope_opener']) === false) {
$error = 'Possible parse error: ';
$error .= $tokens[$stackPtr]['content'];
$error .= ' missing opening or closing brace';
$phpcsFile->addWarning($error, $stackPtr);
return;
}
 
$curlyBrace = $tokens[$stackPtr]['scope_opener'];
$lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($curlyBrace - 1), $stackPtr, true);
$classLine = $tokens[$lastContent]['line'];
$braceLine = $tokens[$curlyBrace]['line'];
if ($braceLine === $classLine) {
$error = 'Opening brace of a ';
$error .= $tokens[$stackPtr]['content'];
$error .= ' must be on the line after the definition';
$phpcsFile->addError($error, $curlyBrace);
return;
} else if ($braceLine > ($classLine + 1)) {
$difference = ($braceLine - $classLine - 1);
$difference .= ($difference === 1) ? ' line' : ' lines';
$error = 'Opening brace of a ';
$error .= $tokens[$stackPtr]['content'];
$error .= ' must be on the line following the ';
$error .= $tokens[$stackPtr]['content'];
$error .= ' declaration; found '.$difference;
$phpcsFile->addError($error, $curlyBrace);
return;
}
 
if ($tokens[($curlyBrace + 1)]['content'] !== $phpcsFile->eolChar) {
$type = strtolower($tokens[$stackPtr]['content']);
$error = "Opening $type brace must be on a line by itself";
$phpcsFile->addError($error, $curlyBrace);
}
 
if ($tokens[($curlyBrace - 1)]['code'] === T_WHITESPACE) {
$prevContent = $tokens[($curlyBrace - 1)]['content'];
if ($prevContent !== $phpcsFile->eolChar) {
$blankSpace = substr($prevContent, strpos($prevContent, $phpcsFile->eolChar));
$spaces = strlen($blankSpace);
if ($spaces !== 0) {
$error = "Expected 0 spaces before opening brace; $spaces found";
$phpcsFile->addError($error, $curlyBrace);
}
}
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidClassNameSniff.php
New file
0,0 → 1,113
<?php
/**
* PEAR_Sniffs_NamingConventions_ValidClassNameSniff.
*
* 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: ValidClassNameSniff.php,v 1.10 2008/04/28 01:02:28 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* PEAR_Sniffs_NamingConventions_ValidClassNameSniff.
*
* Ensures class and interface names start with a capital letter
* and use _ separators.
*
* @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 PEAR_Sniffs_NamingConventions_ValidClassNameSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_CLASS,
T_INTERFACE,
);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The current file being processed.
* @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();
 
$className = $phpcsFile->findNext(T_STRING, $stackPtr);
$name = trim($tokens[$className]['content']);
 
// Make sure the first letter is a capital.
if (preg_match('|^[A-Z]|', $name) === 0) {
$error = ucfirst($tokens[$stackPtr]['content']).' name must begin with a capital letter';
$phpcsFile->addError($error, $stackPtr);
}
 
// Check that each new word starts with a capital as well, but don't
// check the first word, as it is checked above.
$validName = true;
$nameBits = explode('_', $name);
$firstBit = array_shift($nameBits);
foreach ($nameBits as $bit) {
if ($bit === '' || $bit{0} !== strtoupper($bit{0})) {
$validName = false;
break;
}
}
 
if ($validName !== true) {
// Strip underscores because they cause the suggested name
// to be incorrect.
$nameBits = explode('_', trim($name, '_'));
$firstBit = array_shift($nameBits);
if ($firstBit === '') {
$error = ucfirst($tokens[$stackPtr]['content']).' name is not valid';
} else {
$newName = strtoupper($firstBit{0}).substr($firstBit, 1).'_';
foreach ($nameBits as $bit) {
if ($bit !== '') {
$newName .= strtoupper($bit{0}).substr($bit, 1).'_';
}
}
 
$newName = rtrim($newName, '_');
$error = ucfirst($tokens[$stackPtr]['content'])." name is not valid; consider $newName instead";
}
 
$phpcsFile->addError($error, $stackPtr);
}//end if
 
}//end process()
 
 
}//end class
 
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidFunctionNameSniff.php
New file
0,0 → 1,263
<?php
/**
* PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ValidFunctionNameSniff.php,v 1.18 2008/01/22 23:50:23 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false) {
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found');
}
 
/**
* PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff.
*
* Ensures method names are correct depending on whether they are public
* or private, and that functions are named correctly.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff
{
 
/**
* A list of all PHP magic methods.
*
* @var array
*/
private $_magicMethods = array(
'construct',
'destruct',
'call',
'callStatic',
'get',
'set',
'isset',
'unset',
'sleep',
'wakeup',
'toString',
'set_state',
'clone',
);
 
/**
* A list of all PHP magic functions.
*
* @var array
*/
private $_magicFunctions = array(
'autoload',
);
 
 
/**
* Constructs a PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff.
*/
public function __construct()
{
parent::__construct(array(T_CLASS, T_INTERFACE), array(T_FUNCTION), true);
 
}//end __construct()
 
 
/**
* Processes the tokens within the scope.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being processed.
* @param int $stackPtr The position where this token was
* found.
* @param int $currScope The position of the current scope.
*
* @return void
*/
protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
{
$className = $phpcsFile->getDeclarationName($currScope);
$methodName = $phpcsFile->getDeclarationName($stackPtr);
 
// Is this a magic method. IE. is prefixed with "__".
if (preg_match('|^__|', $methodName) !== 0) {
$magicPart = substr($methodName, 2);
if (in_array($magicPart, $this->_magicMethods) === false) {
$error = "Method name \"$className::$methodName\" is invalid; only PHP magic methods should be prefixed with a double underscore";
$phpcsFile->addError($error, $stackPtr);
}
 
return;
}
 
// PHP4 constructors are allowed to break our rules.
if ($methodName === $className) {
return;
}
 
// PHP4 destructors are allowed to break our rules.
if ($methodName === '_'.$className) {
return;
}
 
$methodProps = $phpcsFile->getMethodProperties($stackPtr);
$isPublic = ($methodProps['scope'] === 'private') ? false : true;
$scope = $methodProps['scope'];
$scopeSpecified = $methodProps['scope_specified'];
 
// If it's a private method, it must have an underscore on the front.
if ($isPublic === false && $methodName{0} !== '_') {
$error = "Private method name \"$className::$methodName\" must be prefixed with an underscore";
$phpcsFile->addError($error, $stackPtr);
return;
}
 
// If it's not a private method, it must not have an underscore on the front.
if ($isPublic === true && $scopeSpecified === true && $methodName{0} === '_') {
$error = ucfirst($scope)." method name \"$className::$methodName\" must not be prefixed with an underscore";
$phpcsFile->addError($error, $stackPtr);
return;
}
 
// If the scope was specified on the method, then the method must be
// camel caps and an underscore should be checked for. If it wasn't
// specified, treat it like a public method and remove the underscore
// prefix if there is one because we cant determine if it is private or
// public.
$testMethodName = $methodName;
if ($scopeSpecified === false && $methodName{0} === '_') {
$testMethodName = substr($methodName, 1);
}
 
if (PHP_CodeSniffer::isCamelCaps($testMethodName, false, $isPublic, false) === false) {
if ($scopeSpecified === true) {
$error = ucfirst($scope)." method name \"$className::$methodName\" is not in camel caps format";
} else {
$error = "Method name \"$className::$methodName\" is not in camel caps format";
}
 
$phpcsFile->addError($error, $stackPtr);
return;
}
 
}//end processTokenWithinScope()
 
 
/**
* Processes the tokens outside the scope.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being processed.
* @param int $stackPtr The position where this token was
* found.
*
* @return void
*/
protected function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$functionName = $phpcsFile->getDeclarationName($stackPtr);
 
// Is this a magic function. IE. is prefixed with "__".
if (preg_match('|^__|', $functionName) !== 0) {
$magicPart = substr($functionName, 2);
if (in_array($magicPart, $this->_magicFunctions) === false) {
$error = "Function name \"$functionName\" is invalid; only PHP magic methods should be prefixed with a double underscore";
$phpcsFile->addError($error, $stackPtr);
}
 
return;
}
 
// Function names can be in two parts; the package name and
// the function name.
$packagePart = '';
$camelCapsPart = '';
$underscorePos = strrpos($functionName, '_');
if ($underscorePos === false) {
$camelCapsPart = $functionName;
} else {
$packagePart = substr($functionName, 0, $underscorePos);
$camelCapsPart = substr($functionName, ($underscorePos + 1));
 
// We don't care about _'s on the front.
$packagePart = ltrim($packagePart, '_');
}
 
// If it has a package part, make sure the first letter is a capital.
if ($packagePart !== '') {
if ($functionName{0} === '_') {
$error = "Function name \"$functionName\" is invalid; only private methods should be prefixed with an underscore";
$phpcsFile->addError($error, $stackPtr);
return;
}
 
if ($functionName{0} !== strtoupper($functionName{0})) {
$error = "Function name \"$functionName\" is prefixed with a package name but does not begin with a capital letter";
$phpcsFile->addError($error, $stackPtr);
return;
}
}
 
// If it doesn't have a camel caps part, it's not valid.
if (trim($camelCapsPart) === '') {
$error = "Function name \"$functionName\" is not valid; name appears incomplete";
$phpcsFile->addError($error, $stackPtr);
return;
}
 
$validName = true;
$newPackagePart = $packagePart;
$newCamelCapsPart = $camelCapsPart;
 
// Every function must have a camel caps part, so check that first.
if (PHP_CodeSniffer::isCamelCaps($camelCapsPart, false, true, false) === false) {
$validName = false;
$newCamelCapsPart = strtolower($camelCapsPart{0}).substr($camelCapsPart, 1);
}
 
if ($packagePart !== '') {
// Check that each new word starts with a capital.
$nameBits = explode('_', $packagePart);
foreach ($nameBits as $bit) {
if ($bit{0} !== strtoupper($bit{0})) {
$newPackagePart = '';
foreach ($nameBits as $bit) {
$newPackagePart .= strtoupper($bit{0}).substr($bit, 1).'_';
}
 
$validName = false;
break;
}
}
}
 
if ($validName === false) {
$newName = rtrim($newPackagePart, '_').'_'.$newCamelCapsPart;
if ($newPackagePart === '') {
$newName = $newCamelCapsPart;
} else {
$newName = rtrim($newPackagePart, '_').'_'.$newCamelCapsPart;
}
 
$error = "Function name \"$functionName\" is invalid; consider \"$newName\" instead";
$phpcsFile->addError($error, $stackPtr);
}
 
}//end processTokenOutsideScope()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidVariableNameSniff.php
New file
0,0 → 1,112
<?php
/**
* PEAR_Sniffs_NamingConventions_ValidVariableNameSniff.
*
* 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: ValidVariableNameSniff.php,v 1.2 2008/06/13 04:10:43 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_Standards_AbstractVariableSniff', true) === false) {
$error = 'Class PHP_CodeSniffer_Standards_AbstractVariableSniff not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
/**
* PEAR_Sniffs_NamingConventions_ValidVariableNameSniff.
*
* Checks the naming of member variables.
*
* @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 PEAR_Sniffs_NamingConventions_ValidVariableNameSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff
{
 
 
/**
* Processes class member variables.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
$memberProps = $phpcsFile->getMemberProperties($stackPtr);
if (empty($memberProps) === true) {
return;
}
 
$memberName = ltrim($tokens[$stackPtr]['content'], '$');
$isPublic = ($memberProps['scope'] === 'private') ? false : true;
$scope = $memberProps['scope'];
$scopeSpecified = $memberProps['scope_specified'];
 
// If it's a private member, it must have an underscore on the front.
if ($isPublic === false && $memberName{0} !== '_') {
$error = "Private member variable \"$memberName\" must be prefixed with an underscore";
$phpcsFile->addError($error, $stackPtr);
return;
}
 
// If it's not a private member, it must not have an underscore on the front.
if ($isPublic === true && $scopeSpecified === true && $memberName{0} === '_') {
$error = ucfirst($scope)." member variable \"$memberName\" must not be prefixed with an underscore";
$phpcsFile->addError($error, $stackPtr);
return;
}
 
}//end processMemberVar()
 
 
/**
* Processes normal variables.
*
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
* @param int $stackPtr The position where the token was found.
*
* @return void
*/
protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
// We don't care about normal variables.
return;
 
}//end processVariable()
 
 
/**
* Processes variables in double quoted strings.
*
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
* @param int $stackPtr The position where the token was found.
*
* @return void
*/
protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
// We don't care about normal variables.
return;
 
}//end processVariableInString()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Commenting/ClassCommentSniff.php
New file
0,0 → 1,233
<?php
/**
* Parses and verifies the doc comments for classes.
*
* 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: ClassCommentSniff.php,v 1.19 2008/12/02 02:38:34 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_CommentParser_ClassCommentParser', true) === false) {
$error = 'Class PHP_CodeSniffer_CommentParser_ClassCommentParser not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
if (class_exists('PEAR_Sniffs_Commenting_FileCommentSniff', true) === false) {
$error = 'Class PEAR_Sniffs_Commenting_FileCommentSniff not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
/**
* Parses and verifies the doc comments for classes.
*
* Verifies that :
* <ul>
* <li>A doc comment exists.</li>
* <li>There is a blank newline after the short description.</li>
* <li>There is a blank newline between the long and short description.</li>
* <li>There is a blank newline between the long description and tags.</li>
* <li>Check the order of the tags.</li>
* <li>Check the indentation of each tag.</li>
* <li>Check required and optional tags and the format of their content.</li>
* </ul>
*
* @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 PEAR_Sniffs_Commenting_ClassCommentSniff extends PEAR_Sniffs_Commenting_FileCommentSniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_CLASS,
T_INTERFACE,
);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$this->currentFile = $phpcsFile;
 
$tokens = $phpcsFile->getTokens();
$type = strtolower($tokens[$stackPtr]['content']);
$find = array(
T_ABSTRACT,
T_WHITESPACE,
T_FINAL,
);
 
// Extract the class comment docblock.
$commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true);
 
if ($commentEnd !== false && $tokens[$commentEnd]['code'] === T_COMMENT) {
$error = "You must use \"/**\" style comments for a $type comment";
$phpcsFile->addError($error, $stackPtr);
return;
} else if ($commentEnd === false
|| $tokens[$commentEnd]['code'] !== T_DOC_COMMENT
) {
$phpcsFile->addError("Missing $type doc comment", $stackPtr);
return;
}
 
$commentStart = ($phpcsFile->findPrevious(T_DOC_COMMENT, ($commentEnd - 1), null, true) + 1);
$commentNext = $phpcsFile->findPrevious(T_WHITESPACE, ($commentEnd + 1), $stackPtr, false, $phpcsFile->eolChar);
 
// Distinguish file and class comment.
$prevClassToken = $phpcsFile->findPrevious(T_CLASS, ($stackPtr - 1));
if ($prevClassToken === false) {
// This is the first class token in this file, need extra checks.
$prevNonComment = $phpcsFile->findPrevious(T_DOC_COMMENT, ($commentStart - 1), null, true);
if ($prevNonComment !== false) {
$prevComment = $phpcsFile->findPrevious(T_DOC_COMMENT, ($prevNonComment - 1));
if ($prevComment === false) {
// There is only 1 doc comment between open tag and class token.
$newlineToken = $phpcsFile->findNext(T_WHITESPACE, ($commentEnd + 1), $stackPtr, false, $phpcsFile->eolChar);
if ($newlineToken !== false) {
$newlineToken = $phpcsFile->findNext(
T_WHITESPACE,
($newlineToken + 1),
$stackPtr,
false,
$phpcsFile->eolChar
);
 
if ($newlineToken !== false) {
// Blank line between the class and the doc block.
// The doc block is most likely a file comment.
$error = "Missing $type doc comment";
$phpcsFile->addError($error, ($stackPtr + 1));
return;
}
}//end if
}//end if
}//end if
}//end if
 
$comment = $phpcsFile->getTokensAsString(
$commentStart,
($commentEnd - $commentStart + 1)
);
 
// Parse the class comment.docblock.
try {
$this->commentParser = new PHP_CodeSniffer_CommentParser_ClassCommentParser($comment, $phpcsFile);
$this->commentParser->parse();
} catch (PHP_CodeSniffer_CommentParser_ParserException $e) {
$line = ($e->getLineWithinComment() + $commentStart);
$phpcsFile->addError($e->getMessage(), $line);
return;
}
 
$comment = $this->commentParser->getComment();
if (is_null($comment) === true) {
$error = ucfirst($type).' doc comment is empty';
$phpcsFile->addError($error, $commentStart);
return;
}
 
// No extra newline before short description.
$short = $comment->getShortComment();
$newlineCount = 0;
$newlineSpan = strspn($short, $phpcsFile->eolChar);
if ($short !== '' && $newlineSpan > 0) {
$line = ($newlineSpan > 1) ? 'newlines' : 'newline';
$error = "Extra $line found before $type comment short description";
$phpcsFile->addError($error, ($commentStart + 1));
}
 
$newlineCount = (substr_count($short, $phpcsFile->eolChar) + 1);
 
// Exactly one blank line between short and long description.
$long = $comment->getLongComment();
if (empty($long) === false) {
$between = $comment->getWhiteSpaceBetween();
$newlineBetween = substr_count($between, $phpcsFile->eolChar);
if ($newlineBetween !== 2) {
$error = "There must be exactly one blank line between descriptions in $type comments";
$phpcsFile->addError($error, ($commentStart + $newlineCount + 1));
}
 
$newlineCount += $newlineBetween;
}
 
// Exactly one blank line before tags.
$tags = $this->commentParser->getTagOrders();
if (count($tags) > 1) {
$newlineSpan = $comment->getNewlineAfter();
if ($newlineSpan !== 2) {
$error = "There must be exactly one blank line before the tags in $type comments";
if ($long !== '') {
$newlineCount += (substr_count($long, $phpcsFile->eolChar) - $newlineSpan + 1);
}
 
$phpcsFile->addError($error, ($commentStart + $newlineCount));
$short = rtrim($short, $phpcsFile->eolChar.' ');
}
}
 
// Check each tag.
$this->processTags($commentStart, $commentEnd);
 
}//end process()
 
 
/**
* Process the version tag.
*
* @param int $errorPos The line number where the error occurs.
*
* @return void
*/
protected function processVersion($errorPos)
{
$version = $this->commentParser->getVersion();
if ($version !== null) {
$content = $version->getContent();
$matches = array();
if (empty($content) === true) {
$error = 'Content missing for @version tag in doc comment';
$this->currentFile->addError($error, $errorPos);
} else if ((strstr($content, 'Release:') === false)) {
$error = "Invalid version \"$content\" in doc comment; consider \"Release: <package_version>\" instead";
$this->currentFile->addWarning($error, $errorPos);
}
}
 
}//end processVersion()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php
New file
0,0 → 1,463
<?php
/**
* Parses and verifies the doc comments 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: FunctionCommentSniff.php,v 1.25 2008/12/17 22:36:41 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_CommentParser_FunctionCommentParser', true) === false) {
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_CommentParser_FunctionCommentParser not found');
}
 
/**
* Parses and verifies the doc comments for functions.
*
* Verifies that :
* <ul>
* <li>A comment exists</li>
* <li>There is a blank newline after the short description.</li>
* <li>There is a blank newline between the long and short description.</li>
* <li>There is a blank newline between the long description and tags.</li>
* <li>Parameter names represent those in the method.</li>
* <li>Parameter comments are in the correct order</li>
* <li>Parameter comments are complete</li>
* <li>A space is present before the first and after the last parameter</li>
* <li>A return type exists</li>
* <li>There must be one blank line between body and headline comments.</li>
* <li>Any throw tag must have an exception class.</li>
* </ul>
*
* @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 PEAR_Sniffs_Commenting_FunctionCommentSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* The name of the method that we are currently processing.
*
* @var string
*/
private $_methodName = '';
 
/**
* The position in the stack where the fucntion token was found.
*
* @var int
*/
private $_functionToken = null;
 
/**
* The position in the stack where the class token was found.
*
* @var int
*/
private $_classToken = null;
 
/**
* The function comment parser for the current method.
*
* @var PHP_CodeSniffer_Comment_Parser_FunctionCommentParser
*/
protected $commentParser = null;
 
/**
* The current PHP_CodeSniffer_File object we are processing.
*
* @var PHP_CodeSniffer_File
*/
protected $currentFile = null;
 
 
/**
* 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)
{
$find = array(
T_COMMENT,
T_DOC_COMMENT,
T_CLASS,
T_FUNCTION,
T_OPEN_TAG,
);
 
$commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1));
 
if ($commentEnd === false) {
return;
}
 
$this->currentFile = $phpcsFile;
$tokens = $phpcsFile->getTokens();
 
// If the token that we found was a class or a function, then this
// function has no doc comment.
$code = $tokens[$commentEnd]['code'];
 
if ($code === T_COMMENT) {
$error = 'You must use "/**" style comments for a function comment';
$phpcsFile->addError($error, $stackPtr);
return;
} else if ($code !== T_DOC_COMMENT) {
$phpcsFile->addError('Missing function doc comment', $stackPtr);
return;
}
 
// If there is any code between the function keyword and the doc block
// then the doc block is not for us.
$ignore = PHP_CodeSniffer_Tokens::$scopeModifiers;
$ignore[] = T_STATIC;
$ignore[] = T_WHITESPACE;
$ignore[] = T_ABSTRACT;
$ignore[] = T_FINAL;
$prevToken = $phpcsFile->findPrevious($ignore, ($stackPtr - 1), null, true);
if ($prevToken !== $commentEnd) {
$phpcsFile->addError('Missing function doc comment', $stackPtr);
return;
}
 
$this->_functionToken = $stackPtr;
 
$this->_classToken = null;
foreach ($tokens[$stackPtr]['conditions'] as $condPtr => $condition) {
if ($condition === T_CLASS || $condition === T_INTERFACE) {
$this->_classToken = $condPtr;
break;
}
}
 
// If the first T_OPEN_TAG is right before the comment, it is probably
// a file comment.
$commentStart = ($phpcsFile->findPrevious(T_DOC_COMMENT, ($commentEnd - 1), null, true) + 1);
$prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($commentStart - 1), null, true);
if ($tokens[$prevToken]['code'] === T_OPEN_TAG) {
// Is this the first open tag?
if ($stackPtr === 0 || $phpcsFile->findPrevious(T_OPEN_TAG, ($prevToken - 1)) === false) {
$phpcsFile->addError('Missing function doc comment', $stackPtr);
return;
}
}
 
$comment = $phpcsFile->getTokensAsString($commentStart, ($commentEnd - $commentStart + 1));
$this->_methodName = $phpcsFile->getDeclarationName($stackPtr);
 
try {
$this->commentParser = new PHP_CodeSniffer_CommentParser_FunctionCommentParser($comment, $phpcsFile);
$this->commentParser->parse();
} catch (PHP_CodeSniffer_CommentParser_ParserException $e) {
$line = ($e->getLineWithinComment() + $commentStart);
$phpcsFile->addError($e->getMessage(), $line);
return;
}
 
$comment = $this->commentParser->getComment();
if (is_null($comment) === true) {
$error = 'Function doc comment is empty';
$phpcsFile->addError($error, $commentStart);
return;
}
 
$this->processParams($commentStart);
$this->processReturn($commentStart, $commentEnd);
$this->processThrows($commentStart);
 
// No extra newline before short description.
$short = $comment->getShortComment();
$newlineCount = 0;
$newlineSpan = strspn($short, $phpcsFile->eolChar);
if ($short !== '' && $newlineSpan > 0) {
$line = ($newlineSpan > 1) ? 'newlines' : 'newline';
$error = "Extra $line found before function comment short description";
$phpcsFile->addError($error, ($commentStart + 1));
}
 
$newlineCount = (substr_count($short, $phpcsFile->eolChar) + 1);
 
// Exactly one blank line between short and long description.
$long = $comment->getLongComment();
if (empty($long) === false) {
$between = $comment->getWhiteSpaceBetween();
$newlineBetween = substr_count($between, $phpcsFile->eolChar);
if ($newlineBetween !== 2) {
$error = 'There must be exactly one blank line between descriptions in function comment';
$phpcsFile->addError($error, ($commentStart + $newlineCount + 1));
}
 
$newlineCount += $newlineBetween;
}
 
// Exactly one blank line before tags.
$params = $this->commentParser->getTagOrders();
if (count($params) > 1) {
$newlineSpan = $comment->getNewlineAfter();
if ($newlineSpan !== 2) {
$error = 'There must be exactly one blank line before the tags in function comment';
if ($long !== '') {
$newlineCount += (substr_count($long, $phpcsFile->eolChar) - $newlineSpan + 1);
}
 
$phpcsFile->addError($error, ($commentStart + $newlineCount));
$short = rtrim($short, $phpcsFile->eolChar.' ');
}
}
 
}//end process()
 
 
/**
* Process any throw tags that this function comment has.
*
* @param int $commentStart The position in the stack where the
* comment started.
*
* @return void
*/
protected function processThrows($commentStart)
{
if (count($this->commentParser->getThrows()) === 0) {
return;
}
 
foreach ($this->commentParser->getThrows() as $throw) {
 
$exception = $throw->getValue();
$errorPos = ($commentStart + $throw->getLine());
 
if ($exception === '') {
$error = '@throws tag must contain the exception class name';
$this->currentFile->addError($error, $errorPos);
}
}
 
}//end processThrows()
 
 
/**
* Process the return comment of this function comment.
*
* @param int $commentStart The position in the stack where the comment started.
* @param int $commentEnd The position in the stack where the comment ended.
*
* @return void
*/
protected function processReturn($commentStart, $commentEnd)
{
// Skip constructor and destructor.
$className = '';
if ($this->_classToken !== null) {
$className = $this->currentFile->getDeclarationName($this->_classToken);
$className = strtolower(ltrim($className, '_'));
}
 
$methodName = strtolower(ltrim($this->_methodName, '_'));
$isSpecialMethod = ($this->_methodName === '__construct' || $this->_methodName === '__destruct');
 
if ($isSpecialMethod === false && $methodName !== $className) {
// Report missing return tag.
if ($this->commentParser->getReturn() === null) {
$error = 'Missing @return tag in function comment';
$this->currentFile->addError($error, $commentEnd);
} else if (trim($this->commentParser->getReturn()->getRawContent()) === '') {
$error = '@return tag is empty in function comment';
$errorPos = ($commentStart + $this->commentParser->getReturn()->getLine());
$this->currentFile->addError($error, $errorPos);
}
}
 
}//end processReturn()
 
 
/**
* Process the function parameter comments.
*
* @param int $commentStart The position in the stack where
* the comment started.
*
* @return void
*/
protected function processParams($commentStart)
{
$realParams = $this->currentFile->getMethodParameters($this->_functionToken);
 
$params = $this->commentParser->getParams();
$foundParams = array();
 
if (empty($params) === false) {
 
$lastParm = (count($params) - 1);
if (substr_count($params[$lastParm]->getWhitespaceAfter(), $this->currentFile->eolChar) !== 2) {
$error = 'Last parameter comment requires a blank newline after it';
$errorPos = ($params[$lastParm]->getLine() + $commentStart);
$this->currentFile->addError($error, $errorPos);
}
 
// Parameters must appear immediately after the comment.
if ($params[0]->getOrder() !== 2) {
$error = 'Parameters must appear immediately after the comment';
$errorPos = ($params[0]->getLine() + $commentStart);
$this->currentFile->addError($error, $errorPos);
}
 
$previousParam = null;
$spaceBeforeVar = 10000;
$spaceBeforeComment = 10000;
$longestType = 0;
$longestVar = 0;
 
foreach ($params as $param) {
 
$paramComment = trim($param->getComment());
$errorPos = ($param->getLine() + $commentStart);
 
// Make sure that there is only one space before the var type.
if ($param->getWhitespaceBeforeType() !== ' ') {
$error = 'Expected 1 space before variable type';
$this->currentFile->addError($error, $errorPos);
}
 
$spaceCount = substr_count($param->getWhitespaceBeforeVarName(), ' ');
if ($spaceCount < $spaceBeforeVar) {
$spaceBeforeVar = $spaceCount;
$longestType = $errorPos;
}
 
$spaceCount = substr_count($param->getWhitespaceBeforeComment(), ' ');
 
if ($spaceCount < $spaceBeforeComment && $paramComment !== '') {
$spaceBeforeComment = $spaceCount;
$longestVar = $errorPos;
}
 
// Make sure they are in the correct order,
// and have the correct name.
$pos = $param->getPosition();
 
$paramName = ($param->getVarName() !== '') ? $param->getVarName() : '[ UNKNOWN ]';
 
if ($previousParam !== null) {
$previousName = ($previousParam->getVarName() !== '') ? $previousParam->getVarName() : 'UNKNOWN';
 
// Check to see if the parameters align properly.
if ($param->alignsVariableWith($previousParam) === false) {
$error = 'The variable names for parameters '.$previousName.' ('.($pos - 1).') and '.$paramName.' ('.$pos.') do not align';
$this->currentFile->addError($error, $errorPos);
}
 
if ($param->alignsCommentWith($previousParam) === false) {
$error = 'The comments for parameters '.$previousName.' ('.($pos - 1).') and '.$paramName.' ('.$pos.') do not align';
$this->currentFile->addError($error, $errorPos);
}
}//end if
 
// Make sure the names of the parameter comment matches the
// actual parameter.
if (isset($realParams[($pos - 1)]) === true) {
$realName = $realParams[($pos - 1)]['name'];
$foundParams[] = $realName;
// Append ampersand to name if passing by reference.
if ($realParams[($pos - 1)]['pass_by_reference'] === true) {
$realName = '&'.$realName;
}
 
if ($realName !== $param->getVarName()) {
$error = 'Doc comment var "'.$paramName;
$error .= '" does not match actual variable name "'.$realName;
$error .= '" at position '.$pos;
 
$this->currentFile->addError($error, $errorPos);
}
} else {
// We must have an extra parameter comment.
$error = 'Superfluous doc comment at position '.$pos;
$this->currentFile->addError($error, $errorPos);
}
 
if ($param->getVarName() === '') {
$error = 'Missing parameter name at position '.$pos;
$this->currentFile->addError($error, $errorPos);
}
 
if ($param->getType() === '') {
$error = 'Missing type at position '.$pos;
$this->currentFile->addError($error, $errorPos);
}
 
if ($paramComment === '') {
$error = 'Missing comment for param "'.$paramName.'" at position '.$pos;
$this->currentFile->addError($error, $errorPos);
}
 
$previousParam = $param;
 
}//end foreach
 
if ($spaceBeforeVar !== 1 && $spaceBeforeVar !== 10000 && $spaceBeforeComment !== 10000) {
$error = 'Expected 1 space after the longest type';
$this->currentFile->addError($error, $longestType);
}
 
if ($spaceBeforeComment !== 1 && $spaceBeforeComment !== 10000) {
$error = 'Expected 1 space after the longest variable name';
$this->currentFile->addError($error, $longestVar);
}
 
}//end if
 
$realNames = array();
foreach ($realParams as $realParam) {
$realNames[] = $realParam['name'];
}
 
// Report and missing comments.
$diff = array_diff($realNames, $foundParams);
foreach ($diff as $neededParam) {
if (count($params) !== 0) {
$errorPos = ($params[(count($params) - 1)]->getLine() + $commentStart);
} else {
$errorPos = $commentStart;
}
 
$error = 'Doc comment for "'.$neededParam.'" missing';
$this->currentFile->addError($error, $errorPos);
}
 
}//end processParams()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Commenting/InlineCommentSniff.php
New file
0,0 → 1,71
<?php
/**
* PHP_CodeSniffer_Sniffs_PEAR_Commenting_InlineCommentSniff.
*
* 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: InlineCommentSniff.php,v 1.5 2008/12/02 02:38:34 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* PHP_CodeSniffer_Sniffs_PEAR_Commenting_InlineCommentSniff.
*
* Checks that no perl-style comments are 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 PEAR_Sniffs_Commenting_InlineCommentSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_COMMENT);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
if ($tokens[$stackPtr]['content']{0} === '#') {
$error = 'Perl-style comments are not allowed. Use "// Comment."';
$error .= ' or "/* comment */" instead.';
$phpcsFile->addError($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Commenting/FileCommentSniff.php
New file
0,0 → 1,762
<?php
/**
* Parses and verifies the doc comments for files.
*
* 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: FileCommentSniff.php,v 1.32 2009/02/10 06:01:46 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_CommentParser_ClassCommentParser', true) === false) {
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_CommentParser_ClassCommentParser not found');
}
 
/**
* Parses and verifies the doc comments for files.
*
* Verifies that :
* <ul>
* <li>A doc comment exists.</li>
* <li>There is a blank newline after the short description.</li>
* <li>There is a blank newline between the long and short description.</li>
* <li>There is a blank newline between the long description and tags.</li>
* <li>A PHP version is specified.</li>
* <li>Check the order of the tags.</li>
* <li>Check the indentation of each tag.</li>
* <li>Check required and optional tags and the format of their content.</li>
* </ul>
*
* @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 PEAR_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* The header comment parser for the current file.
*
* @var PHP_CodeSniffer_Comment_Parser_ClassCommentParser
*/
protected $commentParser = null;
 
/**
* The current PHP_CodeSniffer_File object we are processing.
*
* @var PHP_CodeSniffer_File
*/
protected $currentFile = null;
 
/**
* Tags in correct order and related info.
*
* @var array
*/
protected $tags = array(
'category' => array(
'required' => true,
'allow_multiple' => false,
'order_text' => 'precedes @package',
),
'package' => array(
'required' => true,
'allow_multiple' => false,
'order_text' => 'follows @category',
),
'subpackage' => array(
'required' => false,
'allow_multiple' => false,
'order_text' => 'follows @package',
),
'author' => array(
'required' => true,
'allow_multiple' => true,
'order_text' => 'follows @subpackage (if used) or @package',
),
'copyright' => array(
'required' => false,
'allow_multiple' => true,
'order_text' => 'follows @author',
),
'license' => array(
'required' => true,
'allow_multiple' => false,
'order_text' => 'follows @copyright (if used) or @author',
),
'version' => array(
'required' => false,
'allow_multiple' => false,
'order_text' => 'follows @license',
),
'link' => array(
'required' => true,
'allow_multiple' => true,
'order_text' => 'follows @version',
),
'see' => array(
'required' => false,
'allow_multiple' => true,
'order_text' => 'follows @link',
),
'since' => array(
'required' => false,
'allow_multiple' => false,
'order_text' => 'follows @see (if used) or @link',
),
'deprecated' => array(
'required' => false,
'allow_multiple' => false,
'order_text' => 'follows @since (if used) or @see (if used) or @link',
),
);
 
 
/**
* 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)
{
$this->currentFile = $phpcsFile;
 
// We are only interested if this is the first open tag.
if ($stackPtr !== 0) {
if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) {
return;
}
}
 
$tokens = $phpcsFile->getTokens();
 
// Find the next non whitespace token.
$commentStart
= $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
 
// Allow declare() statements at the top of the file.
if ($tokens[$commentStart]['code'] === T_DECLARE) {
$semicolon = $phpcsFile->findNext(T_SEMICOLON, ($commentStart + 1));
$commentStart
= $phpcsFile->findNext(T_WHITESPACE, ($semicolon + 1), null, true);
}
 
// Ignore vim header.
if ($tokens[$commentStart]['code'] === T_COMMENT) {
if (strstr($tokens[$commentStart]['content'], 'vim:') !== false) {
$commentStart = $phpcsFile->findNext(
T_WHITESPACE,
($commentStart + 1),
null,
true
);
}
}
 
$errorToken = ($stackPtr + 1);
if (isset($tokens[$errorToken]) === false) {
$errorToken--;
}
 
if ($tokens[$commentStart]['code'] === T_CLOSE_TAG) {
// We are only interested if this is the first open tag.
return;
} else if ($tokens[$commentStart]['code'] === T_COMMENT) {
$error = 'You must use "/**" style comments for a file comment';
$phpcsFile->addError($error, $errorToken);
return;
} else if ($commentStart === false
|| $tokens[$commentStart]['code'] !== T_DOC_COMMENT
) {
$phpcsFile->addError('Missing file doc comment', $errorToken);
return;
} else {
 
// Extract the header comment docblock.
$commentEnd = $phpcsFile->findNext(
T_DOC_COMMENT,
($commentStart + 1),
null,
true
);
 
$commentEnd--;
 
// Check if there is only 1 doc comment between the
// open tag and class token.
$nextToken = array(
T_ABSTRACT,
T_CLASS,
T_FUNCTION,
T_DOC_COMMENT,
);
 
$commentNext = $phpcsFile->findNext($nextToken, ($commentEnd + 1));
if ($commentNext !== false
&& $tokens[$commentNext]['code'] !== T_DOC_COMMENT
) {
// Found a class token right after comment doc block.
$newlineToken = $phpcsFile->findNext(
T_WHITESPACE,
($commentEnd + 1),
$commentNext,
false,
$phpcsFile->eolChar
);
 
if ($newlineToken !== false) {
$newlineToken = $phpcsFile->findNext(
T_WHITESPACE,
($newlineToken + 1),
$commentNext,
false,
$phpcsFile->eolChar
);
 
if ($newlineToken === false) {
// No blank line between the class token and the doc block.
// The doc block is most likely a class comment.
$error = 'Missing file doc comment';
$phpcsFile->addError($error, $errorToken);
return;
}
}
}//end if
 
$comment = $phpcsFile->getTokensAsString(
$commentStart,
($commentEnd - $commentStart + 1)
);
 
// Parse the header comment docblock.
try {
$this->commentParser = new PHP_CodeSniffer_CommentParser_ClassCommentParser($comment, $phpcsFile);
$this->commentParser->parse();
} catch (PHP_CodeSniffer_CommentParser_ParserException $e) {
$line = ($e->getLineWithinComment() + $commentStart);
$phpcsFile->addError($e->getMessage(), $line);
return;
}
 
$comment = $this->commentParser->getComment();
if (is_null($comment) === true) {
$error = 'File doc comment is empty';
$phpcsFile->addError($error, $commentStart);
return;
}
 
// No extra newline before short description.
$short = $comment->getShortComment();
$newlineCount = 0;
$newlineSpan = strspn($short, $phpcsFile->eolChar);
if ($short !== '' && $newlineSpan > 0) {
$line = ($newlineSpan > 1) ? 'newlines' : 'newline';
$error = "Extra $line found before file comment short description";
$phpcsFile->addError($error, ($commentStart + 1));
}
 
$newlineCount = (substr_count($short, $phpcsFile->eolChar) + 1);
 
// Exactly one blank line between short and long description.
$long = $comment->getLongComment();
if (empty($long) === false) {
$between = $comment->getWhiteSpaceBetween();
$newlineBetween = substr_count($between, $phpcsFile->eolChar);
if ($newlineBetween !== 2) {
$error = 'There must be exactly one blank line between descriptions in file comment';
$phpcsFile->addError($error, ($commentStart + $newlineCount + 1));
}
 
$newlineCount += $newlineBetween;
}
 
// Exactly one blank line before tags.
$tags = $this->commentParser->getTagOrders();
if (count($tags) > 1) {
$newlineSpan = $comment->getNewlineAfter();
if ($newlineSpan !== 2) {
$error = 'There must be exactly one blank line before the tags in file comment';
if ($long !== '') {
$newlineCount += (substr_count($long, $phpcsFile->eolChar) - $newlineSpan + 1);
}
 
$phpcsFile->addError($error, ($commentStart + $newlineCount));
$short = rtrim($short, $phpcsFile->eolChar.' ');
}
}
 
// Check the PHP Version.
$this->processPHPVersion($commentStart, $commentEnd, $long);
 
// Check each tag.
$this->processTags($commentStart, $commentEnd);
}//end if
 
}//end process()
 
 
/**
* Check that the PHP version is specified.
*
* @param int $commentStart Position in the stack where the comment started.
* @param int $commentEnd Position in the stack where the comment ended.
* @param string $comment The text of the function comment.
*
* @return void
*/
protected function processPHPVersion($commentStart, $commentEnd, $commentText)
{
if (strstr(strtolower($commentText), 'php version') === false) {
$error = 'PHP version not specified';
$this->currentFile->addWarning($error, $commentEnd);
}
 
}//end processPHPVersion()
 
 
/**
* Processes each required or optional tag.
*
* @param int $commentStart Position in the stack where the comment started.
* @param int $commentEnd Position in the stack where the comment ended.
*
* @return void
*/
protected function processTags($commentStart, $commentEnd)
{
$docBlock = (get_class($this) === 'PEAR_Sniffs_Commenting_FileCommentSniff') ? 'file' : 'class';
$foundTags = $this->commentParser->getTagOrders();
$orderIndex = 0;
$indentation = array();
$longestTag = 0;
$errorPos = 0;
 
foreach ($this->tags as $tag => $info) {
 
// Required tag missing.
if ($info['required'] === true && in_array($tag, $foundTags) === false) {
$error = "Missing @$tag tag in $docBlock comment";
$this->currentFile->addError($error, $commentEnd);
continue;
}
 
// Get the line number for current tag.
$tagName = ucfirst($tag);
if ($info['allow_multiple'] === true) {
$tagName .= 's';
}
 
$getMethod = 'get'.$tagName;
$tagElement = $this->commentParser->$getMethod();
if (is_null($tagElement) === true || empty($tagElement) === true) {
continue;
}
 
$errorPos = $commentStart;
if (is_array($tagElement) === false) {
$errorPos = ($commentStart + $tagElement->getLine());
}
 
// Get the tag order.
$foundIndexes = array_keys($foundTags, $tag);
 
if (count($foundIndexes) > 1) {
// Multiple occurance not allowed.
if ($info['allow_multiple'] === false) {
$error = "Only 1 @$tag tag is allowed in a $docBlock comment";
$this->currentFile->addError($error, $errorPos);
} else {
// Make sure same tags are grouped together.
$i = 0;
$count = $foundIndexes[0];
foreach ($foundIndexes as $index) {
if ($index !== $count) {
$errorPosIndex
= ($errorPos + $tagElement[$i]->getLine());
$error = "@$tag tags must be grouped together";
$this->currentFile->addError($error, $errorPosIndex);
}
 
$i++;
$count++;
}
}
}//end if
 
// Check tag order.
if ($foundIndexes[0] > $orderIndex) {
$orderIndex = $foundIndexes[0];
} else {
if (is_array($tagElement) === true && empty($tagElement) === false) {
$errorPos += $tagElement[0]->getLine();
}
 
$orderText = $info['order_text'];
$error = "The @$tag tag is in the wrong order; the tag $orderText";
$this->currentFile->addError($error, $errorPos);
}
 
// Store the indentation for checking.
$len = strlen($tag);
if ($len > $longestTag) {
$longestTag = $len;
}
 
if (is_array($tagElement) === true) {
foreach ($tagElement as $key => $element) {
$indentation[] = array(
'tag' => $tag,
'space' => $this->getIndentation($tag, $element),
'line' => $element->getLine(),
);
}
} else {
$indentation[] = array(
'tag' => $tag,
'space' => $this->getIndentation($tag, $tagElement),
);
}
 
$method = 'process'.$tagName;
if (method_exists($this, $method) === true) {
// Process each tag if a method is defined.
call_user_func(array($this, $method), $errorPos);
} else {
if (is_array($tagElement) === true) {
foreach ($tagElement as $key => $element) {
$element->process(
$this->currentFile,
$commentStart,
$docBlock
);
}
} else {
$tagElement->process(
$this->currentFile,
$commentStart,
$docBlock
);
}
}
}//end foreach
 
foreach ($indentation as $indentInfo) {
if ($indentInfo['space'] !== 0
&& $indentInfo['space'] !== ($longestTag + 1)
) {
$expected = (($longestTag - strlen($indentInfo['tag'])) + 1);
$space = ($indentInfo['space'] - strlen($indentInfo['tag']));
$error = "@$indentInfo[tag] tag comment indented incorrectly. ";
$error .= "Expected $expected spaces but found $space.";
 
$getTagMethod = 'get'.ucfirst($indentInfo['tag']);
 
if ($this->tags[$indentInfo['tag']]['allow_multiple'] === true) {
$line = $indentInfo['line'];
} else {
$tagElem = $this->commentParser->$getTagMethod();
$line = $tagElem->getLine();
}
 
$this->currentFile->addError($error, ($commentStart + $line));
}
}
 
}//end processTags()
 
 
/**
* Get the indentation information of each tag.
*
* @param string $tagName The name of the
* doc comment
* element.
* @param PHP_CodeSniffer_CommentParser_DocElement $tagElement The doc comment
* element.
*
* @return void
*/
protected function getIndentation($tagName, $tagElement)
{
if ($tagElement instanceof PHP_CodeSniffer_CommentParser_SingleElement) {
if ($tagElement->getContent() !== '') {
return (strlen($tagName) + substr_count($tagElement->getWhitespaceBeforeContent(), ' '));
}
} else if ($tagElement instanceof PHP_CodeSniffer_CommentParser_PairElement) {
if ($tagElement->getValue() !== '') {
return (strlen($tagName) + substr_count($tagElement->getWhitespaceBeforeValue(), ' '));
}
}
 
return 0;
 
}//end getIndentation()
 
 
/**
* Process the category tag.
*
* @param int $errorPos The line number where the error occurs.
*
* @return void
*/
protected function processCategory($errorPos)
{
$category = $this->commentParser->getCategory();
if ($category !== null) {
$content = $category->getContent();
if ($content !== '') {
if (PHP_CodeSniffer::isUnderscoreName($content) !== true) {
$newContent = str_replace(' ', '_', $content);
$nameBits = explode('_', $newContent);
$firstBit = array_shift($nameBits);
$newName = ucfirst($firstBit).'_';
foreach ($nameBits as $bit) {
$newName .= ucfirst($bit).'_';
}
 
$validName = trim($newName, '_');
$error = "Category name \"$content\" is not valid; consider \"$validName\" instead";
$this->currentFile->addError($error, $errorPos);
}
} else {
$error = '@category tag must contain a name';
$this->currentFile->addError($error, $errorPos);
}
}
 
}//end processCategory()
 
 
/**
* Process the package tag.
*
* @param int $errorPos The line number where the error occurs.
*
* @return void
*/
protected function processPackage($errorPos)
{
$package = $this->commentParser->getPackage();
if ($package !== null) {
$content = $package->getContent();
if ($content !== '') {
if (PHP_CodeSniffer::isUnderscoreName($content) !== true) {
$newContent = str_replace(' ', '_', $content);
$nameBits = explode('_', $newContent);
$firstBit = array_shift($nameBits);
$newName = strtoupper($firstBit{0}).substr($firstBit, 1).'_';
foreach ($nameBits as $bit) {
$newName .= strtoupper($bit{0}).substr($bit, 1).'_';
}
 
$validName = trim($newName, '_');
$error = "Package name \"$content\" is not valid; consider \"$validName\" instead";
$this->currentFile->addError($error, $errorPos);
}
} else {
$error = '@package tag must contain a name';
$this->currentFile->addError($error, $errorPos);
}
}
 
}//end processPackage()
 
 
/**
* Process the subpackage tag.
*
* @param int $errorPos The line number where the error occurs.
*
* @return void
*/
protected function processSubpackage($errorPos)
{
$package = $this->commentParser->getSubpackage();
if ($package !== null) {
$content = $package->getContent();
if ($content !== '') {
if (PHP_CodeSniffer::isUnderscoreName($content) !== true) {
$newContent = str_replace(' ', '_', $content);
$nameBits = explode('_', $newContent);
$firstBit = array_shift($nameBits);
$newName = strtoupper($firstBit{0}).substr($firstBit, 1).'_';
foreach ($nameBits as $bit) {
$newName .= strtoupper($bit{0}).substr($bit, 1).'_';
}
 
$validName = trim($newName, '_');
$error = "Subpackage name \"$content\" is not valid; consider \"$validName\" instead";
$this->currentFile->addError($error, $errorPos);
}
} else {
$error = '@subpackage tag must contain a name';
$this->currentFile->addError($error, $errorPos);
}
}
 
}//end processSubpackage()
 
 
/**
* Process the author tag(s) that this header comment has.
*
* This function is different from other _process functions
* as $authors is an array of SingleElements, so we work out
* the errorPos for each element separately
*
* @param int $commentStart The position in the stack where
* the comment started.
*
* @return void
*/
protected function processAuthors($commentStart)
{
$authors = $this->commentParser->getAuthors();
// Report missing return.
if (empty($authors) === false) {
foreach ($authors as $author) {
$errorPos = ($commentStart + $author->getLine());
$content = $author->getContent();
if ($content !== '') {
$local = '\da-zA-Z-_+';
// Dot character cannot be the first or last character
// in the local-part.
$localMiddle = $local.'.\w';
if (preg_match('/^([^<]*)\s+<(['.$local.']['.$localMiddle.']*['.$local.']@[\da-zA-Z][-.\w]*[\da-zA-Z]\.[a-zA-Z]{2,7})>$/', $content) === 0) {
$error = 'Content of the @author tag must be in the form "Display Name <username@example.com>"';
$this->currentFile->addError($error, $errorPos);
}
} else {
$docBlock = (get_class($this) === 'PEAR_Sniffs_Commenting_FileCommentSniff') ? 'file' : 'class';
$error = "Content missing for @author tag in $docBlock comment";
$this->currentFile->addError($error, $errorPos);
}
}
}
 
}//end processAuthors()
 
 
/**
* Process the copyright tags.
*
* @param int $commentStart The position in the stack where
* the comment started.
*
* @return void
*/
protected function processCopyrights($commentStart)
{
$copyrights = $this->commentParser->getCopyrights();
foreach ($copyrights as $copyright) {
$errorPos = ($commentStart + $copyright->getLine());
$content = $copyright->getContent();
if ($content !== '') {
$matches = array();
if (preg_match('/^([0-9]{4})((.{1})([0-9]{4}))? (.+)$/', $content, $matches) !== 0) {
// Check earliest-latest year order.
if ($matches[3] !== '') {
if ($matches[3] !== '-') {
$error = 'A hyphen must be used between the earliest and latest year';
$this->currentFile->addError($error, $errorPos);
}
 
if ($matches[4] !== '' && $matches[4] < $matches[1]) {
$error = "Invalid year span \"$matches[1]$matches[3]$matches[4]\" found; consider \"$matches[4]-$matches[1]\" instead";
$this->currentFile->addWarning($error, $errorPos);
}
}
} else {
$error = '@copyright tag must contain a year and the name of the copyright holder';
$this->currentFile->addError($error, $errorPos);
}
} else {
$error = '@copyright tag must contain a year and the name of the copyright holder';
$this->currentFile->addError($error, $errorPos);
}//end if
}//end if
 
}//end processCopyrights()
 
 
/**
* Process the license tag.
*
* @param int $errorPos The line number where the error occurs.
*
* @return void
*/
protected function processLicense($errorPos)
{
$license = $this->commentParser->getLicense();
if ($license !== null) {
$value = $license->getValue();
$comment = $license->getComment();
if ($value === '' || $comment === '') {
$error = '@license tag must contain a URL and a license name';
$this->currentFile->addError($error, $errorPos);
}
}
 
}//end processLicense()
 
 
/**
* Process the version tag.
*
* @param int $errorPos The line number where the error occurs.
*
* @return void
*/
protected function processVersion($errorPos)
{
$version = $this->commentParser->getVersion();
if ($version !== null) {
$content = $version->getContent();
$matches = array();
if (empty($content) === true) {
$error = 'Content missing for @version tag in file comment';
$this->currentFile->addError($error, $errorPos);
} else if (strstr($content, 'CVS:') === false
&& strstr($content, 'SVN:') === false
) {
$error = "Invalid version \"$content\" in file comment; consider \"CVS: <cvs_id>\" or \"SVN: <svn_id>\" instead";
$this->currentFile->addWarning($error, $errorPos);
}
}
 
}//end processVersion()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Files/LineLengthSniff.php
New file
0,0 → 1,57
<?php
/**
* PEAR_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.6 2007/07/27 05:36:23 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('Generic_Sniffs_Files_LineLengthSniff', true) === false) {
throw new PHP_CodeSniffer_Exception('Class Generic_Sniffs_Files_LineLengthSniff not found');
}
 
/**
* PEAR_Sniffs_Files_LineLengthSniff.
*
* Checks all lines in the file, and throws warnings if they are over 85
* characters in length.
*
* @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 PEAR_Sniffs_Files_LineLengthSniff extends Generic_Sniffs_Files_LineLengthSniff
{
 
/**
* The limit that the length of a line should not exceed.
*
* @var int
*/
protected $lineLimit = 85;
 
/**
* The limit that the length of a line must not exceed.
*
* Set to zero (0) to disable.
*
* @var int
*/
protected $absoluteLineLimit = 0;
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Files/IncludingFileSniff.php
New file
0,0 → 1,138
<?php
/**
* PEAR_Sniffs_Files_IncludingFileSniff.
*
* 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: IncludingFileSniff.php,v 1.5 2007/10/22 23:11:56 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* PEAR_Sniffs_Files_IncludingFileSniff.
*
* Checks that the include_once is used in conditional situations, and
* require_once is used elsewhere. Also checks that brackets do not surround
* the file being included.
*
* @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 PEAR_Sniffs_Files_IncludingFileSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* Conditions that should use include_once
*
* @var array(int)
*/
private static $_conditions = array(
T_IF,
T_ELSE,
T_ELSEIF,
T_SWITCH,
);
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_INCLUDE_ONCE,
T_REQUIRE_ONCE,
T_REQUIRE,
T_INCLUDE,
);
 
}//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();
 
$nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
if ($tokens[$nextToken]['code'] === T_OPEN_PARENTHESIS) {
$error = '"'.$tokens[$stackPtr]['content'].'"';
$error .= ' is a statement, not a function; ';
$error .= 'no parentheses are required';
$phpcsFile->addError($error, $stackPtr);
}
 
$inCondition = (count($tokens[$stackPtr]['conditions']) !== 0) ? true : false;
 
// Check to see if this including statement is within the parenthesis of a condition.
// If that's the case then we need to process it as being within a condition, as they
// are checking the return value.
if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
foreach ($tokens[$stackPtr]['nested_parenthesis'] as $left => $right) {
if (isset($tokens[$left]['parenthesis_owner']) === true) {
$inCondition = true;
}
}
}
 
// Check to see if they are assigning the return value of this including call.
// If they are then they are probably checking it, so its conditional.
$previous = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
if (in_array($tokens[$previous]['code'], PHP_CodeSniffer_Tokens::$assignmentTokens) === true) {
// The have assigned the return value to it, so its conditional.
$inCondition = true;
}
 
$tokenCode = $tokens[$stackPtr]['code'];
if ($inCondition === true) {
// We are inside a conditional statement. We need an include_once.
if ($tokenCode === T_REQUIRE_ONCE) {
$error = 'File is being conditionally included; ';
$error .= 'use "include_once" instead';
$phpcsFile->addError($error, $stackPtr);
} else if ($tokenCode === T_REQUIRE) {
$error = 'File is being conditionally included; ';
$error .= 'use "include" instead';
$phpcsFile->addError($error, $stackPtr);
}
} else {
// We are unconditionally including, we need a require_once.
if ($tokenCode === T_INCLUDE_ONCE) {
$error = 'File is being unconditionally included; ';
$error .= 'use "require_once" instead';
$phpcsFile->addError($error, $stackPtr);
} else if ($tokenCode === T_INCLUDE) {
$error = 'File is being unconditionally included; ';
$error .= 'use "require" instead';
$phpcsFile->addError($error, $stackPtr);
}
}//end if
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Files/LineEndingsSniff.php
New file
0,0 → 1,47
<?php
/**
* PEAR_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.3 2007/07/27 05:36:23 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('Generic_Sniffs_Files_LineEndingsSniff', true) === false) {
throw new PHP_CodeSniffer_Exception('Class Generic_Sniffs_Files_LineEndingsSniff not found');
}
 
/**
* PEAR_Sniffs_Files_LineEndingsSniff.
*
* Checks that end of line characters are "\n".
*
* @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 PEAR_Sniffs_Files_LineEndingsSniff extends Generic_Sniffs_Files_LineEndingsSniff
{
 
/**
* The valid EOL character.
*
* @var string
*/
protected $eolChar = "\n";
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/ControlStructures/MultiLineConditionSniff.php
New file
0,0 → 1,144
<?php
/**
* PEAR_Sniffs_ControlStructures_MultiLineConditionSniff.
*
* 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: MultiLineConditionSniff.php,v 1.2 2008/12/07 22:25:02 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* PEAR_Sniffs_ControlStructures_MultiLineConditionSniff.
*
* Ensure multi-line IF conditions are defined correctly.
*
* @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 PEAR_Sniffs_ControlStructures_MultiLineConditionSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_IF);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
// We need to work out how far indented the if statement
// itself is, so we can work out how far to indent conditions.
$statementIndent = 0;
for ($i = ($stackPtr - 1); $i >= 0; $i--) {
if ($tokens[$i]['line'] !== $tokens[$stackPtr]['line']) {
$i++;
break;
}
}
 
if ($tokens[$i]['code'] === T_WHITESPACE) {
$statementIndent = strlen($tokens[$i]['content']);
}
 
// Each line between the parenthesis should be indented 4 spaces
// and start with an operator.
$openBracket = $tokens[$stackPtr]['parenthesis_opener'];
$closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
$lastLine = $tokens[$openBracket]['line'];
for ($i = ($openBracket + 1); $i < $closeBracket; $i++) {
if ($tokens[$i]['line'] !== $lastLine) {
if ($tokens[$i]['line'] === $tokens[$closeBracket]['line']) {
$next = $phpcsFile->findNext(T_WHITESPACE, $i, null, true);
if ($next !== $closeBracket) {
// CLosing bracket is on the same line as a condition.
$error = 'Closing parenthesis of a multi-line IF statement must be on a new line';
$phpcsFile->addError($error, $i);
$expectedIndent = ($statementIndent + 4);
} else {
// Closing brace needs to be indented to the same level
// as the function.
$expectedIndent = $statementIndent;
}
} else {
$expectedIndent = ($statementIndent + 4);
}
 
// We changed lines, so this should be a whitespace indent token.
if ($tokens[$i]['code'] !== T_WHITESPACE) {
$foundIndent = 0;
} else {
$foundIndent = strlen($tokens[$i]['content']);
}
 
if ($expectedIndent !== $foundIndent) {
$error = "Multi-line IF statement not indented correctly; expected $expectedIndent spaces but found $foundIndent";
$phpcsFile->addError($error, $i);
}
 
if ($tokens[$i]['line'] !== $tokens[$closeBracket]['line']) {
$next = $phpcsFile->findNext(T_WHITESPACE, $i, null, true);
if (in_array($tokens[$next]['code'], PHP_CodeSniffer_Tokens::$booleanOperators) === false) {
$error = 'Each line in a multi-line IF statement must begin with a boolean operator';
$phpcsFile->addError($error, $i);
}
}
 
$lastLine = $tokens[$i]['line'];
}//end if
}//end for
 
// The openning brace needs to be one space away
// from the closing parenthesis.
if ($tokens[($closeBracket + 1)]['code'] !== T_WHITESPACE) {
$length = 0;
} else {
$length = strlen($tokens[($closeBracket + 1)]['content']);
}
 
if ($length !== 1) {
$error = "There must be a single space between the closing parenthesis and the openning brace of a multi-line IF statement; found $length spaces";
$phpcsFile->addError($error, ($closeBracket + 1));
}
 
// And just in case they do something funny before the brace...
$next = $phpcsFile->findNext(T_WHITESPACE, ($closeBracket + 1), null, true);
if ($next !== false && $tokens[$next]['code'] !== T_OPEN_CURLY_BRACKET) {
$error = 'There must be a single space between the closing parenthesis and the openning brace of a multi-line IF statement';
$phpcsFile->addError($error, $next);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/ControlStructures/InlineControlStructureSniff.php
New file
0,0 → 1,48
<?php
/**
* PEAR_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:32 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('Generic_Sniffs_ControlStructures_InlineControlStructureSniff', true) === false) {
$error = 'Class Generic_Sniffs_ControlStructures_InlineControlStructureSniff not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
/**
* PEAR_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 PEAR_Sniffs_ControlStructures_InlineControlStructureSniff extends Generic_Sniffs_ControlStructures_InlineControlStructureSniff
{
 
/**
* If true, an error will be thrown; otherwise a warning.
*
* @var bool
*/
protected $error = false;
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/ControlStructures/ControlSignatureSniff.php
New file
0,0 → 1,71
<?php
/**
* Verifies that control statements conform to their coding standards.
*
* 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: ControlSignatureSniff.php,v 1.7 2007/10/23 06:05:14 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_Standards_AbstractPatternSniff', true) === false) {
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractPatternSniff not found');
}
 
/**
* Verifies that control statements conform to their coding standards.
*
* @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 PEAR_Sniffs_ControlStructures_ControlSignatureSniff extends PHP_CodeSniffer_Standards_AbstractPatternSniff
{
 
 
/**
* Constructs a PEAR_Sniffs_ControlStructures_ControlSignatureSniff.
*/
public function __construct()
{
parent::__construct(true);
 
}//end __construct()
 
 
/**
* Returns the patterns that this test wishes to verify.
*
* @return array(string)
*/
protected function getPatterns()
{
return array(
'do {EOL...} while (...);EOL',
'while (...) {EOL',
'for (...) {EOL',
'if (...) {EOL',
'foreach (...) {EOL',
'} else if (...) {EOL',
'} elseif (...) {EOL',
'} else {EOL',
'do {EOL',
);
 
}//end getPatterns()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/AbstractScopeSniff.php
New file
0,0 → 1,239
<?php
/**
* An AbstractScopeTest allows for tests that extend from this class to
* listen for tokens within a particluar scope.
*
* 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: AbstractScopeSniff.php,v 1.11 2008/12/01 05:41:28 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* An AbstractScopeTest allows for tests that extend from this class to
* listen for tokens within a particluar scope.
*
* Below is a test that listens to methods that exist only within classes:
* <code>
* class ClassScopeTest extends PHP_CodeSniffer_Standards_AbstractScopeSniff
* {
* public function __construct()
* {
* parent::__construct(array(T_CLASS), array(T_FUNCTION));
* }
*
* protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $)
* {
* $className = $phpcsFile->getDeclarationName($currScope);
* echo 'encountered a method within class '.$className;
* }
* }
* </code>
*
* @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
*/
abstract class PHP_CodeSniffer_Standards_AbstractScopeSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* The token types that this test wishes to listen to within the scope.
*
* @var array()
*/
private $_tokens = array();
 
/**
* The type of scope opener tokens that this test wishes to listen to.
*
* @var string
*/
private $_scopeTokens = array();
 
/**
* The position in the tokens array that opened the current scope.
*
* @var array()
*/
protected $currScope = null;
 
/**
* The current file being checked.
*
* @var string
*/
protected $currFile = '';
 
/**
* True if this test should fire on tokens outside of the scope.
*
* @var boolean
*/
private $_listenOutside = false;
 
 
/**
* Constructs a new AbstractScopeTest.
*
* @param array $scopeTokens The type of scope the test wishes to listen to.
* @param array $tokens The tokens that the test wishes to listen to
* within the scope.
* @param boolean $listenOutside If true this test will also alert the
* extending class when a token is found outside
* the scope, by calling the
* processTokenOutideScope method.
*
* @see PHP_CodeSniffer.getValidScopeTokeners()
* @throws PHP_CodeSniffer_Test_Exception If the specified tokens array is empty.
*/
public function __construct(
array $scopeTokens,
array $tokens,
$listenOutside=false
) {
if (empty($scopeTokens) === true) {
$error = 'The scope tokens list cannot be empty';
throw new PHP_CodeSniffer_Test_Exception($error);
}
 
if (empty($tokens) === true) {
$error = 'The tokens list cannot be empty';
throw new PHP_CodeSniffer_Test_Exception($error);
}
 
$invalidScopeTokens = array_intersect($scopeTokens, $tokens);
if (empty($invalidScopeTokens) === false) {
$invalid = implode(', ', $invalidScopeTokens);
$error = "Scope tokens [$invalid] cant be in the tokens array";
throw new PHP_CodeSniffer_Test_Exception($error);
}
 
$this->_listenOutside = $listenOutside;
$this->_scopeTokens = $scopeTokens;
$this->_tokens = $tokens;
 
}//end __construct()
 
 
/**
* The method that is called to register the tokens this test wishes to
* listen to.
*
* DO NOT OVERRIDE THIS METHOD. Use the constructor of this class to register
* for the desired tokens and scope.
*
* @return array(int)
* @see __constructor()
*/
public final function register()
{
if ($this->_listenOutside === false) {
return $this->_scopeTokens;
} else {
return array_merge($this->_scopeTokens, $this->_tokens);
}
 
}//end register()
 
 
/**
* Processes the tokens that this test is listening for.
*
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
* @param int $stackPtr The position in the stack where this
* token was found.
*
* @return void
* @see processTokenWithinScope()
*/
public final function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$file = $phpcsFile->getFilename();
if ($this->currFile !== $file) {
// We have changed files, so clean up.
$this->currScope = null;
$this->currFile = $file;
}
 
$tokens = $phpcsFile->getTokens();
 
if (in_array($tokens[$stackPtr]['code'], $this->_scopeTokens) === true) {
$this->currScope = $stackPtr;
$phpcsFile->addTokenListener($this, $this->_tokens);
} else if ($this->currScope !== null
&& isset($tokens[$this->currScope]['scope_closer']) === true
&& $stackPtr > $tokens[$this->currScope]['scope_closer']
) {
$this->currScope = null;
if ($this->_listenOutside === true) {
// This is a token outside the current scope, so notify the
// extender as they wish to know about this.
$this->processTokenOutsideScope($phpcsFile, $stackPtr);
} else {
// Don't remove the listener if the extender wants to know about
// tokens that live outside the current scope.
$phpcsFile->removeTokenListener($this, $this->_tokens);
}
} else if ($this->currScope !== null) {
$this->processTokenWithinScope($phpcsFile, $stackPtr, $this->currScope);
} else {
$this->processTokenOutsideScope($phpcsFile, $stackPtr);
}
 
}//end process()
 
 
/**
* Processes a token that is found within the scope that this test is
* listening to.
*
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
* @param int $stackPtr The position in the stack where this
* token was found.
* @param int $currScope The position in the tokens array that
* opened the scope that this test is
* listening for.
*
* @return void
*/
protected abstract function processTokenWithinScope(
PHP_CodeSniffer_File $phpcsFile,
$stackPtr,
$currScope
);
 
 
/**
* Processes a token that is found within the scope that this test is
* listening to.
*
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
* @param int $stackPtr The position in the stack where this
* token was found.
*
* @return void
*/
protected function processTokenOutsideScope(
PHP_CodeSniffer_File $phpcsFile,
$stackPtr
) {
return;
 
}//end processTokenOutsideScope()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/CodingStandard.php
New file
0,0 → 1,73
<?php
/**
* Bass Coding Standard class.
*
* 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: CodingStandard.php,v 1.4 2008/02/01 03:19:53 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Base Coding Standard 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 PHP_CodeSniffer_Standards_CodingStandard
{
 
 
/**
* Return a list of external sniffs to include with this standard.
*
* External locations can be single sniffs, a whole directory of sniffs, or
* an entire coding standard. Locations start with the standard name. For
* example:
* PEAR => include all sniffs in this standard
* PEAR/Sniffs/Files => include all sniffs in this dir
* PEAR/Sniffs/Files/LineLengthSniff => include this single sniff
*
* @return array
*/
public function getIncludedSniffs()
{
return array();
 
}//end getIncludedSniffs()
 
 
/**
* Return a list of external sniffs to exclude from this standard.
*
* External locations can be single sniffs, a whole directory of sniffs, or
* an entire coding standard. Locations start with the standard name. For
* example:
* PEAR => exclude all sniffs in this standard
* PEAR/Sniffs/Files => exclude all sniffs in this dir
* PEAR/Sniffs/Files/LineLengthSniff => exclude this single sniff
*
* @return array
*/
public function getExcludedSniffs()
{
return array();
 
}//end getExcludedSniffs()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/IncorrectPatternException.php
New file
0,0 → 1,36
<?php
/**
* An exception thrown if the pattern being processed is not supposed to be
* validating the code in question.
*
* 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: IncorrectPatternException.php,v 1.2 2006/12/12 02:19:03 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* An exception thrown if the pattern being processed is not supposed to be
* validating the code in question.
*
* @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_IncorrectPatternException extends Exception
{
 
}//end class
 
?>
/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/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/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.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/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/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/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/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/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/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/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/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
 
?>
/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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
 
?>