Skip to content

Commit

Permalink
MDL-19247 Cleaned up most of the sniffer files and adjusted some rule…
Browse files Browse the repository at this point in the history
…s such as do { ... } while ();
  • Loading branch information
nicolasconnault committed May 21, 2009
1 parent 8265a51 commit 68a1cf5
Show file tree
Hide file tree
Showing 40 changed files with 747 additions and 866 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
/**
* File containing the Class Declaration Test.
*
* @package lib-pear-php-codesniffer-standards-moodle-sniffs-classes
* @copyright 2008 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package moodlecore
* @subpackage lib-pear-php-codesniffer-standards-moodle-sniffs-classes
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
Expand Down Expand Up @@ -64,7 +65,7 @@ public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
}

$curlybrace = $tokens[$stackptr]['scope_opener'];
$lastcontent = $phpcsfile->findPrevious(T_WHITESPACE, ($curlybrace - 1), $stackptr, true);
$lastcontent = $phpcsfile->findprevious(T_WHITESPACE, ($curlybrace - 1), $stackptr, true);
$classline = $tokens[$lastcontent]['line'];
$braceline = $tokens[$curlybrace]['line'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
/**
* File containing the moodle_sniffs_codeanalysis_emptystatementsniff Class
*
* @package lib-pear-php-codesniffer-standards-moodle-sniffs-codeanalysis
* @copyright 2008 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package moodlecore
* @subpackage lib-pear-php-codesniffer-standards-moodle-sniffs-codeanalysis
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
Expand All @@ -42,7 +43,7 @@
* <b>elsif</b>, <b>for</b>, <b>foreach<b>, <b>if</b>, <b>switch</b>, <b>try</b>
* and <b>while</b>.
*
* @copyright 2008 Nicolas Connault
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class moodle_sniffs_codeanalysis_emptystatementsniff implements php_codesniffer_sniff
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
/**
* This file is part of the CodeAnalysis addon for PHP_CodeSniffer.
*
* @package lib-pear-php-codesniffer-standards-moodle-sniffs-codeanalysis
* @copyright 2008 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package moodlecore
* @subpackage lib-pear-php-codesniffer-standards-moodle-sniffs-codeanalysis
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
Expand All @@ -38,7 +39,7 @@
* }
* </code>
*
* @copyright 2008 Nicolas Connault
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class moodle_sniffs_codeanalysis_forloopshouldbewhileloopsniff implements php_codesniffer_sniff
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
/**
* This file is part of the CodeAnalysis addon for PHP_CodeSniffer.
*
* @package lib-pear-php-codesniffer-standards-moodle-sniffs-codeanalysis
* @copyright 2008 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package moodlecore
* @subpackage lib-pear-php-codesniffer-standards-moodle-sniffs-codeanalysis
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
Expand All @@ -41,7 +42,7 @@
* }
* </code>
*
* @copyright 2008 Nicolas Connault
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class moodle_sniffs_codeanalysis_forloopwithtestfunctioncallsniff implements php_codesniffer_sniff
Expand Down Expand Up @@ -100,7 +101,7 @@ public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)

// 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);
$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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
/**
* This file is part of the CodeAnalysis addon for PHP_CodeSniffer.
*
* @package lib-pear-php-codesniffer-standards-moodle-sniffs-codeanalysis
* @copyright 2008 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package moodlecore
* @subpackage lib-pear-php-codesniffer-standards-moodle-sniffs-codeanalysis
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
Expand All @@ -45,7 +46,7 @@
* }
* </code>
*
* @copyright 2008 Nicolas Connault
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class moodle_sniffs_codeanalysis_jumbledincrementersniff implements php_codesniffer_sniff
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
/**
* This file is part of the CodeAnalysis addon for PHP_CodeSniffer.
*
* @package lib-pear-php-codesniffer-standards-moodle-sniffs-codeanalysis
* @copyright 2008 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package moodlecore
* @subpackage lib-pear-php-codesniffer-standards-moodle-sniffs-codeanalysis
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
Expand All @@ -42,7 +43,7 @@
* }
* </code>
*
* @copyright 2008 Nicolas Connault
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class moodle_sniffs_codeanalysis_unconditionalifstatementsniff implements php_codesniffer_sniff
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
/**
* This file is part of the CodeAnalysis addon for PHP_CodeSniffer.
*
* @package lib-pear-php-codesniffer-standards-moodle-sniffs-codeanalysis
* @copyright 2008 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package moodlecore
* @subpackage lib-pear-php-codesniffer-standards-moodle-sniffs-codeanalysis
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
Expand All @@ -38,7 +39,7 @@
* }
* </code>
*
* @copyright 2008 Nicolas Connault
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class moodle_sniffs_codeanalysis_unnecessaryfinalmodifiersniff implements php_codesniffer_sniff
Expand Down Expand Up @@ -77,7 +78,7 @@ public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
}

// Fetch previous token.
$prev = $phpcsfile->findPrevious(PHP_CodeSniffer_tokens::$emptyTokens, ($stackptr - 1), null, true);
$prev = $phpcsfile->findprevious(PHP_CodeSniffer_tokens::$emptyTokens, ($stackptr - 1), null, true);

// Skip for non final class.
if ($prev === false || $tokens[$prev]['code'] !== T_FINAL) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
/**
* This file is part of the CodeAnalysis addon for PHP_CodeSniffer.
*
* @package lib-pear-php-codesniffer-standards-moodle-sniffs-codeanalysis
* @copyright 2008 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package moodlecore
* @subpackage lib-pear-php-codesniffer-standards-moodle-sniffs-codeanalysis
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
Expand All @@ -31,7 +32,7 @@
* interface that defines multiple methods but the implementation only needs some
* of them.
*
* @copyright 2008 Nicolas Connault
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class moodle_sniffs_codeanalysis_unusedfunctionparametersniff implements php_codesniffer_sniff
Expand Down Expand Up @@ -70,7 +71,7 @@ public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
}

$params = array();
foreach ($phpcsfile->getmethodParameters($stackptr) as $param) {
foreach ($phpcsfile->getmethodparameters($stackptr) as $param) {
$params[$param['name']] = $stackptr;
}

Expand All @@ -91,7 +92,7 @@ public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
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);
$tmp = $phpcsfile->findnext(PHP_CodeSniffer_tokens::$emptyTokens, ($next + 1), null, true);
if ($tmp === false) {
return;
}
Expand All @@ -101,7 +102,7 @@ public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
return;
}

$tmp = $phpcsfile->findNext(PHP_CodeSniffer_tokens::$emptyTokens, ($tmp + 1), null, true);
$tmp = $phpcsfile->findnext(PHP_CodeSniffer_tokens::$emptyTokens, ($tmp + 1), null, true);

// There is a return <token>.
if ($tmp !== false && $tokens[$tmp] === T_SEMICOLON) {
Expand Down Expand Up @@ -140,5 +141,3 @@ public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)


}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
/**
* This file is part of the CodeAnalysis addon for PHP_CodeSniffer.
*
* @package lib-pear-php-codesniffer-standards-moodle-sniffs-codeanalysis
* @copyright 2008 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package moodlecore
* @subpackage lib-pear-php-codesniffer-standards-moodle-sniffs-codeanalysis
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
Expand All @@ -38,11 +39,10 @@
* }
* </code>
*
* @copyright 2008 Nicolas Connault
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class moodle_sniffs_codeanalysis_uselessoverridingmethodsniff implements php_codesniffer_sniff
{
class moodle_sniffs_codeanalysis_uselessoverridingmethodsniff implements php_codesniffer_sniff {


/**
Expand Down Expand Up @@ -81,7 +81,7 @@ public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)

// Get all parameters from method signature.
$signature = array();
foreach ($phpcsfile->getmethodParameters($stackptr) as $param) {
foreach ($phpcsfile->getmethodparameters($stackptr) as $param) {
$signature[] = $param['name'];
}

Expand All @@ -106,30 +106,30 @@ public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
}

// Find next non empty token index, should be double colon.
$next = $phpcsfile->findNext(PHP_CodeSniffer_tokens::$emptyTokens, ($next + 1), null, true);
$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);
$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);
$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(
$validparametertypes = array(
T_VARIABLE,
T_LNUMBER,
T_CONSTANT_ENCAPSED_STRING,
Expand All @@ -156,7 +156,7 @@ public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
}
}

$next = $phpcsfile->findNext(PHP_CodeSniffer_tokens::$emptyTokens, ($next + 1), null, true);
$next = $phpcsfile->findnext(PHP_CodeSniffer_tokens::$emptyTokens, ($next + 1), null, true);
if ($next === false || $tokens[$next]['code'] !== T_SEMICOLON) {
return;
}
Expand All @@ -181,5 +181,3 @@ public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)


}

?>
Loading

0 comments on commit 68a1cf5

Please sign in to comment.