]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19247 Cleaned up most of the sniffer files and adjusted some rules such as do...
authornicolasconnault <nicolasconnault>
Thu, 21 May 2009 09:48:31 +0000 (09:48 +0000)
committernicolasconnault <nicolasconnault>
Thu, 21 May 2009 09:48:31 +0000 (09:48 +0000)
40 files changed:
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/Classes/ClassDeclarationSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/CodeAnalysis/EmptyStatementSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/CodeAnalysis/ForLoopShouldBeWhileLoopSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/CodeAnalysis/ForLoopWithTestFunctionCallSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/CodeAnalysis/JumbledIncrementerSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/CodeAnalysis/UnconditionalIfStatementSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/CodeAnalysis/UnnecessaryFinalModifierSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/CodeAnalysis/UnusedFunctionParameterSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/CodeAnalysis/UselessOverridingMethodSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/Commenting/ClassCommentSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/Commenting/FileCommentSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/Commenting/FunctionCommentSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/Commenting/InlineCommentSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/ControlStructures/ControlSignatureSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/ControlStructures/ElseIfDeclarationSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/ControlStructures/InlineControlStructureSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/Files/ClosingPHPTagSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/Files/IncludingFileSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/Files/LineEndingsSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/Files/LineLengthSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/Formatting/SpaceAfterCastSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/Functions/FunctionCallArgumentSpacingSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/Functions/FunctionCallSignatureSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/Functions/FunctionDeclarationSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/Functions/LowercaseFunctionKeywordsSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/Functions/ValidDefaultValueSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/NamingConventions/ValidClassNameSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/NamingConventions/ValidFunctionNameSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/NamingConventions/ValidVariableNameSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/PHP/DisallowShortOpenTagSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/PHP/LowerCaseConstantSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/PHP/LowercasePHPFunctionsSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/Strings/DoubleQuoteUsageSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/Strings/EchoedStringsSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/WhiteSpace/ControlStructureBlankLineSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/WhiteSpace/DisallowTabIndentSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/WhiteSpace/MemberVarSpacingSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/WhiteSpace/ScopeIndentSniff.php

index c0c8d1999bafb2b765500ccc2e874c9e49070b7f..45d13853aaa512a8eb896e3495c57d72aef5f6e4 100644 (file)
 /**
  * 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
  */
 
 /**
@@ -64,7 +65,7 @@ class moodle_sniffs_classes_classdeclarationsniff implements php_codesniffer_sni
         }
 
         $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'];
 
index 42b43ddd2b17d91f43c9f5addf1829631e37b78f..fc908609ecbbc3ca677ea0d17b3d054a6bb8328e 100644 (file)
 /**
  * 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
  */
 
 /**
@@ -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
index 89966fbd1a3a57a0f1f5b1c77a982f83d7ab8e1e..110e4553b30ea1ee634de5969cb3ccd6aa541c84 100644 (file)
 /**
  * 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
  */
 
 /**
@@ -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
index 5a77f699395ed932b665ca76ace34276796e4aec..4b755e8001945c48e1bb9776b275b99883465c5f 100644 (file)
 /**
  * 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
  */
 
 /**
@@ -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
@@ -100,7 +101,7 @@ class moodle_sniffs_codeanalysis_forloopwithtestfunctioncallsniff implements php
 
             // 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';
index 0a17fe2a10bb5d29e8854d85224c0db280dca107..f272168ca54f4e11daae76304edaa4cdf97156c6 100644 (file)
 /**
  * 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
  */
 
 /**
@@ -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
index bd3f019dfea5c59509c0f077c628802738737e1d..d54411a55d9ffaf7dbf74ec99e113712ba58ab48 100644 (file)
 /**
  * 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
  */
 
 /**
@@ -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
index b10400349c6ae60674b20bf90278a5825bb2dfea..0ee64447a24306cbe4f32d0ffe76776f417ec611 100644 (file)
 /**
  * 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
  */
 
 /**
@@ -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
@@ -77,7 +78,7 @@ class moodle_sniffs_codeanalysis_unnecessaryfinalmodifiersniff implements php_co
         }
 
         // 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) {
index c282731b329428c26809f989c37f3304ed065235..c9e00c5307a28aa09491c46519dac8ea75bdc449 100644 (file)
 /**
  * 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
  */
 
 /**
@@ -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
@@ -70,7 +71,7 @@ class moodle_sniffs_codeanalysis_unusedfunctionparametersniff implements php_cod
         }
 
         $params = array();
-        foreach ($phpcsfile->getmethodParameters($stackptr) as $param) {
+        foreach ($phpcsfile->getmethodparameters($stackptr) as $param) {
             $params[$param['name']] = $stackptr;
         }
 
@@ -91,7 +92,7 @@ class moodle_sniffs_codeanalysis_unusedfunctionparametersniff implements php_cod
                 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;
                 }
@@ -101,7 +102,7 @@ class moodle_sniffs_codeanalysis_unusedfunctionparametersniff implements php_cod
                     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) {
@@ -140,5 +141,3 @@ class moodle_sniffs_codeanalysis_unusedfunctionparametersniff implements php_cod
 
 
 }
-
-?>
index bec8aa1a20f00f9230ebb4898951a467bbd4c143..7730c934587dc224a795075a847dcae7ae08cc60 100644 (file)
 /**
  * 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
  */
 
 /**
  * }
  * </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 {
 
 
     /**
@@ -81,7 +81,7 @@ class moodle_sniffs_codeanalysis_uselessoverridingmethodsniff implements php_cod
 
         // Get all parameters from method signature.
         $signature = array();
-        foreach ($phpcsfile->getmethodParameters($stackptr) as $param) {
+        foreach ($phpcsfile->getmethodparameters($stackptr) as $param) {
             $signature[] = $param['name'];
         }
 
@@ -106,7 +106,7 @@ class moodle_sniffs_codeanalysis_uselessoverridingmethodsniff implements php_cod
         }
 
         // 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) {
@@ -114,7 +114,7 @@ class moodle_sniffs_codeanalysis_uselessoverridingmethodsniff implements php_cod
         }
 
         // 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) {
@@ -122,14 +122,14 @@ class moodle_sniffs_codeanalysis_uselessoverridingmethodsniff implements php_cod
         }
 
         // 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,
@@ -156,7 +156,7 @@ class moodle_sniffs_codeanalysis_uselessoverridingmethodsniff implements php_cod
             }
         }
 
-        $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;
         }
@@ -181,5 +181,3 @@ class moodle_sniffs_codeanalysis_uselessoverridingmethodsniff implements php_cod
 
 
 }
-
-?>
index 4025c75db191bcb947d92a0bde322c7cd96ac40e..8c32bc141643b72e0aac1bbc69a133bbf82aca14 100644 (file)
 /**
  * Parses and verifies the doc comments for classes.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-commenting
- * @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-commenting
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 if (class_exists('PHP_CodeSniffer_CommentParser_ClassCommentParser', true) === false) {
@@ -46,7 +47,7 @@ if (class_exists('moodle_sniffs_commenting_filecommentsniff', true) === false) {
  *  <li>Check required and optional tags and the format of their content.</li>
  * </ul>
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 class moodle_sniffs_commenting_classcommentsniff extends moodle_sniffs_commenting_filecommentsniff {
@@ -87,7 +88,7 @@ class moodle_sniffs_commenting_classcommentsniff extends moodle_sniffs_commentin
                   );
 
         // Extract the class comment docblock.
-        $commentend = $phpcsfile->findPrevious($find, ($stackptr - 1), null, true);
+        $commentend = $phpcsfile->findprevious($find, ($stackptr - 1), null, true);
 
         if ($commentend !== false && $tokens[$commentend]['code'] === T_COMMENT) {
             $phpcsfile->adderror("You must use \"/**\" style comments for a $type comment", $stackptr);
@@ -98,25 +99,25 @@ class moodle_sniffs_commenting_classcommentsniff extends moodle_sniffs_commentin
             return;
         }
 
-        $commentstart = ($phpcsfile->findPrevious(T_DOC_COMMENT, ($commentend - 1), null, true) + 1);
-        $commentnext  = $phpcsfile->findPrevious(T_WHITESPACE, ($commentend + 1), $stackptr, false, $phpcsfile->eolChar);
+        $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));
+        $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);
+            $prevnoncomment = $phpcsfile->findprevious(T_DOC_COMMENT, ($commentstart - 1), null, true);
 
             if ($prevnoncomment !== false) {
-                $prevcomment = $phpcsfile->findPrevious(T_DOC_COMMENT, ($prevnoncomment - 1));
+                $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);
+                    $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);
+                        $newlinetoken = $phpcsfile->findnext(T_WHITESPACE, ($newlinetoken + 1), $stackptr, false, $phpcsfile->eolChar);
 
                         if ($newlinetoken !== false) {
                             // Blank line between the class and the doc block.
@@ -135,6 +136,7 @@ class moodle_sniffs_commenting_classcommentsniff extends moodle_sniffs_commentin
         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);
@@ -166,7 +168,7 @@ class moodle_sniffs_commenting_classcommentsniff extends moodle_sniffs_commentin
         $long = $comment->getlongcomment();
 
         if (empty($long) === false) {
-            $between        = $comment->getWhiteSpaceBetween();
+            $between        = $comment->getWhiteSpacebetween();
             $newlinebetween = substr_count($between, $phpcsfile->eolChar);
 
             if ($newlinebetween !== 2) {
index 9e3cbb9134e966500ec976fc13976a03396e928c..2dea546b546f804453bace6751388139a21621b1 100644 (file)
 /**
  * Parses and verifies the doc comments for files.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-commenting
- * @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-commenting
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 if (class_exists('PHP_CodeSniffer_CommentParser_ClassCommentParser', true) === false) {
@@ -41,7 +42,7 @@ if (class_exists('PHP_CodeSniffer_CommentParser_ClassCommentParser', true) === f
  *  <li>Check required and optional tags and the format of their content.</li>
  * </ul>
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
@@ -70,7 +71,7 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
            'category'   => array(
                             'required'       => false,
                             'allow_multiple' => false,
-                            'order_text'     => 'precedes @package',
+                            'order_text'     => 'precedes @subpackage',
                            ),
            'package'    => array(
                             'required'       => true,
@@ -80,12 +81,12 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
            'subpackage' => array(
                             'required'       => false,
                             'allow_multiple' => false,
-                            'order_text'     => 'follows @package',
+                            'order_text'     => 'follows @subpackage',
                            ),
            'author'     => array(
                             'required'       => false,
                             'allow_multiple' => true,
-                            'order_text'     => 'follows @subpackage (if used) or @package',
+                            'order_text'     => 'follows @subsubpackage (if used) or @subpackage',
                            ),
            'copyright'  => array(
                             'required'       => true,
@@ -124,6 +125,10 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
                            ),
                 );
 
+    protected $core_folders = array('admin', 'backup', 'blog', 'calendar', 'course',
+                                    'error', 'group', 'iplookup', 'lib', 'login',
+                                    'message', 'mnet', 'my', 'notes', 'pix', 'rss',
+                                    'tag', 'user', 'userpix');
 
     /**
      * Returns an array of tokens this test wants to listen for.
@@ -150,7 +155,7 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
         // We are only interested if this is the first open tag.
         if ($stackptr !== 0) {
 
-            if ($phpcsfile->findPrevious(T_OPEN_TAG, ($stackptr - 1)) !== false) {
+            if ($phpcsfile->findprevious(T_OPEN_TAG, ($stackptr - 1)) !== false) {
                 return;
             }
         }
@@ -504,13 +509,13 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
         if ($tagelement instanceof PHP_CodeSniffer_CommentParser_Singleelement) {
 
             if ($tagelement->getcontent() !== '') {
-                return (strlen($tagname) + substr_count($tagelement->getWhitespaceBeforecontent(), ' '));
+                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 (strlen($tagname) + substr_count($tagelement->getwhitespacebeforevalue(), ' '));
             }
         }
 
@@ -567,20 +572,28 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
     protected function processpackage($errorpos) {
         global $CFG;
         $package = $this->commentparser->getPackage();
+
         $filename = str_replace($CFG->dirroot, '', $this->currentfile->getfilename());
+        $path_parts = explode('/', $filename);
 
-        // Replace slashes or backslashes in file path with dashes
-        $expected_package = strtolower(str_replace('/', '-', $filename));
+        if (in_array($path_parts[1], $this->core_folders)) {
+            $expected_package = 'moodlecore';
 
-        if (strpos($expected_package, '-')) {
-            $expected_package = strtolower(str_replace('\\', '-', $filename));
-        }
+        } else {
+
+            // Replace slashes or backslashes in file path with dashes
+            $expected_package = strtolower(str_replace('/', '-', $filename));
 
-        // Strip off last part: the name of the searched file
-        $expected_package = substr($expected_package, 0, strrpos($expected_package, '-'));
+            if (strpos($expected_package, '-')) {
+                $expected_package = strtolower(str_replace('\\', '-', $filename));
+            }
 
-        // Remove first dash if present
-        $expected_package = ltrim($expected_package, '-');
+            // Strip off last part: the name of the searched file
+            $expected_package = substr($expected_package, 0, strrpos($expected_package, '-'));
+
+            // Remove first dash if present
+            $expected_package = ltrim($expected_package, '-');
+        }
 
         if ($package !== null) {
             $content = $package->getcontent();
@@ -597,7 +610,7 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
                 }
 
             } else {
-                $error = '@package tag must contain a name';
+                $error = '@subpackage tag must contain a name';
                 $this->currentfile->adderror($error, $errorpos);
             }
         }
@@ -632,7 +645,7 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
 
                     $validname = trim($newname, '_');
                     $error     = "Subpackage name \"$content\" is not valid; consider \"$validname\" instead";
-                    $this->currentfile->adderror($error, $errorpos);
+                    // $this->currentfile->adderror($error, $errorpos);
                 }
 
             } else {
index 6360a9ce93033885468f7d427f05895c73b445bc..f48c17392756d303b773426c52187da820dba2a3 100644 (file)
 /**
  * Parses and verifies the doc comments for functions.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-commenting
- * @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-commenting
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 if (class_exists('PHP_CodeSniffer_CommentParser_FunctionCommentParser', true) === false) {
@@ -35,20 +36,19 @@ if (class_exists('PHP_CodeSniffer_CommentParser_FunctionCommentParser', true) ==
  *  <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>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>
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_sniff
-{
+class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_sniff {
 
     /**
      * The name of the method that we are currently processing.
@@ -76,14 +76,14 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
      *
      * @var PHP_CodeSniffer_Comment_Parser_FunctionCommentParser
      */
-    protected $commentParser = null;
+    protected $commentparser = null;
 
     /**
      * The current PHP_CodeSniffer_File object we are processing.
      *
      * @var PHP_CodeSniffer_File
      */
-    protected $currentFile = null;
+    protected $currentfile = null;
 
 
     /**
@@ -91,8 +91,7 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
      *
      * @return array
      */
-    public function register()
-    {
+    public function register() {
         return array(T_FUNCTION);
 
     }
@@ -107,8 +106,7 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
      *
      * @return void
      */
-    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
         $find = array(
                  T_COMMENT,
                  T_DOC_COMMENT,
@@ -117,13 +115,13 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
                  T_OPEN_TAG,
                 );
 
-        $commentend = $phpcsfile->findPrevious($find, ($stackptr - 1));
+        $commentend = $phpcsfile->findprevious($find, ($stackptr - 1));
 
         if ($commentend === false) {
             return;
         }
 
-        $this->currentFile = $phpcsfile;
+        $this->currentfile = $phpcsfile;
         $tokens            = $phpcsfile->gettokens();
 
         // If the token that we found was a class or a function, then this
@@ -134,6 +132,7 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
             $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;
@@ -146,7 +145,8 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
         $ignore[]  = T_WHITESPACE;
         $ignore[]  = T_ABSTRACT;
         $ignore[]  = T_FINAL;
-        $prevtoken = $phpcsfile->findPrevious($ignore, ($stackptr - 1), null, true);
+        $prevtoken = $phpcsfile->findprevious($ignore, ($stackptr - 1), null, true);
+
         if ($prevtoken !== $commentend) {
             $phpcsfile->adderror('Missing function doc comment', $stackptr);
             return;
@@ -154,20 +154,23 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
 
         $this->_functiontoken = $stackptr;
 
-        foreach ($tokens[$stackptr]['conditions'] as $condPtr => $condition) {
+        foreach ($tokens[$stackptr]['conditions'] as $condptr => $condition) {
+
             if ($condition === T_CLASS || $condition === T_INTERFACE) {
-                $this->_classtoken = $condPtr;
+                $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);
+        $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) {
+
+            if ($stackptr === 0 || $phpcsfile->findprevious(T_OPEN_TAG, ($prevtoken - 1)) === false) {
                 $phpcsfile->adderror('Missing function doc comment', $stackptr);
                 return;
             }
@@ -177,31 +180,34 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
         $this->_methodname = $phpcsfile->getDeclarationname($stackptr);
 
         try {
-            $this->commentParser = new PHP_CodeSniffer_CommentParser_FunctionCommentParser($comment, $phpcsfile);
-            $this->commentParser->parse();
+            $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();
+        $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);
+        $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';
+        $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));
         }
@@ -210,25 +216,30 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
 
         // 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) {
+            $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;
+            $newlinecount += $newlinebetween;
         }
 
         // Exactly one blank line before tags.
-        $params = $this->commentParser->gettagOrders();
+        $params = $this->commentparser->gettagOrders();
+
         if (count($params) > 1) {
-            $newlineSpan = $comment->getNewlineAfter();
-            if ($newlineSpan !== 2) {
+            $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);
+                    $newlinecount += (substr_count($long, $phpcsfile->eolChar) - $newlinespan + 1);
                 }
 
                 $phpcsfile->addwarning($error, ($commentstart + $newlinecount));
@@ -247,23 +258,22 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
      *
      * @return void
      */
-    protected function processThrows($commentstart)
-    {
-        if (count($this->commentParser->getThrows()) === 0) {
+    protected function processthrows($commentstart) {
+
+        if (count($this->commentparser->getthrows()) === 0) {
             return;
         }
 
-        foreach ($this->commentParser->getThrows() as $throw) {
+        foreach ($this->commentparser->getthrows() as $throw) {
 
-            $exception = $throw->getValue();
+            $exception = $throw->getvalue();
             $errorpos  = ($commentstart + $throw->getline());
 
             if ($exception === '') {
                 $error = '@throws tag must contain the exception class name';
-                $this->currentFile->adderror($error, $errorpos);
+                $this->currentfile->adderror($error, $errorpos);
             }
         }
-
     }
 
 
@@ -275,12 +285,12 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
      *
      * @return void
      */
-    protected function processReturn($commentstart, $commentend)
-    {
+    protected function processreturn($commentstart, $commentend) {
         // Skip constructor and destructor.
         $classname = '';
+
         if ($this->_classtoken !== null) {
-            $classname = $this->currentFile->getDeclarationname($this->_classtoken);
+            $classname = $this->currentfile->getdeclarationname($this->_classtoken);
             $classname = strtolower(ltrim($classname, '_'));
         }
 
@@ -289,19 +299,18 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
 
         if ($isspecialmethod === false && $methodname !== $classname) {
             // Report missing return tag.
-            if ($this->commentParser->getReturn() === null) {
+            if ($this->commentparser->getreturn() === null) {
                 $error = 'Missing @return tag in function comment';
-                $this->currentFile->adderror($error, $commentend);
-            } else if (trim($this->commentParser->getReturn()->getRawcontent()) === '') {
+                $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);
+                $errorpos = ($commentstart + $this->commentparser->getreturn()->getline());
+                $this->currentfile->adderror($error, $errorpos);
             }
         }
-
     }
 
-
     /**
      * Process the function parameter comments.
      *
@@ -310,155 +319,156 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
      *
      * @return void
      */
-    protected function processParams($commentstart)
-    {
-        $realParams = $this->currentFile->getmethodParameters($this->_functiontoken);
+    protected function processparams($commentstart) {
+        $realparams = $this->currentfile->getmethodparameters($this->_functiontoken);
 
-        $params      = $this->commentParser->getParams();
-        $foundParams = array();
+        $params      = $this->commentparser->getparams();
+        $foundparams = array();
 
         if (empty($params) === false) {
 
-            $lastParm = (count($params) - 1);
-            if (substr_count($params[$lastParm]->getWhitespaceAfter(), $this->currentFile->eolChar) !== 2) {
+            $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->addwarning($error, $errorpos);
+                $errorpos = ($params[$lastparm]->getline() + $commentstart);
+                $this->currentfile->addwarning($error, $errorpos);
             }
 
-            // Parameters must appear immediately after the comment.
+            // parameters must appear immediately after the comment.
             if ($params[0]->getOrder() !== 2) {
-                $error    = 'Parameters must appear immediately after the comment';
+                $error    = 'parameters must appear immediately after the comment';
                 $errorpos = ($params[0]->getline() + $commentstart);
-                $this->currentFile->adderror($error, $errorpos);
+                $this->currentfile->adderror($error, $errorpos);
             }
 
-            $previousParam      = null;
-            $spaceBeforeVar     = 10000;
-            $spaceBeforeComment = 10000;
-            $longestType        = 0;
-            $longestVar         = 0;
+            $previousparam      = null;
+            $spacebeforevar     = 10000;
+            $spacebeforecomment = 10000;
+            $longesttype        = 0;
+            $longestvar         = 0;
 
             foreach ($params as $param) {
 
-                $paramComment = trim($param->getComment());
+                $paramcomment = trim($param->getcomment());
                 $errorpos     = ($param->getline() + $commentstart);
 
                 // Make sure that there is only one space before the var type.
-                if ($param->getWhitespaceBeforeType() !== ' ') {
+                if ($param->getwhitespacebeforetype() !== ' ') {
                     $error = 'Expected 1 space before variable type';
-                    $this->currentFile->addwarning($error, $errorpos);
+                    $this->currentfile->addwarning($error, $errorpos);
                 }
 
-                $spacecount = substr_count($param->getWhitespaceBeforeVarname(), ' ');
-                if ($spacecount < $spaceBeforeVar) {
-                    $spaceBeforeVar = $spacecount;
-                    $longestType    = $errorpos;
+                $spacecount = substr_count($param->getwhitespacebeforevarname(), ' ');
+
+                if ($spacecount < $spacebeforevar) {
+                    $spacebeforevar = $spacecount;
+                    $longesttype    = $errorpos;
                 }
 
-                $spacecount = substr_count($param->getWhitespaceBeforeComment(), ' ');
+                $spacecount = substr_count($param->getwhitespacebeforecomment(), ' ');
 
-                if ($spacecount < $spaceBeforeComment && $paramComment !== '') {
-                    $spaceBeforeComment = $spacecount;
-                    $longestVar         = $errorpos;
+                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 ]';
+                $paramname = ($param->getvarname() !== '') ? $param->getvarname() : '[ UNKNOWN ]';
 
-                if ($previousParam !== null) {
-                    $previousname = ($previousParam->getVarname() !== '') ? $previousParam->getVarname() : 'UNKNOWN';
+                if ($previousparam !== null) {
+                    $previousname = ($previousparam->getvarname() !== '') ? $previousparam->getvarname() : 'UNKNOWN';
 
                     // Check to see if the parameters align properly.
-                    if ($param->alignsVariableWith($previousParam) === false) {
+                    if ($param->alignsvariablewith($previousparam) === false) {
                         $error = 'The variable names for parameters '.$previousname.' ('.($pos - 1).') and '.$paramname.' ('.$pos.') do not align';
-                        $this->currentFile->addwarning($error, $errorpos);
+                        $this->currentfile->addwarning($error, $errorpos);
                     }
 
-                    if ($param->alignsCommentWith($previousParam) === false) {
+                    if ($param->alignsCommentWith($previousparam) === false) {
                         $error = 'The comments for parameters '.$previousname.' ('.($pos - 1).') and '.$paramname.' ('.$pos.') do not align';
-                        $this->currentFile->addwarning($error, $errorpos);
+                        $this->currentfile->addwarning($error, $errorpos);
                     }
                 }
 
                 // 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;
+                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) {
+                    if ($realparams[($pos - 1)]['pass_by_reference'] === true) {
                         $realname = '&'.$realname;
                     }
 
-                    if ($realname !== $param->getVarname()) {
+                    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);
+                        $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);
+                    $this->currentfile->adderror($error, $errorpos);
                 }
 
-                if ($param->getVarname() === '') {
+                if ($param->getvarname() === '') {
                     $error = 'Missing parameter name at position '.$pos;
-                     $this->currentFile->adderror($error, $errorpos);
+                     $this->currentfile->adderror($error, $errorpos);
                 }
 
-                if ($param->getType() === '') {
+                if ($param->gettype() === '') {
                     $error = 'Missing type at position '.$pos;
-                    $this->currentFile->adderror($error, $errorpos);
+                    $this->currentfile->adderror($error, $errorpos);
                 }
 
-                if ($paramComment === '') {
+                if ($paramcomment === '') {
                     $error = 'Missing comment for param "'.$paramname.'" at position '.$pos;
-                    $this->currentFile->adderror($error, $errorpos);
+                    $this->currentfile->adderror($error, $errorpos);
                 }
 
-                $previousParam = $param;
+                $previousparam = $param;
 
             }
 
-            if ($spaceBeforeVar !== 1 && $spaceBeforeVar !== 10000 && $spaceBeforeComment !== 10000) {
+            if ($spacebeforevar !== 1 && $spacebeforevar !== 10000 && $spacebeforecomment !== 10000) {
                 $error = 'Expected 1 space after the longest type';
-                $this->currentFile->adderror($error, $longestType);
+                $this->currentfile->adderror($error, $longesttype);
             }
 
-            if ($spaceBeforeComment !== 1 && $spaceBeforeComment !== 10000) {
+            if ($spacebeforecomment !== 1 && $spacebeforecomment !== 10000) {
                 $error = 'Expected 1 space after the longest variable name';
-                $this->currentFile->adderror($error, $longestVar);
+                $this->currentfile->adderror($error, $longestvar);
             }
 
         }
 
         $realnames = array();
-        foreach ($realParams as $realParam) {
-            $realnames[] = $realParam['name'];
+
+        foreach ($realparams as $realparam) {
+            $realnames[] = $realparam['name'];
         }
 
         // Report and missing comments.
-        $diff = array_diff($realnames, $foundParams);
-        foreach ($diff as $neededParam) {
+        $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);
+            $error = 'Doc comment for "'.$neededparam.'" missing';
+            $this->currentfile->adderror($error, $errorpos);
         }
-
     }
-
-
 }
-
-?>
index f2b8abfc6b42b976adbd58ed1fe7a16fe8a469a4..b9d70abfff996a7d0aa7a7dbb36024f4b2fb1e72 100644 (file)
 /**
  * php_codesniffer_sniffs_moodle_commenting_inlinecommentsniff.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-commenting
- * @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-commenting
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 /**
  *
  * Checks that no perl-style comments are used.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_commenting_inlinecommentsniff implements php_codesniffer_sniff
-{
+class moodle_sniffs_commenting_inlinecommentsniff implements php_codesniffer_sniff {
 
 
     /**
@@ -39,10 +39,8 @@ class moodle_sniffs_commenting_inlinecommentsniff implements php_codesniffer_sni
      *
      * @return array
      */
-    public function register()
-    {
+    public function register() {
         return array(T_COMMENT);
-
     }
 
 
@@ -55,8 +53,7 @@ class moodle_sniffs_commenting_inlinecommentsniff implements php_codesniffer_sni
      *
      * @return void
      */
-    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
         $tokens = $phpcsfile->gettokens();
 
         if ($tokens[$stackptr]['content']{0} === '#') {
@@ -64,10 +61,5 @@ class moodle_sniffs_commenting_inlinecommentsniff implements php_codesniffer_sni
             $error .= ' or "/* comment */" instead.';
             $phpcsfile->adderror($error, $stackptr);
         }
-
     }
-
-
 }
-
-?>
index 66376674490c2e19bbe3d45b3bf6528a5d2884c7..8ac027d536d470ce5c92b9480f8d03f80eb3c042 100644 (file)
 /**
  * Verifies that control statements conform to their coding standards.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-controlstructures
- * @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-controlstructures
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 if (class_exists('PHP_CodeSniffer_Standards_AbstractPatternSniff', true) === false) {
@@ -29,20 +30,17 @@ if (class_exists('PHP_CodeSniffer_Standards_AbstractPatternSniff', true) === fal
 /**
  * Verifies that control statements conform to their coding standards.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_controlstructures_controlsignaturesniff extends php_codesniffer_standards_abstractpatternsniff
-{
+class moodle_sniffs_controlstructures_controlsignaturesniff extends php_codesniffer_standards_abstractpatternsniff {
 
 
     /**
      * Constructs a moodle_sniffs_controlstructures_controlsignaturesniff.
      */
-    public function __construct()
-    {
+    public function __construct() {
         parent::__construct(true);
-
     }
 
 
@@ -51,22 +49,15 @@ class moodle_sniffs_controlstructures_controlsignaturesniff extends php_codesnif
      *
      * @return array(string)
      */
-    protected function getPatterns()
-    {
-        return array(
-                'do {EOL...} while (...);EOL',
-                'while (...) {EOL',
-                'for (...) {EOL',
-                'if (...) {EOL',
-                'foreach (...) {EOL',
-                '} else if (...) {EOL',
-                '} else {EOL',
-                'do {EOL',
-               );
-
+    protected function getpatterns() {
+        return array('do {EOL...} while (...);EOL',
+                     'while (...) {EOL',
+                     'for (...) {EOL',
+                     'if (...) {EOL',
+                     'foreach (...) {EOL',
+                     '} else if (...) {EOL',
+                     '} else {EOL',
+                     'do {EOL',
+                     'try {EOL...} catch (...) {EOL...}');
     }
-
-
 }
-
-?>
index d95da4f3d2aae285607a27a3402dbb6104bb4147..0e85987d09bee467f5cc3e2fafe5eb4d88f908ad 100644 (file)
 /**
  * moodle_sniffs_controlstructures_elseifdeclarationsniff.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-controlstructures
- * @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-controlstructures
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 /**
  * Verifies that there are not elseif statements. The else and the if should
  * be separated by a space.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_controlstructures_elseifdeclarationsniff implements php_codesniffer_sniff
-{
+class moodle_sniffs_controlstructures_elseifdeclarationsniff implements php_codesniffer_sniff {
 
 
     /**
@@ -40,10 +40,8 @@ class moodle_sniffs_controlstructures_elseifdeclarationsniff implements php_code
      *
      * @return array
      */
-    public function register()
-    {
+    public function register() {
         return array(T_ELSEIF);
-
     }
 
 
@@ -56,15 +54,8 @@ class moodle_sniffs_controlstructures_elseifdeclarationsniff implements php_code
      *
      * @return void
      */
-    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
         $error = 'Usage of ELSEIF not allowed. Use ELSE IF instead.';
         $phpcsfile->adderror($error, $stackptr);
-
     }
-
-
 }
-
-
-?>
index 20d8030b3e642499bc152951fea2f1ba0263bd60..554dd695d42e8c8d54d82c4306b68ab17b85896a 100644 (file)
 /**
  * moodle_sniffs_controlstructures_inlinecontrolstructuresniff.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-controlstructures
- * @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-controlstructures
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 /**
  *
  * Verifies that inline control statements are not present.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_controlstructures_inlinecontrolstructuresniff implements php_codesniffer_sniff
-{
+class moodle_sniffs_controlstructures_inlinecontrolstructuresniff implements php_codesniffer_sniff {
 
     /**
      * A list of tokenizers this sniff supports.
      *
      * @var array
      */
-    public $supportedtokenizers = array(
-                                   'PHP',
-                                   'JS',
-                                  );
+    public $supportedtokenizers = array('PHP', 'JS');
 
     /**
      * If true, an error will be thrown; otherwise a warning.
@@ -55,18 +52,14 @@ class moodle_sniffs_controlstructures_inlinecontrolstructuresniff implements php
      *
      * @return array
      */
-    public function register()
-    {
-        return array(
-                T_IF,
-                T_ELSE,
-                T_FOREACH,
-                T_WHILE,
-                T_DO,
-                T_SWITCH,
-                T_FOR,
-               );
-
+    public function register() {
+        return array(T_IF,
+                     T_ELSE,
+                     T_FOREACH,
+                     T_WHILE,
+                     T_DO,
+                     T_SWITCH,
+                     T_FOR);
     }
 
 
@@ -79,8 +72,7 @@ class moodle_sniffs_controlstructures_inlinecontrolstructuresniff implements php
      *
      * @return void
      */
-    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
         $tokens = $phpcsfile->gettokens();
 
         if (isset($tokens[$stackptr]['scope_opener']) === false) {
@@ -91,11 +83,14 @@ class moodle_sniffs_controlstructures_inlinecontrolstructuresniff implements php
 
             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);
+                $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;
                         }
@@ -113,10 +108,5 @@ class moodle_sniffs_controlstructures_inlinecontrolstructuresniff implements php
 
             return;
         }
-
     }
-
-
 }
-
-?>
index d2cfeb66c1504d8f4eb458e1c84c444ce85713a9..42089a8a9c2e42f86b596a49e23d1be55182eaf7 100644 (file)
 /**
  * File including class for sniffing out the closing PHP tag
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-files
- * @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-files
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 /**
  * Class for sniffing out the closing PHP tag
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 class moodle_sniffs_files_closingphptagsniff implements php_codesniffer_sniff {
@@ -53,6 +54,7 @@ class moodle_sniffs_files_closingphptagsniff implements php_codesniffer_sniff {
         $tokens = $phpcsfile->gettokens();
 
         $last_token = end($tokens);
+
         if ($last_token['code'] === T_CLOSE_TAG) {
             $error  = 'Closing PHP tag is not required at the end of the file. Please remove.';
             $phpcsfile->addwarning($error, $stackptr);
index 08998e891116f3df81deceb0d7137665edfb9259..0906259564fa1a2588a0f5fcaa98747670b425c2 100644 (file)
 /**
  * moodle_sniffs_files_includingfilesniff.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-files
- * @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-files
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 /**
  * require_once is used elsewhere. Also checks that brackets do not surround
  * the file being included.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_files_includingfilesniff implements php_codesniffer_sniff
-{
+class moodle_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,
-                                  );
+    private static $_conditions = array(T_IF, T_ELSE, T_ELSEIF, T_SWITCH);
 
 
     /**
@@ -53,15 +48,8 @@ class moodle_sniffs_files_includingfilesniff implements php_codesniffer_sniff
      *
      * @return array
      */
-    public function register()
-    {
-        return array(
-                T_INCLUDE_ONCE,
-                T_REQUIRE_ONCE,
-                T_REQUIRE,
-                T_INCLUDE,
-               );
-
+    public function register() {
+        return array(T_INCLUDE_ONCE, T_REQUIRE_ONCE, T_REQUIRE, T_INCLUDE);
     }
 
 
@@ -74,11 +62,10 @@ class moodle_sniffs_files_includingfilesniff implements php_codesniffer_sniff
      *
      * @return void
      */
-    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
         $tokens = $phpcsfile->gettokens();
 
-        //$nexttoken = $phpcsfile->findNext(PHP_CodeSniffer_tokens::$emptyTokens, ($stackptr + 1), null, true);
+        //$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; ';
@@ -86,55 +73,57 @@ class moodle_sniffs_files_includingfilesniff implements php_codesniffer_sniff
         //    $phpcsfile->adderror($error, $stackptr);
         //}
 
-        $inCondition = (count($tokens[$stackptr]['conditions']) !== 0) ? true : false;
+        $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;
+                    $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);
+        $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;
+            $incondition = true;
         }
 
-        $tokenCode = $tokens[$stackptr]['code'];
-        if ($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) {
+            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) {
+
+            } 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) {
+            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) {
+
+            } else if ($tokencode === T_INCLUDE) {
                 $error  = 'File is being unconditionally included; ';
                 $error .= 'use "require" instead';
                 $phpcsfile->adderror($error, $stackptr);
             }
         }
-
     }
-
-
 }
-
-?>
index ec182c08a7f48c271bac3bfd8cd3673759b93948..e8ce7ca79a7a4117df6c7767d4f9e208ef20e991 100644 (file)
 /**
  * moodle_sniffs_files_lineendingssniff.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-files
- * @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-files
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 /**
  *
  * Checks that end of line characters are correct.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_files_lineendingssniff implements php_codesniffer_sniff
-{
+class moodle_sniffs_files_lineendingssniff implements php_codesniffer_sniff {
 
     /**
      * The valid EOL character.
@@ -46,8 +46,7 @@ class moodle_sniffs_files_lineendingssniff implements php_codesniffer_sniff
      *
      * @return array
      */
-    public function register()
-    {
+    public function register() {
         return array(T_OPEN_TAG);
 
     }
@@ -62,11 +61,11 @@ class moodle_sniffs_files_lineendingssniff implements php_codesniffer_sniff
      *
      * @return void
      */
-    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    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) {
+
+            if ($phpcsfile->findprevious(T_OPEN_TAG, ($stackptr - 1)) !== false) {
                 return;
             }
         }
@@ -83,8 +82,4 @@ class moodle_sniffs_files_lineendingssniff implements php_codesniffer_sniff
         }
 
     }
-
-
 }
-
-?>
index 7e3e94c569cea80304e64333a5e48ac30797f93c..3a79106fd4941bcdd59101c8d9e17dcaa832e7b8 100644 (file)
 /**
  * moodle_sniffs_files_linelengthsniff.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-files
- * @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-files
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 /**
  * characters in length and errors if they are over 100. Both these
  * figures can be changed by extending this sniff in your own standard.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_files_linelengthsniff implements php_codesniffer_sniff
-{
+class moodle_sniffs_files_linelengthsniff implements php_codesniffer_sniff {
 
     /**
      * The limit that the length of a line should not exceed.
      *
      * @var int
      */
-    protected $lineLimit = 120;
+    protected $linelimit = 120;
 
     /**
      * The limit that the length of a line must not exceed.
@@ -49,7 +49,7 @@ class moodle_sniffs_files_linelengthsniff implements php_codesniffer_sniff
      *
      * @var int
      */
-    protected $absolutelineLimit = 200;
+    protected $absolutelinelimit = 200;
 
 
     /**
@@ -57,10 +57,8 @@ class moodle_sniffs_files_linelengthsniff implements php_codesniffer_sniff
      *
      * @return array
      */
-    public function register()
-    {
+    public function register() {
         return array(T_OPEN_TAG);
-
     }
 
 
@@ -73,13 +71,13 @@ class moodle_sniffs_files_linelengthsniff implements php_codesniffer_sniff
      *
      * @return void
      */
-    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    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) {
+        $previousopentag = $phpcsfile->findprevious(array(T_OPEN_TAG), ($stackptr - 1));
+
+        if ($previousopentag !== false) {
             return;
         }
 
@@ -88,17 +86,19 @@ class moodle_sniffs_files_linelengthsniff implements php_codesniffer_sniff
         $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);
+                $this->checklinelength($phpcsfile, ($tokencount - 1), $currentlinecontent);
                 $currentlinecontent = $tokens[$tokencount]['content'];
                 $currentline++;
             }
         }
 
-        $this->checklineLength($phpcsfile, ($tokencount - 1), $currentlinecontent);
+        $this->checklinelength($phpcsfile, ($tokencount - 1), $currentlinecontent);
 
     }
 
@@ -112,25 +112,21 @@ class moodle_sniffs_files_linelengthsniff implements php_codesniffer_sniff
      *
      * @return void
      */
-    protected function checklineLength(PHP_CodeSniffer_File $phpcsfile, $stackptr, $linecontent)
-    {
+    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";
+            $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";
+
+            } else if ($linelength > $this->linelimit) {
+                $warning = 'line exceeds '.$this->linelimit." characters; contains $linelength characters";
                 $phpcsfile->addwarning($warning, $stackptr);
             }
         }
-
     }
-
-
 }
-
-?>
index 4927f712d4b570cd2c3dbb7d872218e3b291ee10..e510e3bd43bae289f62a67da2be0a610f2ae3b6f 100644 (file)
 /**
  * moodle_sniffs_formatting_spaceaftercastsniff.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-formatting
- * @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-formatting
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 /**
  *
  * Ensures there is a single space after cast tokens.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_formatting_spaceaftercastsniff implements php_codesniffer_sniff
-{
+class moodle_sniffs_formatting_spaceaftercastsniff implements php_codesniffer_sniff {
 
 
     /**
@@ -39,10 +39,8 @@ class moodle_sniffs_formatting_spaceaftercastsniff implements php_codesniffer_sn
      *
      * @return array
      */
-    public function register()
-    {
+    public function register() {
         return PHP_CodeSniffer_tokens::$castTokens;
-
     }
 
 
@@ -55,8 +53,7 @@ class moodle_sniffs_formatting_spaceaftercastsniff implements php_codesniffer_sn
      *
      * @return void
      */
-    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
         $tokens = $phpcsfile->gettokens();
 
         if ($tokens[($stackptr + 1)]['code'] !== T_WHITESPACE) {
@@ -69,10 +66,5 @@ class moodle_sniffs_formatting_spaceaftercastsniff implements php_codesniffer_sn
             $error = 'A cast statement must be followed by a single space';
             $phpcsfile->adderror($error, $stackptr);
         }
-
     }
-
-
 }
-
-?>
index 122139212d87ec40170cde04bd18224dfb3fbdcb..59f48013bc382c9a95c60faa30b50ea3c4ba5908 100644 (file)
 /**
  * moodle_sniffs_functions_functioncallargumentspacingsniff.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-functions
- * @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-functions
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 /**
  *
  * Checks that calls to methods and functions are spaced correctly.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_functions_functioncallargumentspacingsniff implements php_codesniffer_sniff
-{
+class moodle_sniffs_functions_functioncallargumentspacingsniff implements php_codesniffer_sniff {
 
 
     /**
@@ -39,10 +39,8 @@ class moodle_sniffs_functions_functioncallargumentspacingsniff implements php_co
      *
      * @return array
      */
-    public function register()
-    {
+    public function register() {
         return array(T_STRING);
-
     }
 
 
@@ -55,8 +53,7 @@ class moodle_sniffs_functions_functioncallargumentspacingsniff implements php_co
      *
      * @return void
      */
-    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
         $tokens = $phpcsfile->gettokens();
 
         // Skip tokens that are the names of functions or classes
@@ -65,44 +62,50 @@ class moodle_sniffs_functions_functioncallargumentspacingsniff implements php_co
         // "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) {
+        $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) {
+        $openbracket = $phpcsfile->findnext(PHP_CodeSniffer_tokens::$emptyTokens, ($functionname + 1), null, true);
+        if ($tokens[$openbracket]['code'] !== T_OPEN_PARENTHESIS) {
             return;
         }
 
-        $closeBracket = $tokens[$openBracket]['parenthesis_closer'];
+        $closebracket = $tokens[$openbracket]['parenthesis_closer'];
+
+        $nextseparator = $openbracket;
 
-        $nextSeperator = $openBracket;
-        while (($nextSeperator = $phpcsfile->findNext(array(T_COMMA, T_VARIABLE), ($nextSeperator + 1), $closeBracket)) !== false) {
+        while (($nextseparator = $phpcsfile->findnext(array(T_COMMA, T_VARIABLE), ($nextseparator + 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) {
+            $brackets    = $tokens[$nextseparator]['nested_parenthesis'];
+            $lastbracket = array_pop($brackets);
+
+            if ($lastbracket !== $closebracket) {
                 continue;
             }
 
-            if ($tokens[$nextSeperator]['code'] === T_COMMA) {
-                if ($tokens[($nextSeperator - 1)]['code'] === T_WHITESPACE) {
+            if ($tokens[$nextseparator]['code'] === T_COMMA) {
+
+                if ($tokens[($nextseparator - 1)]['code'] === T_WHITESPACE) {
                     $error = 'Space found before comma in function call';
                     $phpcsfile->addwarning($error, $stackptr);
                 }
 
-                if ($tokens[($nextSeperator + 1)]['code'] !== T_WHITESPACE) {
+                if ($tokens[($nextseparator + 1)]['code'] !== T_WHITESPACE) {
                     $error = 'No space found after comma in function call';
                     $phpcsfile->addwarning($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 (strpos($tokens[($nextseparator + 1)]['content'], $phpcsfile->eolChar) === false) {
+                        $space = strlen($tokens[($nextseparator + 1)]['content']);
+
                         if ($space > 1) {
                             $error  = 'Expected 1 space after comma in function call; ';
                             $error .= $space.' found';
@@ -110,11 +113,15 @@ class moodle_sniffs_functions_functioncallargumentspacingsniff implements php_co
                         }
                     }
                 }
+
             } else {
                 // token is a variable.
-                $nexttoken = $phpcsfile->findNext(PHP_CodeSniffer_tokens::$emptyTokens, ($nextSeperator + 1), $closeBracket, true);
+                $nexttoken = $phpcsfile->findnext(PHP_CodeSniffer_tokens::$emptyTokens, ($nextseparator + 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->addwarning($error, $stackptr);
@@ -128,10 +135,5 @@ class moodle_sniffs_functions_functioncallargumentspacingsniff implements php_co
                 }
             }
         }
-
     }
-
-
 }
-
-?>
index 2da9a624ff955af7dffb84c5ea3d1452023a6390..53514a6c20d03ee271c039a89e865a3d59a7a20f 100644 (file)
 /**
  * moodle_sniffs_functions_functioncallsignaturesniff.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-functions
- * @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-functions
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 /**
  * moodle_sniffs_functions_functioncallsignaturesniff.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_functions_functioncallsignaturesniff implements php_codesniffer_sniff
-{
+class moodle_sniffs_functions_functioncallsignaturesniff implements php_codesniffer_sniff {
 
 
     /**
@@ -37,10 +37,8 @@ class moodle_sniffs_functions_functioncallsignaturesniff implements php_codesnif
      *
      * @return array
      */
-    public function register()
-    {
+    public function register() {
         return array(T_STRING);
-
     }
 
 
@@ -53,12 +51,11 @@ class moodle_sniffs_functions_functioncallsignaturesniff implements php_codesnif
      *
      * @return void
      */
-    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
         $tokens = $phpcsfile->gettokens();
 
         // Find the next non-empty token.
-        $next = $phpcsfile->findNext(PHP_CodeSniffer_tokens::$emptyTokens, ($stackptr + 1), null, true);
+        $next = $phpcsfile->findnext(PHP_CodeSniffer_tokens::$emptyTokens, ($stackptr + 1), null, true);
 
         if ($tokens[$next]['code'] !== T_OPEN_PARENTHESIS) {
             // Not a function call.
@@ -71,7 +68,8 @@ class moodle_sniffs_functions_functioncallsignaturesniff implements php_codesnif
         }
 
         // Find the previous non-empty token.
-        $previous = $phpcsfile->findPrevious(PHP_CodeSniffer_tokens::$emptyTokens, ($stackptr - 1), null, true);
+        $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;
@@ -98,7 +96,7 @@ class moodle_sniffs_functions_functioncallsignaturesniff implements php_codesnif
 
         if ($tokens[($closer - 1)]['code'] === T_WHITESPACE) {
             // Checking this: $value = my_function(...[*]).
-            $between = $phpcsfile->findNext(T_WHITESPACE, ($next + 1), null, true);
+            $between = $phpcsfile->findnext(T_WHITESPACE, ($next + 1), null, true);
 
             // Only throw an error if there is some content between the parenthesis.
             // IE. Checking for this: $value = my_function().
@@ -111,17 +109,14 @@ class moodle_sniffs_functions_functioncallsignaturesniff implements php_codesnif
             }
         }
 
-        $next = $phpcsfile->findNext(T_WHITESPACE, ($closer + 1), null, true);
+        $next = $phpcsfile->findnext(T_WHITESPACE, ($closer + 1), null, true);
 
         if ($tokens[$next]['code'] === T_SEMICOLON) {
+
             if (in_array($tokens[($closer + 1)]['code'], PHP_CodeSniffer_tokens::$emptyTokens) === true) {
                 $error = 'Space after closing parenthesis of function call prohibited';
                 $phpcsfile->adderror($error, $closer);
             }
         }
-
     }
-
-
 }
-?>
index 1dcf2d1e9c4d9bccf1b7c2f9c46551b71deb5c73..87633d35294ccec22606cc1140af6449a7cf1289 100644 (file)
 /**
  * moodle_sniffs_functions_functiondeclarationsniff.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-functions
- * @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-functions
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 if (class_exists('PHP_CodeSniffer_Standards_AbstractPatternSniff', true) === false) {
@@ -31,11 +32,10 @@ if (class_exists('PHP_CodeSniffer_Standards_AbstractPatternSniff', true) === fal
  *
  * Checks the function declaration is correct.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_functions_functiondeclarationsniff extends php_codesniffer_standards_abstractpatternsniff
-{
+class moodle_sniffs_functions_functiondeclarationsniff extends php_codesniffer_standards_abstractpatternsniff {
 
 
     /**
@@ -43,16 +43,10 @@ class moodle_sniffs_functions_functiondeclarationsniff extends php_codesniffer_s
      *
      * @return array
      */
-    protected function getPatterns()
-    {
+    protected function getpatterns() {
         return array(
                 'function abc(...) {',
                 'abstract function abc(...);'
                );
-
     }
-
-
 }
-
-?>
index 776a3ffd86ac29aed8a1b0730e3bf9f02ac031d2..f88d545eb98409d50691ddc292d22e1b5b66515c 100644 (file)
 /**
  * moodle_sniffs_functions_lowercasefunctionkeywordssniff.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-functions
- * @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-functions
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 /**
  *
  * Ensures all class keywords are lowercase.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_functions_lowercasefunctionkeywordssniff implements php_codesniffer_sniff
-{
+class moodle_sniffs_functions_lowercasefunctionkeywordssniff implements php_codesniffer_sniff {
 
 
     /**
@@ -39,16 +39,8 @@ class moodle_sniffs_functions_lowercasefunctionkeywordssniff implements php_code
      *
      * @return array
      */
-    public function register()
-    {
-        return array(
-                T_FUNCTION,
-                T_PUBLIC,
-                T_PRIVATE,
-                T_PROTECTED,
-                T_STATIC,
-               );
-
+    public function register() {
+        return array(T_FUNCTION, T_PUBLIC, T_PRIVATE, T_PROTECTED, T_STATIC);
     }
 
 
@@ -61,21 +53,16 @@ class moodle_sniffs_functions_lowercasefunctionkeywordssniff implements php_code
      *
      * @return void
      */
-    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
         $tokens = $phpcsfile->gettokens();
 
         $content = $tokens[$stackptr]['content'];
+
         if ($content !== strtolower($content)) {
             $type     = strtoupper($content);
             $expected = strtolower($content);
             $error    = "$type keyword must be lowercase; expected \"$expected\" but found \"$content\"";
             $phpcsfile->adderror($error, $stackptr);
         }
-
     }
-
-
 }
-
-?>
index 835258a788e54506cb622107d2e0d6a14083c7ad..df5ff4dcc0f2a761fafa22beaf3f154128124630 100644 (file)
 /**
  * moodle_sniffs_functions_validdefaultvaluesniff.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-functions
- * @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-functions
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 /**
  * A Sniff to ensure that parameters defined for a function that have a default
  * value come at the end of the function signature.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_functions_validdefaultvaluesniff implements php_codesniffer_sniff
-{
+class moodle_sniffs_functions_validdefaultvaluesniff implements php_codesniffer_sniff {
 
 
     /**
@@ -40,10 +40,8 @@ class moodle_sniffs_functions_validdefaultvaluesniff implements php_codesniffer_
      *
      * @return array
      */
-    public function register()
-    {
+    public function register() {
         return array(T_FUNCTION);
-
     }
 
 
@@ -56,8 +54,7 @@ class moodle_sniffs_functions_validdefaultvaluesniff implements php_codesniffer_
      *
      * @return void
      */
-    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
         $tokens = $phpcsfile->gettokens();
 
         $argstart = $tokens[$stackptr]['parenthesis_opener'];
@@ -65,20 +62,22 @@ class moodle_sniffs_functions_validdefaultvaluesniff implements php_codesniffer_
 
         // 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;
+        $defaultfound = false;
+
+        $nextarg = $argstart;
 
-        $nextArg = $argstart;
-        while (($nextArg = $phpcsfile->findNext(T_VARIABLE, ($nextArg + 1), $argend)) !== false) {
-            $argHasDefault = self::_argHasDefault($phpcsfile, $nextArg);
-            if (($argHasDefault === false) && ($defaultFound === true)) {
+        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);
+                $phpcsfile->adderror($error, $nextarg);
                 return;
             }
 
-            if ($argHasDefault === true) {
-                $defaultFound = true;
+            if ($arghasdefault === true) {
+                $defaultfound = true;
             }
         }
 
@@ -89,15 +88,15 @@ class moodle_sniffs_functions_validdefaultvaluesniff implements php_codesniffer_
      * 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
+     * @param int                  $argptr    The position of the argument
      *                                        in the stack.
      *
      * @return bool
      */
-    private static function _argHasDefault(PHP_CodeSniffer_File $phpcsfile, $argPtr)
-    {
+    private static function _arghasdefault(PHP_CodeSniffer_File $phpcsfile, $argptr) {
         $tokens    = $phpcsfile->gettokens();
-        $nexttoken = $phpcsfile->findNext(PHP_CodeSniffer_tokens::$emptyTokens, ($argPtr + 1), null, true);
+        $nexttoken = $phpcsfile->findnext(PHP_CodeSniffer_tokens::$emptyTokens, ($argptr + 1), null, true);
+
         if ($tokens[$nexttoken]['code'] !== T_EQUAL) {
             return false;
         }
@@ -108,5 +107,3 @@ class moodle_sniffs_functions_validdefaultvaluesniff implements php_codesniffer_
 
 
 }
-
-?>
index 3c4ddb92ea9192f2ee1a39dc5fe3b409788d4b64..92e487d9d4fd8f6d4505585ef7ee24fb40d16ddc 100644 (file)
 /**
  * moodle_sniffs_namingconventions_uppercaseconstantnamesniff.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-namingconventions
- * @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-namingconventions
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 /**
  *
  * Ensures that constant names are all uppercase.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_namingconventions_uppercaseconstantnamesniff implements php_codesniffer_sniff
-{
+class moodle_sniffs_namingconventions_uppercaseconstantnamesniff implements php_codesniffer_sniff {
 
 
     /**
@@ -39,10 +39,8 @@ class moodle_sniffs_namingconventions_uppercaseconstantnamesniff implements php_
      *
      * @return array
      */
-    public function register()
-    {
+    public function register() {
         return array(T_STRING);
-
     }
 
 
@@ -55,8 +53,7 @@ class moodle_sniffs_namingconventions_uppercaseconstantnamesniff implements php_
      *
      * @return void
      */
-    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
         $tokens    = $phpcsfile->gettokens();
         $constname = $tokens[$stackptr]['content'];
 
@@ -67,28 +64,24 @@ class moodle_sniffs_namingconventions_uppercaseconstantnamesniff implements php_
 
         // 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) {
+        $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) {
+            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";
+                    $error = 'Class constants must be uppercase; expected '.strtoupper($constname).
+                             " but found $constname";
                     $phpcsfile->adderror($error, $stackptr);
                 }
 
@@ -96,27 +89,31 @@ class moodle_sniffs_namingconventions_uppercaseconstantnamesniff implements php_
             }
 
             // Is this a class name?
-            $nextPtr = $phpcsfile->findNext(array(T_WHITESPACE), ($stackptr + 1), null, true);
-            if ($tokens[$nextPtr]['code'] === T_DOUBLE_COLON) {
+            $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) {
+            if ($tokens[$nextptr]['code'] === T_VARIABLE) {
                 return;
-            } else if ($phpcsfile->isReference($nextPtr) === true) {
+
+            } 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) {
+            $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) {
+            $prevptr = $phpcsfile->findprevious(array(T_WHITESPACE, T_OPEN_PARENTHESIS), ($stackptr - 1), null, true);
+
+            if ($tokens[$prevptr]['code'] === T_DECLARE) {
                 return;
             }
 
@@ -133,21 +130,18 @@ class moodle_sniffs_namingconventions_uppercaseconstantnamesniff implements php_
             */
 
             // 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) {
+            $constptr = $phpcsfile->findnext(array(T_WHITESPACE), ($openbracket + 1), null, true);
+
+            if ($tokens[$constptr]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
                 return;
             }
 
-            $constname = $tokens[$constPtr]['content'];
+            $constname = $tokens[$constptr]['content'];
+
             if (strtoupper($constname) !== $constname) {
                 $error = 'Constants must be uppercase; expected '.strtoupper($constname)." but found $constname";
                 $phpcsfile->adderror($error, $stackptr);
             }
         }
-
     }
-
-
 }
-
-?>
index 9f337aff374a806cc4de770123c17b4bc15f30ad..b468f2ce9d01079460a238656650f2e88058694c 100644 (file)
 /**
  * moodle_sniffs_namingconventions_validclassnamesniff.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-namingconventions
- * @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-namingconventions
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 /**
  * Ensures class and interface names start with a capital letter
  * and use _ separators.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_namingconventions_validclassnamesniff implements php_codesniffer_sniff
-{
+class moodle_sniffs_namingconventions_validclassnamesniff implements php_codesniffer_sniff {
 
 
     /**
@@ -40,13 +40,8 @@ class moodle_sniffs_namingconventions_validclassnamesniff implements php_codesni
      *
      * @return array
      */
-    public function register()
-    {
-        return array(
-                T_CLASS,
-                T_INTERFACE,
-               );
-
+    public function register() {
+        return array(T_CLASS, T_INTERFACE);
     }
 
 
@@ -59,11 +54,10 @@ class moodle_sniffs_namingconventions_validclassnamesniff implements php_codesni
      *
      * @return void
      */
-    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
         $tokens = $phpcsfile->gettokens();
 
-        $classname = $phpcsfile->findNext(T_STRING, $stackptr);
+        $classname = $phpcsfile->findnext(T_STRING, $stackptr);
         $name      = trim($tokens[$classname]['content']);
 
         // Make sure that the word is all lowercase
@@ -72,11 +66,5 @@ class moodle_sniffs_namingconventions_validclassnamesniff implements php_codesni
             $error = ucfirst($tokens[$stackptr]['content']).' name is not valid, must be all lower-case';
             $phpcsfile->adderror($error, $stackptr);
         }
-
     }
-
-
 }
-
-
-?>
index d0bfb52943c63239170d97215a4c407d70dbdeaa..c37744160d4de246367ecac4c06cac48d03cb283 100644 (file)
 /**
  * moodle_sniffs_namingconventions_validfunctionnamesniff.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-namingconventions
- * @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-namingconventions
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 if (class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false) {
@@ -32,11 +33,10 @@ if (class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false
  * Ensures method names are correct depending on whether they are public
  * or private, and that functions are named correctly.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_namingconventions_validfunctionnamesniff extends php_codesniffer_standards_abstractscopesniff
-{
+class moodle_sniffs_namingconventions_validfunctionnamesniff extends php_codesniffer_standards_abstractscopesniff {
 
     /**
      * A list of all PHP magic methods.
@@ -64,18 +64,14 @@ class moodle_sniffs_namingconventions_validfunctionnamesniff extends php_codesni
      *
      * @var array
      */
-    private $_magicFunctions = array(
-                                'autoload',
-                               );
+    private $_magicfunctions = array('autoload');
 
 
     /**
      * Constructs a moodle_sniffs_namingconventions_validfunctionnamesniff.
      */
-    public function __construct()
-    {
+    public function __construct() {
         parent::__construct(array(T_CLASS, T_INTERFACE), array(T_FUNCTION), true);
-
     }
 
 
@@ -85,20 +81,21 @@ class moodle_sniffs_namingconventions_validfunctionnamesniff extends php_codesni
      * @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.
+     * @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);
+    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";
+            $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);
             }
 
@@ -115,14 +112,15 @@ class moodle_sniffs_namingconventions_validfunctionnamesniff extends php_codesni
             return;
         }
 
-        $methodProps    = $phpcsfile->getmethodProperties($stackptr);
-        $isPublic       = ($methodProps['scope'] === 'private') ? false : true;
-        $scope          = $methodProps['scope'];
-        $scopeSpecified = $methodProps['scope_specified'];
+        $methodprops    = $phpcsfile->getmethodproperties($stackptr);
+        $ispublic       = ($methodprops['scope'] === 'private') ? false : true;
+        $scope          = $methodprops['scope'];
+        $scopespecified = $methodprops['scope_specified'];
 
         // Only lower-case accepted
         if (preg_match('/[A-Z]+/', $methodname)) {
-            if ($scopeSpecified === true) {
+
+            if ($scopespecified === true) {
                 $error = ucfirst($scope)." method name \"$classname::$methodname\" must be in lower-case letters only";
             } else {
                 $error = "method name \"$classname::$methodname\" must be in lower-case letters only";
@@ -134,7 +132,8 @@ class moodle_sniffs_namingconventions_validfunctionnamesniff extends php_codesni
 
         // No numbers accepted
         if (preg_match('/[0-9]+/', $methodname)) {
-            if ($scopeSpecified === true) {
+
+            if ($scopespecified === true) {
                 $error = ucfirst($scope)." method name \"$classname::$methodname\" must only contain letters";
             } else {
                 $error = "Method name \"$classname::$methodname\" must only contain letters";
@@ -156,15 +155,16 @@ class moodle_sniffs_namingconventions_validfunctionnamesniff extends php_codesni
      *
      * @return void
      */
-    protected function processtokenOutsideScope(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
-        $functionname = $phpcsfile->getDeclarationname($stackptr);
+    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";
+            $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);
             }
 
@@ -191,5 +191,3 @@ class moodle_sniffs_namingconventions_validfunctionnamesniff extends php_codesni
 
 
 }
-
-?>
index 314e23684ed390e5950211b33cb3ca1907535085..af1868b20c026eb536a6a2eb6e0ff4cf0f86383d 100644 (file)
 /**
  * moodle_sniffs_namingconventions_validvariablenamesniff.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-namingconventions
- * @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-namingconventions
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 if (class_exists('PHP_CodeSniffer_Standards_AbstractVariableSniff', true) === false) {
@@ -32,11 +33,10 @@ if (class_exists('PHP_CodeSniffer_Standards_AbstractVariableSniff', true) === fa
  *
  * Checks the naming of member variables.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_namingconventions_validvariablenamesniff extends php_codesniffer_standards_abstractvariablesniff
-{
+class moodle_sniffs_namingconventions_validvariablenamesniff extends php_codesniffer_standards_abstractvariablesniff {
 
     private $allowed_global_vars = array('CFG', 'SESSION', 'USER', 'COURSE', 'SITE', 'PAGE', 'DB', 'THEME',
                                          '_SERVER', '_GET', '_POST', '_FILES', '_REQUEST', '_SESSION',
@@ -51,10 +51,10 @@ class moodle_sniffs_namingconventions_validvariablenamesniff extends php_codesni
      *
      * @return void
      */
-    protected function processMemberVar(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    protected function processmembervar(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
         $tokens = $phpcsfile->gettokens();
         $membername     = ltrim($tokens[$stackptr]['content'], '$');
+
         if (preg_match('/[A-Z]+/', $membername)) {
             $error = "Member variable \"$membername\" must be all lower-case";
             $phpcsfile->adderror($error, $stackptr);
@@ -62,13 +62,14 @@ class moodle_sniffs_namingconventions_validvariablenamesniff extends php_codesni
         }
 
         // Must not be preceded by 'var' keyword
-        $keyword = $phpcsfile->findPrevious(T_VAR, $stackptr);
+        $keyword = $phpcsfile->findprevious(T_VAR, $stackptr);
+
         if ($tokens[$keyword]['line'] == $tokens[$stackptr]['line']) {
-            $error = "The 'var' keyword is not permitted. Visibility must be explicitly declared with public, private or protected";
+            $error = "The 'var' keyword is not permitted." .
+                     'Visibility must be explicitly declared with public, private or protected';
             $phpcsfile->adderror($error, $stackptr);
             return;
         }
-
     }
 
 
@@ -80,18 +81,18 @@ class moodle_sniffs_namingconventions_validvariablenamesniff extends php_codesni
      *
      * @return void
      */
-    protected function processVariable(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    protected function processvariable(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
         $tokens = $phpcsfile->gettokens();
         $membername     = ltrim($tokens[$stackptr]['content'], '$');
+
         if (preg_match('/[A-Z]+/', $membername)) {
+
             if (!in_array($membername, $this->allowed_global_vars)) {
                 $error = "Member variable \"$membername\" must be all lower-case";
                 $phpcsfile->adderror($error, $stackptr);
                 return;
             }
         }
-
     }
 
 
index 8e02f317eb659eb3349d204f8f14b88d3f9e069e..e88658352b899d7873b2c0ec96c383e7255fe750 100644 (file)
 /**
  * moodle_sniffs_php_disallowshortopentagsniff.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-php
- * @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-php
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 /**
  *
  * Makes sure that shorthand PHP open tags are not used.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_php_disallowshortopentagsniff implements php_codesniffer_sniff
-{
+class moodle_sniffs_php_disallowshortopentagsniff implements php_codesniffer_sniff {
 
 
     /**
@@ -39,13 +39,8 @@ class moodle_sniffs_php_disallowshortopentagsniff implements php_codesniffer_sni
      *
      * @return array
      */
-    public function register()
-    {
-        return array(
-                T_OPEN_TAG,
-                T_OPEN_TAG_WITH_ECHO,
-               );
-
+    public function register() {
+        return array(T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO);
     }
 
 
@@ -58,8 +53,7 @@ class moodle_sniffs_php_disallowshortopentagsniff implements php_codesniffer_sni
      *
      * @return void
      */
-    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    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.
@@ -79,15 +73,11 @@ class moodle_sniffs_php_disallowshortopentagsniff implements php_codesniffer_sni
         }
 
         if ($opentag['code'] === T_OPEN_TAG_WITH_ECHO) {
-            $nextVar = $tokens[$phpcsfile->findNext(PHP_CodeSniffer_tokens::$emptyTokens, ($stackptr + 1), null, true)];
+            $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'].' ...".';
+            $error  .= $opentag['content'].' '.$nextvar['content'].' ..." but expected "<?php echo '.
+                       $nextvar['content'].' ...".';
             $phpcsfile->adderror($error, $stackptr);
         }
-
     }
-
-
 }
-
-?>
index 26ac008cfb914c20e278247f983b6f800664735c..5dcd21ebedf3bb286eb2828d271926e666bb8b3f 100644 (file)
 /**
  * moodle_sniffs_php_lowercaseconstantsniff.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-php
- * @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-php
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 /**
  *
  * Checks that all uses of true, false and null are lowerrcase.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_php_lowercaseconstantsniff implements php_codesniffer_sniff
-{
+class moodle_sniffs_php_lowercaseconstantsniff implements php_codesniffer_sniff {
 
     /**
      * A list of tokenizers this sniff supports.
      *
      * @var array
      */
-    public $supportedtokenizers = array(
-                                   'PHP',
-                                   'JS',
-                                  );
+    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,
-               );
+    public function register() {
+        return array(T_TRUE, T_FALSE, T_NULL);
 
     }
 
@@ -68,19 +60,15 @@ class moodle_sniffs_php_lowercaseconstantsniff implements php_codesniffer_sniff
      *
      * @return void
      */
-    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    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.'"';
+            $error = 'TRUE, FALSE and NULL must be lowercase; expected "'.
+                     strtolower($keyword).'" but found "'.$keyword.'"';
             $phpcsfile->adderror($error, $stackptr);
         }
-
     }
-
-
 }
-
-?>
index 57683c8537cfbda8cc43f775fb2c8a7a2a07500e..e52e3f8b6a1b6a41b4c6a04666d81af0702d091c 100644 (file)
 /**
  * moodle_sniffs_php_lowercasephpfunctionssniff.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-php
- * @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-php
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 /**
  *
  * Ensures all calls to inbuilt PHP functions are lowercase.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_php_lowercasephpfunctionssniff implements php_codesniffer_sniff
-{
+class moodle_sniffs_php_lowercasephpfunctionssniff implements php_codesniffer_sniff {
 
 
     /**
@@ -39,8 +39,7 @@ class moodle_sniffs_php_lowercasephpfunctionssniff implements php_codesniffer_sn
      *
      * @return array
      */
-    public function register()
-    {
+    public function register() {
         return array(
                 T_ISSET,
                 T_ECHO,
@@ -61,7 +60,6 @@ class moodle_sniffs_php_lowercasephpfunctionssniff implements php_codesniffer_sn
                 T_DECLARE,
                 T_STRING,
                );
-
     }
 
 
@@ -74,12 +72,12 @@ class moodle_sniffs_php_lowercasephpfunctionssniff implements php_codesniffer_sn
      *
      * @return void
      */
-    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
         $tokens = $phpcsfile->gettokens();
 
         if ($tokens[$stackptr]['code'] !== T_STRING) {
             $content = $tokens[$stackptr]['content'];
+
             if ($content !== strtolower($content)) {
                 $type     = strtoupper($content);
                 $expected = strtolower($content);
@@ -91,7 +89,8 @@ class moodle_sniffs_php_lowercasephpfunctionssniff implements php_codesniffer_sn
         }
 
         // Make sure this is a function call.
-        $next = $phpcsfile->findNext(T_WHITESPACE, ($stackptr + 1), null, true);
+        $next = $phpcsfile->findnext(T_WHITESPACE, ($stackptr + 1), null, true);
+
         if ($next === false) {
             // Not a function call.
             return;
@@ -102,7 +101,8 @@ class moodle_sniffs_php_lowercasephpfunctionssniff implements php_codesniffer_sn
             return;
         }
 
-        $prev = $phpcsfile->findPrevious(T_WHITESPACE, ($stackptr - 1), null, true);
+        $prev = $phpcsfile->findprevious(T_WHITESPACE, ($stackptr - 1), null, true);
+
         if ($tokens[$prev]['code'] === T_FUNCTION) {
             // Function declaration, not a function call.
             return;
@@ -123,19 +123,15 @@ class moodle_sniffs_php_lowercasephpfunctionssniff implements php_codesniffer_sn
         // user defined global functions can exist, except for
         // PHP_CodeSniffer ones.
         $content = $tokens[$stackptr]['content'];
+
         if (function_exists($content) === false) {
             return;
         }
 
         if ($content !== strtolower($content)) {
             $expected = strtolower($content);
-            $error    = "Calls to inbuilt PHP functions must be lowercase; expected \"$expected\" but found \"$content\"";
+            $error = "Calls to inbuilt PHP functions must be lowercase; expected \"$expected\" but found \"$content\"";
             $phpcsfile->adderror($error, $stackptr);
         }
-
     }
-
-
 }
-
-?>
index bf20d210e976a56991cfd7b2a2e7231ba85240cb..53c2a096383fe13afcc1ab236404e940d836fef9 100644 (file)
 /**
  * moodle_sniffs_strings_doublequoteusagesniff.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-strings
- * @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-strings
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 /**
  *
  * Makes sure that any use of Double Quotes ("") are warranted.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_strings_doublequoteusagesniff implements php_codesniffer_sniff
-{
+class moodle_sniffs_strings_doublequoteusagesniff implements php_codesniffer_sniff {
 
 
     /**
@@ -39,12 +39,8 @@ class moodle_sniffs_strings_doublequoteusagesniff implements php_codesniffer_sni
      *
      * @return array
      */
-    public function register()
-    {
-        return array(
-                T_CONSTANT_ENCAPSED_STRING,
-               );
-
+    public function register() {
+        return array(T_CONSTANT_ENCAPSED_STRING);
     }
 
 
@@ -57,34 +53,33 @@ class moodle_sniffs_strings_doublequoteusagesniff implements php_codesniffer_sni
      *
      * @return void
      */
-    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
         $tokens = $phpcsfile->gettokens();
 
-        $workingString = $tokens[$stackptr]['content'];
+        $workingstring = $tokens[$stackptr]['content'];
 
         // Check if it's a double quoted string.
-        if (strpos($workingString, '"') === false) {
+        if (strpos($workingstring, '"') === false) {
             return;
         }
 
         // Make sure it's not a part of a string started above.
         // If it is, then we have already checked it.
-        if ($workingString[0] !== '"') {
+        if ($workingstring[0] !== '"') {
             return;
         }
 
         // Work through the following tokens, in case this string is stretched
         // over multiple Lines.
         for ($i = ($stackptr + 1); $i < $phpcsfile->numTokens; $i++) {
+
             if ($tokens[$i]['type'] !== 'T_CONSTANT_ENCAPSED_STRING') {
                 break;
             }
-
-            $workingString .= $tokens[$i]['content'];
+            $workingstring .= $tokens[$i]['content'];
         }
 
-        $allowedChars = array(
+        $allowedchars = array(
                          '\n',
                          '\r',
                          '\f',
@@ -92,20 +87,17 @@ class moodle_sniffs_strings_doublequoteusagesniff implements php_codesniffer_sni
                          '\v',
                          '\x',
                          '\'',
+                         '$'
                         );
 
-        foreach ($allowedChars as $testChar) {
-            if (strpos($workingString, $testChar) !== false) {
+        foreach ($allowedchars as $testchar) {
+
+            if (strpos($workingstring, $testchar) !== false) {
                 return;
             }
         }
 
-        $error = "String $workingString does not require double quotes; use single quotes instead";
+        $error = "String $workingstring does not require double quotes; use single quotes instead";
         $phpcsfile->addwarning($error, $stackptr);
-
     }
-
-
 }
-
-?>
index d56794b1c13dc1c8e424f70682246517b4bcf36b..99e8e8656981387693c1c2b4ab718d1eab3c4e80 100644 (file)
 /**
  * moodle_sniffs_strings_echoedstringssniff.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-strings
- * @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-strings
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 /**
  * Makes sure that any strings that are "echoed" are not enclosed in brackets
  * like a function call.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_strings_echoedstringssniff implements php_codesniffer_sniff
-{
+class moodle_sniffs_strings_echoedstringssniff implements php_codesniffer_sniff {
 
 
     /**
@@ -40,10 +40,8 @@ class moodle_sniffs_strings_echoedstringssniff implements php_codesniffer_sniff
      *
      * @return array
      */
-    public function register()
-    {
+    public function register() {
         return array(T_ECHO);
-
     }
 
 
@@ -56,32 +54,26 @@ class moodle_sniffs_strings_echoedstringssniff implements php_codesniffer_sniff
      *
      * @return void
      */
-    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
         $tokens = $phpcsfile->gettokens();
 
-        $firstcontent = $phpcsfile->findNext(array(T_WHITESPACE), ($stackptr + 1), null, true);
+        $firstcontent = $phpcsfile->findnext(array(T_WHITESPACE), ($stackptr + 1), null, true);
         // If the first non-whitespace token is not an opening parenthesis, then we are not concerned.
         if ($tokens[$firstcontent]['code'] !== T_OPEN_PARENTHESIS) {
             return;
         }
 
-        $endOfStatement = $phpcsfile->findNext(array(T_SEMICOLON), $stackptr, null, false);
+        $endofstatement = $phpcsfile->findnext(array(T_SEMICOLON), $stackptr, null, false);
 
         // If the token before the semi-colon is not a closing parenthesis, then we are not concerned.
-        if ($tokens[($endOfStatement - 1)]['code'] !== T_CLOSE_PARENTHESIS) {
+        if ($tokens[($endofstatement - 1)]['code'] !== T_CLOSE_PARENTHESIS) {
             return;
         }
 
-        if (($phpcsfile->findNext(PHP_CodeSniffer_tokens::$operators, $stackptr, $endOfStatement, false)) === false) {
+        if (($phpcsfile->findnext(PHP_CodeSniffer_tokens::$operators, $stackptr, $endofstatement, false)) === false) {
             // There are no arithmetic operators in this.
             $error = 'Echoed strings should not be bracketed';
             $phpcsfile->adderror($error, $stackptr);
         }
-
     }
-
-
 }
-
-?>
index 4171f8bcf8f57db6c2a32738f09eb2b81dedbf32..8456ff2484c0d118f8b484357425dbb7af8ee2b2 100644 (file)
 /**
  * moodle_sniffs_whitespace_controlstructureblanklinesniff
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-whitespace
- * @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-whitespace
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 /**
@@ -27,7 +28,7 @@
  *
  * Checks that there is a blank line before control structures
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 class moodle_sniffs_whitespace_controlstructureblanklinesniff implements php_codesniffer_sniff {
@@ -58,14 +59,21 @@ class moodle_sniffs_whitespace_controlstructureblanklinesniff implements php_cod
 
         // Move back until we find the previous non-whitespace, non-comment token
         do {
-            $previoustoken = $phpcsfile->findprevious(array(T_WHITESPACE, T_COMMENT, T_DOC_COMMENT), ($previoustoken - 1), null, true);
+            $previoustoken = $phpcsfile->findprevious(array(T_WHITESPACE, T_COMMENT, T_DOC_COMMENT),
+                                                      ($previoustoken - 1), null, true);
+
         } while ($tokens[$previoustoken]['line'] == $tokens[$stackptr]['line']);
 
         $previous_non_ws_token = $tokens[$previoustoken];
 
         // If this token is immediately on the line before this control structure, print a warning
         if ($previous_non_ws_token['line'] == ($tokens[$stackptr]['line'] - 1)) {
-            $phpcsfile->addWarning('You should add a blank line before control structures', $stackptr);
+            // Exception: do {EOL...} while (...);
+            if ($tokens[$stackptr]['code'] == T_WHILE && $tokens[($stackptr - 1)]['code'] == T_CLOSE_CURLY_BRACKET) {
+                // Ignore do...while (see above)
+            } else {
+                $phpcsfile->addWarning('You should add a blank line before control structures', $stackptr);
+            }
         }
     }
 }
index 9c5fc2cefd65a22f98b8d182408245092b3737f4..8a142c137ca766053e600a2a910e424cdbfd87a6 100644 (file)
 /**
  * moodle_sniffs_whitespace_disallowtabindentsniff.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-whitespace
- * @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-whitespace
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 /**
  *
  * Throws errors if tabs are used for indentation.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_whitespace_disallowtabindentsniff implements php_codesniffer_sniff
-{
+class moodle_sniffs_whitespace_disallowtabindentsniff implements php_codesniffer_sniff {
 
     /**
      * A list of tokenizers this sniff supports.
      *
      * @var array
      */
-    public $supportedtokenizers = array(
-                                   'PHP',
-                                   'JS',
-                                  );
+    public $supportedtokenizers = array('PHP', 'JS');
 
 
     /**
@@ -49,10 +46,8 @@ class moodle_sniffs_whitespace_disallowtabindentsniff implements php_codesniffer
      *
      * @return array
      */
-    public function register()
-    {
+    public function register() {
         return array(T_WHITESPACE);
-
     }
 
 
@@ -65,12 +60,12 @@ class moodle_sniffs_whitespace_disallowtabindentsniff implements php_codesniffer
      *
      * @return void
      */
-    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    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;
         }
@@ -79,10 +74,5 @@ class moodle_sniffs_whitespace_disallowtabindentsniff implements php_codesniffer
             $error = 'Spaces must be used to indent lines; tabs are not allowed';
             $phpcsfile->adderror($error, $stackptr);
         }
-
     }
-
-
 }
-
-?>
index 1b6ec79a1a8bbd57a515ec520f7fe8ae38f51541..429ea305341d8dadf98ee1e5668bfad312951415 100644 (file)
 /**
  * Verifies that class members are spaced correctly.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-whitespace
- * @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-whitespace
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 if (class_exists('PHP_CodeSniffer_Standards_AbstractVariableSniff', true) === false) {
@@ -29,11 +30,10 @@ if (class_exists('PHP_CodeSniffer_Standards_AbstractVariableSniff', true) === fa
 /**
  * Verifies that class members are spaced correctly.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_whitespace_membervarspacingsniff extends php_codesniffer_standards_abstractvariablesniff
-{
+class moodle_sniffs_whitespace_membervarspacingsniff extends php_codesniffer_standards_abstractvariablesniff {
 
 
     /**
@@ -44,24 +44,28 @@ class moodle_sniffs_whitespace_membervarspacingsniff extends php_codesniffer_sta
      *
      * @return void
      */
-    protected function processMemberVar(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    protected function processmembervar(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
         $tokens = $phpcsfile->gettokens();
 
         // There needs to be 1 blank line before the var, not counting comments.
         $prevlinetoken = null;
+
         for ($i = ($stackptr - 1); $i > 0; $i--) {
+
             if (in_array($tokens[$i]['code'], PHP_CodeSniffer_tokens::$commentTokens) === true) {
                 // Skip comments.
                 continue;
+
             } else if (strpos($tokens[$i]['content'], $phpcsfile->eolChar) === false) {
                 // Not the end of the line.
                 continue;
+
             } else {
                 // If this is a WHITESPACE token, and the token right before
                 // it is a DOC_COMMENT, then it is just the newline after the
                 // member var's comment, and can be skipped.
-                if ($tokens[$i]['code'] === T_WHITESPACE && in_array($tokens[($i - 1)]['code'], PHP_CodeSniffer_tokens::$commentTokens) === true) {
+                if ($tokens[$i]['code'] === T_WHITESPACE &&
+                    in_array($tokens[($i - 1)]['code'], PHP_CodeSniffer_tokens::$commentTokens) === true) {
                     continue;
                 }
 
@@ -74,15 +78,15 @@ class moodle_sniffs_whitespace_membervarspacingsniff extends php_codesniffer_sta
             // Never found the previous line, which means
             // there are 0 blank lines before the member var.
             $foundlines = 0;
+
         } else {
-            $prevcontent = $phpcsfile->findPrevious(array(T_WHITESPACE, T_DOC_COMMENT), $prevlinetoken, null, true);
+            $prevcontent = $phpcsfile->findprevious(array(T_WHITESPACE, T_DOC_COMMENT), $prevlinetoken, null, true);
             $foundlines  = ($tokens[$prevlinetoken]['line'] - $tokens[$prevcontent]['line']);
         }
 
         if ($foundlines !== 1) {
             // $phpcsfile->adderror("Expected 1 blank line before member var; $foundlines found", $stackptr);
         }
-
     }
 
 
@@ -94,11 +98,9 @@ class moodle_sniffs_whitespace_membervarspacingsniff extends php_codesniffer_sta
      *
      * @return void
      */
-    protected function processVariable(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    protected function processvariable(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
         // We don't care about normal variables.
         return;
-
     }
 
 
@@ -110,14 +112,8 @@ class moodle_sniffs_whitespace_membervarspacingsniff extends php_codesniffer_sta
      *
      * @return void
      */
-    protected function processVariableInString(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    protected function processvariableinstring(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
         // We don't care about normal variables.
         return;
-
     }
-
-
 }
-
-?>
index 08f79f3a94c75a8a47b1f97deb679e36cbdea768..f21e0547fcc9bf5c957b1c3c79c18e66ffdd74ea 100644 (file)
 /**
  * moodle_sniffs_whitespace_scopeclosingbracesniff.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-whitespace
- * @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-whitespace
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 /**
  *
  * Checks that the closing braces of scopes are aligned correctly.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_whitespace_scopeclosingbracesniff implements php_codesniffer_sniff
-{
+class moodle_sniffs_whitespace_scopeclosingbracesniff implements php_codesniffer_sniff {
 
 
     /**
@@ -39,10 +39,8 @@ class moodle_sniffs_whitespace_scopeclosingbracesniff implements php_codesniffer
      *
      * @return array
      */
-    public function register()
-    {
+    public function register() {
         return PHP_CodeSniffer_tokens::$scopeOpeners;
-
     }
 
 
@@ -55,8 +53,7 @@ class moodle_sniffs_whitespace_scopeclosingbracesniff implements php_codesniffer
      *
      * @return void
      */
-    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
         $tokens = $phpcsfile->gettokens();
 
         // If this is an inline condition (ie. there is no scope opener), then
@@ -70,7 +67,9 @@ class moodle_sniffs_whitespace_scopeclosingbracesniff implements php_codesniffer
         // 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;
             }
@@ -78,14 +77,15 @@ class moodle_sniffs_whitespace_scopeclosingbracesniff implements php_codesniffer
 
         // 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);
+        $linestart = $phpcsfile->findnext(array(T_WHITESPACE), ($linestart + 1), null, true);
 
-        $startColumn = $tokens[$linestart]['column'];
+        $startcolumn = $tokens[$linestart]['column'];
         $scopestart  = $tokens[$stackptr]['scope_opener'];
         $scopeend    = $tokens[$stackptr]['scope_closer'];
 
         // Check that the closing brace is on its own line.
-        $lastcontent = $phpcsfile->findPrevious(array(T_WHITESPACE), ($scopeend - 1), $scopestart, true);
+        $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);
@@ -93,29 +93,29 @@ class moodle_sniffs_whitespace_scopeclosingbracesniff implements php_codesniffer
         }
 
         // 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) {
+        $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);
+            if ($braceindent !== ($startcolumn + 4)) {
+                $error = 'Break statement indented incorrectly; expected '.($startcolumn + 3).' spaces, found '.
+                         ($braceindent - 1);
                 $phpcsfile->adderror($error, $scopeend);
             }
+
         } else {
+
             if (in_array($tokens[$stackptr]['code'], array(T_CASE, T_DEFAULT))) {
-                $startColumn -= 4;
+                $startcolumn -= 4;
             }
 
-            if ($braceIndent !== $startColumn) {
-                $error = 'Closing brace indented incorrectly; expected '.($startColumn - 1).' spaces, found '.($braceIndent - 1);
+            if ($braceindent !== $startcolumn) {
+                $error = 'Closing brace indented incorrectly; expected '.($startcolumn - 1).' spaces, found '.
+                         ($braceindent - 1);
                 $phpcsfile->adderror($error, $scopeend);
             }
         }
-
     }
-
-
 }
-
-?>
index 32ecb681e79cc7c608bb731a55302acf188e7c7d..ce3f0a617bf41c122b6d7a2fe2c7a560c3da589f 100644 (file)
 /**
  * moodle_sniffs_whitespace_scopeindentsniff.
  *
- * @package   lib-pear-php-codesniffer-standards-moodle-sniffs-whitespace
- * @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-whitespace
+ * @copyright  2009 Nicolas Connault
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 /**
  * is indented correctly. This sniff will throw errors if tabs are used
  * for indentation rather than spaces.
  *
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class moodle_sniffs_whitespace_scopeindentsniff implements php_codesniffer_sniff
-{
+class moodle_sniffs_whitespace_scopeindentsniff implements php_codesniffer_sniff {
 
     /**
      * The number of spaces code should be indented.
@@ -57,7 +57,7 @@ class moodle_sniffs_whitespace_scopeindentsniff implements php_codesniffer_sniff
      *
      * @var array(int)
      */
-    protected $nonIndentingScopes = array();
+    protected $nonindentingscopes = array();
 
 
     /**
@@ -65,10 +65,8 @@ class moodle_sniffs_whitespace_scopeindentsniff implements php_codesniffer_sniff
      *
      * @return array
      */
-    public function register()
-    {
+    public function register() {
         return PHP_CodeSniffer_tokens::$scopeOpeners;
-
     }
 
 
@@ -81,8 +79,7 @@ class moodle_sniffs_whitespace_scopeindentsniff implements php_codesniffer_sniff
      *
      * @return void
      */
-    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
         $tokens = $phpcsfile->gettokens();
 
         // If this is an inline condition (ie. there is no scope opener), then
@@ -92,8 +89,9 @@ class moodle_sniffs_whitespace_scopeindentsniff implements php_codesniffer_sniff
         }
 
         if ($tokens[$stackptr]['code'] === T_ELSE) {
-            $next = $phpcsfile->findNext(PHP_CodeSniffer_tokens::$emptyTokens, ($stackptr + 1), null, true);
+            $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;
             }
@@ -101,6 +99,7 @@ class moodle_sniffs_whitespace_scopeindentsniff implements php_codesniffer_sniff
 
         // 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) {
@@ -115,43 +114,47 @@ class moodle_sniffs_whitespace_scopeindentsniff implements php_codesniffer_sniff
 
         // Based on the conditions that surround this token, determine the
         // indent that we expect this current content to be.
-        $expectedIndent = $this->calculateExpectedIndent($tokens, $firsttoken);
+        $expectedindent = $this->calculateexpectedindent($tokens, $firsttoken);
 
-        if ($tokens[$firsttoken]['column'] !== $expectedIndent) {
+        if ($tokens[$firsttoken]['column'] !== $expectedindent) {
             $error  = 'line indented incorrectly; expected ';
-            $error .= ($expectedIndent - 1).' spaces, found ';
+            $error .= ($expectedindent - 1).' spaces, found ';
             $error .= ($tokens[$firsttoken]['column'] - 1);
             $phpcsfile->adderror($error, $stackptr);
         }
 
-        $scopeOpener = $tokens[$stackptr]['scope_opener'];
-        $scopeCloser = $tokens[$stackptr]['scope_closer'];
+        $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);
+        if (in_array($tokens[$firsttoken]['code'], $this->nonindentingscopes) === false) {
+            $indent = ($expectedindent + $this->indent);
+
         } else {
-            $indent = $expectedIndent;
+            $indent = $expectedindent;
         }
 
         $newline     = false;
-        $commentOpen = false;
-        $inHereDoc   = 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++) {
+        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);
+                    $nexttoken = $phpcsfile->findnext(T_SEMICOLON, $i, $scopecloser);
+
                     if ($nexttoken !== false) {
                         $i = $nexttoken;
                     }
@@ -163,11 +166,13 @@ class moodle_sniffs_whitespace_scopeindentsniff implements php_codesniffer_sniff
             // 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;
+                $inheredoc = true;
                 continue;
-            } else if ($inHereDoc === true) {
+
+            } else if ($inheredoc === true) {
+
                 if ($tokens[$i]['code'] === T_END_HEREDOC) {
-                    $inHereDoc = false;
+                    $inheredoc = false;
                 }
 
                 continue;
@@ -189,19 +194,21 @@ class moodle_sniffs_whitespace_scopeindentsniff implements php_codesniffer_sniff
 
                 // Special case for non-PHP code.
                 if ($tokens[$firsttoken]['code'] === T_INLINE_HTML) {
-                    $trimmedcontentLength = strlen(ltrim($tokens[$firsttoken]['content']));
-                    if ($trimmedcontentLength === 0) {
+                    $trimmedcontentlength = strlen(ltrim($tokens[$firsttoken]['content']));
+
+                    if ($trimmedcontentlength === 0) {
                         continue;
                     }
 
-                    $contentLength = strlen($tokens[$firsttoken]['content']);
-                    $column        = ($contentLength - $trimmedcontentLength + 1);
+                    $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
@@ -213,8 +220,8 @@ class moodle_sniffs_whitespace_scopeindentsniff implements php_codesniffer_sniff
                 // This is a special condition for T_DOC_COMMENT and C-style
                 // comments, which contain whitespace between each line.
                 if (in_array($tokens[$firsttoken]['code'], array(T_COMMENT, T_DOC_COMMENT)) === 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
@@ -222,20 +229,23 @@ class moodle_sniffs_whitespace_scopeindentsniff implements php_codesniffer_sniff
                         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;
+                            $commentopen = true;
                         }
-                    } else if ($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);
+                        $contentlength        = strlen($tokens[$firsttoken]['content']);
+                        $trimmedcontentlength = strlen(ltrim($tokens[$firsttoken]['content']));
+                        $column               = ($contentlength - $trimmedcontentlength + 1);
+
                         if (preg_match('|\*/$|', $content) !== 0) {
-                            $commentOpen = false;
+                            $commentopen = false;
                         }
                     }
                 }
@@ -244,8 +254,10 @@ class moodle_sniffs_whitespace_scopeindentsniff implements php_codesniffer_sniff
                 // 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 ';
                         }
@@ -257,7 +269,6 @@ class moodle_sniffs_whitespace_scopeindentsniff implements php_codesniffer_sniff
                 }
             }
         }
-
     }
 
 
@@ -269,29 +280,24 @@ class moodle_sniffs_whitespace_scopeindentsniff implements php_codesniffer_sniff
      *
      * @return int
      */
-    protected function calculateExpectedIndent(array $tokens, $stackptr)
-    {
-        $conditionStack = array();
+    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) {
+        $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;
+            if (in_array($condition, $this->nonindentingscopes) === false) {
+                $conditionstack[$id] = $condition;
             }
         }
 
-        return ((count($conditionStack) * $this->indent) + 1);
-
+        return ((count($conditionstack) * $this->indent) + 1);
     }
-
-
 }
-
-?>