]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19247 Adjusted detection and cleaned up sniff files.
authornicolasconnault <nicolasconnault>
Thu, 21 May 2009 03:53:28 +0000 (03:53 +0000)
committernicolasconnault <nicolasconnault>
Thu, 21 May 2009 03:53:28 +0000 (03:53 +0000)
19 files changed:
lib/pear/PHP/CodeSniffer/MoodleCLI.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/MoodleCodingStandard.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/Classes/ClassDeclarationSniff.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/Files/LineEndingsSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/Files/LineLengthSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/Functions/FunctionCallArgumentSpacingSniff.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/WhiteSpace/ControlStructureBlankLineSniff.php
lib/pear/PHP/CodeSniffer/Standards/Moodle/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php

index a2064b859b4550c05416133b8cee563567670108..e30c982334410035908fc7d0d0ffeb386ac3ca97 100644 (file)
  * Simple modifications to the CLI class to only use the Moodle Standard
  *
  * @package   lib-pear-php-codesniffer
- * @copyright 2008 Nicolas Connault
+ * @copyright 2009 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
-include_once('PHP/MoodleCodeSniffer.php');
+require_once('PHP/MoodleCodeSniffer.php');
 require_once('PHP/CodeSniffer/CLI.php');
 
 /**
@@ -91,7 +91,7 @@ class moodle_codesniffer_cli extends php_codesniffer_cli {
      * @return array The updated CLI values.
      * @see getCommandLineValues()
      */
-    public function processUnknownArgument($arg, $pos, $values) {
+    public function processunknownargument($arg, $pos, $values) {
         global $args, $argv, $argc;
 
         // We don't know about any additional switches; just files.
@@ -102,6 +102,7 @@ class moodle_codesniffer_cli extends php_codesniffer_cli {
         }
 
         $file = $_SERVER['PWD'] . '/' . $arg;
+
         if (file_exists($file) === false) {
             echo 'ERROR: The file "'.$arg.'" does not exist.'.PHP_EOL.PHP_EOL;
             $this->printUsage();
index 5bf062b8da0cee41717ce9c456852e908b284af7..f471d367c8bb96707c7690701d8591e798431665 100644 (file)
  *
  * Simple modifications to the CLI class to only use the Moodle Standard
  *
- * @package   lib-pear-php-codesniffer
+ * @package   lib-pear-php-codesniffer-standards-moodle
  * @copyright 2008 Nicolas Connault
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-
 if (class_exists('PHP_CodeSniffer_Standards_CodingStandard', true) === false) {
     throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_CodingStandard not found');
 }
index a6b68fb09197c2f6f7c7195389c502a7274b725c..c0c8d1999bafb2b765500ccc2e874c9e49070b7f 100644 (file)
@@ -56,7 +56,7 @@ class moodle_sniffs_classes_classdeclarationsniff implements php_codesniffer_sni
         $tokens = $phpcsfile->gettokens();
 
         if (isset($tokens[$stackptr]['scope_opener']) === false) {
-            $error  = 'Possible parse error: ';
+            $error  = 'possible parse error: ';
             $error .= $tokens[$stackptr]['content'];
             $error .= ' missing opening or closing brace';
             $phpcsfile->addwarning($error, $stackptr);
index caf2bc03776144ec39d77f47f8abaecb81c3ac44..c282731b329428c26809f989c37f3304ed065235 100644 (file)
@@ -70,7 +70,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;
         }
 
@@ -130,8 +130,8 @@ class moodle_sniffs_codeanalysis_unusedfunctionparametersniff implements php_cod
         }
 
         if ($emptyBody === false && count($params) > 0) {
-            foreach ($params as $paramName => $position) {
-                $error = 'The method parameter '.$paramName.' is never used';
+            foreach ($params as $paramname => $position) {
+                $error = 'The method parameter '.$paramname.' is never used';
                 $phpcsfile->addwarning($error, $position);
             }
         }
index cc5ded9cfe977f6a5f9f412db2e41c7d32a3435d..bec8aa1a20f00f9230ebb4898951a467bbd4c143 100644 (file)
@@ -77,11 +77,11 @@ class moodle_sniffs_codeanalysis_uselessoverridingmethodsniff implements php_cod
         }
 
         // Get function name.
-        $methodName = $phpcsfile->getDeclarationName($stackptr);
+        $methodname = $phpcsfile->getDeclarationname($stackptr);
 
         // Get all parameters from method signature.
         $signature = array();
-        foreach ($phpcsfile->getMethodParameters($stackptr) as $param) {
+        foreach ($phpcsfile->getmethodParameters($stackptr) as $param) {
             $signature[] = $param['name'];
         }
 
@@ -117,7 +117,7 @@ class moodle_sniffs_codeanalysis_uselessoverridingmethodsniff implements php_cod
         $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) {
+        if ($next === false || $tokens[$next]['content'] !== $methodname) {
             return;
         }
 
@@ -136,22 +136,22 @@ class moodle_sniffs_codeanalysis_uselessoverridingmethodsniff implements php_cod
                                );
 
         $parameters       = array('');
-        $parenthesisCount = 1;
+        $parenthesiscount = 1;
         $count            = count($tokens);
         for (++$next; $next < $count; ++$next) {
             $code = $tokens[$next]['code'];
 
             if ($code === T_OPEN_PARENTHESIS) {
-                ++$parenthesisCount;
+                ++$parenthesiscount;
             } else if ($code === T_CLOSE_PARENTHESIS) {
-                --$parenthesisCount;
-            } else if ($parenthesisCount === 1 && $code === T_COMMA) {
+                --$parenthesiscount;
+            } else if ($parenthesiscount === 1 && $code === T_COMMA) {
                 $parameters[] = '';
             } else if (in_array($code, PHP_CodeSniffer_tokens::$emptyTokens) === false) {
                 $parameters[(count($parameters) - 1)] .= $tokens[$next]['content'];
             }
 
-            if ($parenthesisCount === 0) {
+            if ($parenthesiscount === 0) {
                 break;
             }
         }
index e072358d4da00336215f28c9885370647fe98a8c..4025c75db191bcb947d92a0bde322c7cd96ac40e 100644 (file)
@@ -87,31 +87,37 @@ 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) {
+        if ($commentend !== false && $tokens[$commentend]['code'] === T_COMMENT) {
             $phpcsfile->adderror("You must use \"/**\" style comments for a $type comment", $stackptr);
             return;
-        } else if ($commentEnd === false || $tokens[$commentEnd]['code'] !== T_DOC_COMMENT) {
+
+        } else if ($commentend === false || $tokens[$commentend]['code'] !== T_DOC_COMMENT) {
             $phpcsfile->adderror("Missing $type doc comment", $stackptr);
             return;
         }
 
-        $commentStart = ($phpcsfile->findPrevious(T_DOC_COMMENT, ($commentEnd - 1), null, true) + 1);
-        $commentNext  = $phpcsfile->findPrevious(T_WHITESPACE, ($commentEnd + 1), $stackptr, false, $phpcsfile->eolChar);
+        $commentstart = ($phpcsfile->findPrevious(T_DOC_COMMENT, ($commentend - 1), null, true) + 1);
+        $commentnext  = $phpcsfile->findPrevious(T_WHITESPACE, ($commentend + 1), $stackptr, false, $phpcsfile->eolChar);
 
         // Distinguish file and class comment.
-        $prevClasstoken = $phpcsfile->findPrevious(T_CLASS, ($stackptr - 1));
-        if ($prevClasstoken === false) {
+        $prevclasstoken = $phpcsfile->findPrevious(T_CLASS, ($stackptr - 1));
+
+        if ($prevclasstoken === false) {
             // This is the first class token in this file, need extra checks.
-            $prevNonComment = $phpcsfile->findPrevious(T_DOC_COMMENT, ($commentStart - 1), null, true);
-            if ($prevNonComment !== false) {
-                $prevComment = $phpcsfile->findPrevious(T_DOC_COMMENT, ($prevNonComment - 1));
-                if ($prevComment === false) {
+            $prevnoncomment = $phpcsfile->findPrevious(T_DOC_COMMENT, ($commentstart - 1), null, true);
+
+            if ($prevnoncomment !== false) {
+                $prevcomment = $phpcsfile->findPrevious(T_DOC_COMMENT, ($prevnoncomment - 1));
+
+                if ($prevcomment === false) {
                     // There is only 1 doc comment between open tag and class token.
-                    $newlinetoken = $phpcsfile->findNext(T_WHITESPACE, ($commentEnd + 1), $stackptr, false, $phpcsfile->eolChar);
+                    $newlinetoken = $phpcsfile->findNext(T_WHITESPACE, ($commentend + 1), $stackptr, false, $phpcsfile->eolChar);
+
                     if ($newlinetoken !== false) {
                         $newlinetoken = $phpcsfile->findNext(T_WHITESPACE, ($newlinetoken + 1), $stackptr, false, $phpcsfile->eolChar);
+
                         if ($newlinetoken !== false) {
                             // Blank line between the class and the doc block.
                             // The doc block is most likely a file comment.
@@ -123,67 +129,74 @@ class moodle_sniffs_commenting_classcommentsniff extends moodle_sniffs_commentin
             }
         }
 
-        $comment = $phpcsfile->gettokensAsString($commentStart, ($commentEnd - $commentStart + 1));
+        $comment = $phpcsfile->gettokensAsString($commentstart, ($commentend - $commentstart + 1));
 
         // Parse the class comment.docblock.
         try {
             $this->commentparser = new PHP_CodeSniffer_CommentParser_ClassCommentParser($comment, $phpcsfile);
             $this->commentparser->parse();
         } catch (PHP_CodeSniffer_CommentParser_ParserException $e) {
-            $line = ($e->getlinewithinComment() + $commentStart);
+            $line = ($e->getlinewithinComment() + $commentstart);
             $phpcsfile->adderror($e->getMessage(), $line);
             return;
         }
 
         $comment = $this->commentparser->getComment();
+
         if (is_null($comment) === true) {
             $error = ucfirst($type).' doc comment is empty';
-            $phpcsfile->adderror($error, $commentStart);
+            $phpcsfile->adderror($error, $commentstart);
             return;
         }
 
         // No extra newline before short description.
         $short        = $comment->getShortComment();
-        $newlineCount = 0;
-        $newlineSpan  = strspn($short, $phpcsfile->eolChar);
-        if ($short !== '' && $newlineSpan > 0) {
-            $line  = ($newlineSpan > 1) ? 'newlines' : 'newline';
+        $newlinecount = 0;
+        $newlinespan  = strspn($short, $phpcsfile->eolChar);
+
+        if ($short !== '' && $newlinespan > 0) {
+            $line  = ($newlinespan > 1) ? 'newlines' : 'newline';
             $error = "Extra $line found before $type comment short description";
-            $phpcsfile->adderror($error, ($commentStart + 1));
+            $phpcsfile->adderror($error, ($commentstart + 1));
         }
 
-        $newlineCount = (substr_count($short, $phpcsfile->eolChar) + 1);
+        $newlinecount = (substr_count($short, $phpcsfile->eolChar) + 1);
 
         // Exactly one blank line between short and long description.
         $long = $comment->getlongcomment();
+
         if (empty($long) === false) {
             $between        = $comment->getWhiteSpaceBetween();
-            $newlineBetween = substr_count($between, $phpcsfile->eolChar);
-            if ($newlineBetween !== 2) {
+            $newlinebetween = substr_count($between, $phpcsfile->eolChar);
+
+            if ($newlinebetween !== 2) {
                 $error = "There must be exactly one blank line between descriptions in $type comments";
-                $phpcsfile->adderror($error, ($commentStart + $newlineCount + 1));
+                $phpcsfile->adderror($error, ($commentstart + $newlinecount + 1));
             }
 
-            $newlineCount += $newlineBetween;
+            $newlinecount += $newlinebetween;
         }
 
         // Exactly one blank line before tags.
-        $tags = $this->commentparser->getTagOrders();
+        $tags = $this->commentparser->gettagOrders();
+
         if (count($tags) > 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 $type comments";
+
                 if ($long !== '') {
-                    $newlineCount += (substr_count($long, $phpcsfile->eolChar) - $newlineSpan + 1);
+                    $newlinecount += (substr_count($long, $phpcsfile->eolChar) - $newlinespan + 1);
                 }
 
-                $phpcsfile->addwarning($error, ($commentStart + $newlineCount));
+                $phpcsfile->addwarning($error, ($commentstart + $newlinecount));
                 $short = rtrim($short, $phpcsfile->eolChar.' ');
             }
         }
 
         // Check each tag.
-        $this->processTags($commentStart, $commentEnd);
+        $this->processtags($commentstart, $commentend);
 
     }
 
@@ -191,26 +204,26 @@ class moodle_sniffs_commenting_classcommentsniff extends moodle_sniffs_commentin
     /**
      * Process the version tag.
      *
-     * @param int $errorPos The line number where the error occurs.
+     * @param int $errorpos The line number where the error occurs.
      *
      * @return void
      */
-    protected function processversion($errorPos)
-    {
+    protected function processversion($errorpos) {
         $version = $this->commentparser->getVersion();
+
         if ($version !== null) {
             $content = $version->getcontent();
             $matches = array();
+
             if (empty($content) === true) {
                 $error = 'content missing for @version tag in doc comment';
-                $this->currentfile->adderror($error, $errorPos);
+                $this->currentfile->adderror($error, $errorpos);
+
             } else if ((strstr($content, 'Release:') === false)) {
                 $error = "Invalid version \"$content\" in doc comment; consider \"Release: <package_version>\" instead";
-                $this->currentfile->addwarning($error, $errorPos);
+                $this->currentfile->addwarning($error, $errorpos);
             }
         }
 
     }
 }
-
-?>
index a279d80b26558b47981d6a8b5c3a3852533f457e..9e3cbb9134e966500ec976fc13976a03396e928c 100644 (file)
@@ -130,10 +130,8 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
      *
      * @return array
      */
-    public function register()
-    {
+    public function register() {
         return array(T_OPEN_TAG);
-
     }
 
 
@@ -151,6 +149,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) {
                 return;
             }
@@ -159,14 +158,15 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
         $tokens = $phpcsfile->gettokens();
 
         // Find the next non whitespace token.
-        $commentStart = $phpcsfile->findnext(T_WHITESPACE, ($stackptr + 1), null, true);
+        $commentstart = $phpcsfile->findnext(T_WHITESPACE, ($stackptr + 1), null, true);
 
         // Look for $Id$ and boilerplate
-        if ($tokens[$commentStart]['code'] != T_COMMENT) {
+        if ($tokens[$commentstart]['code'] != T_COMMENT) {
             $phpcsfile->adderror('File must begin with License boilerplate', ($stackptr + 1));
             return;
-        } else if (preg_match('|\$Id\$|i', $tokens[$commentStart]['content'])) {
-            $phpcsfile->addwarning('$Id$ tag is no longer required, please remove.', ($stackptr + 1));
+
+        } else if (preg_match('|\$Id\$|i', $tokens[$commentstart]['content'])) {
+            $phpcsfile->addwarning("\$Id\$ tag is no longer required, please remove.", ($stackptr + 1));
             return;
         }
 
@@ -212,16 +212,19 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
         if ($tokens[$filedoctoken]['code'] === T_CLOSE_TAG) {
             // We are only interested if this is the first open tag.
             return;
+
         } else if ($tokens[$filedoctoken]['code'] === T_COMMENT) {
             $phpcsfile->adderror('You must use "/**" style comments for a file comment', ($filedoctoken + 1));
             return;
+
         } else if ($filedoctoken === false || $tokens[$filedoctoken]['code'] !== T_DOC_COMMENT) {
             $phpcsfile->adderror('Missing file doc comment', ($filedoctoken + 1));
             return;
+
         } else {
 
             // Extract the header comment docblock.
-            $commentEnd = ($phpcsfile->findnext(T_DOC_COMMENT, ($filedoctoken + 1), null, true) - 1);
+            $commentend = ($phpcsfile->findnext(T_DOC_COMMENT, ($filedoctoken + 1), null, true) - 1);
 
             // Check if there is only 1 doc comment between the open tag and class token.
             $nexttoken   = array(
@@ -230,12 +233,17 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
                             T_FUNCTION,
                             T_DOC_COMMENT,
                            );
-            $commentNext = $phpcsfile->findnext($nexttoken, ($commentEnd + 1));
-            if ($commentNext !== false && $tokens[$commentNext]['code'] !== T_DOC_COMMENT) {
+            $commentnext = $phpcsfile->findnext($nexttoken, ($commentend + 1));
+
+            if ($commentnext !== false && $tokens[$commentnext]['code'] !== T_DOC_COMMENT) {
                 // Found a class token right after comment doc block.
-                $newlinetoken = $phpcsfile->findnext(T_WHITESPACE, ($commentEnd + 1), $commentNext, false, $phpcsfile->eolChar);
+                $newlinetoken = $phpcsfile->findnext(T_WHITESPACE, ($commentend + 1),
+                                                     $commentnext, false, $phpcsfile->eolChar);
+
                 if ($newlinetoken !== false) {
-                    $newlinetoken = $phpcsfile->findnext(T_WHITESPACE, ($newlinetoken + 1), $commentNext, false, $phpcsfile->eolChar);
+                    $newlinetoken = $phpcsfile->findnext(T_WHITESPACE, ($newlinetoken + 1),
+                                                         $commentnext, false, $phpcsfile->eolChar);
+
                     if ($newlinetoken === false) {
                         // No blank line between the class token and the doc block.
                         // The doc block is most likely a class comment.
@@ -245,12 +253,13 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
                 }
             }
 
-            $comment = $phpcsfile->gettokensAsString($filedoctoken, ($commentEnd - $filedoctoken + 1));
+            $comment = $phpcsfile->gettokensAsString($filedoctoken, ($commentend - $filedoctoken + 1));
 
             // Parse the header comment docblock.
             try {
                 $this->commentparser = new PHP_CodeSniffer_CommentParser_ClassCommentParser($comment, $phpcsfile);
                 $this->commentparser->parse();
+
             } catch (PHP_CodeSniffer_CommentParser_ParserException $e) {
                 $line = ($e->getlinewithinComment() + $filedoctoken);
                 $phpcsfile->adderror($e->getMessage(), $line);
@@ -258,6 +267,7 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
             }
 
             $comment = $this->commentparser->getComment();
+
             if (is_null($comment) === true) {
                 $error = 'File doc comment is empty';
                 $phpcsfile->adderror($error, $filedoctoken);
@@ -266,40 +276,46 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
 
             // 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';
+            $newlinecount = 0;
+            $newlinespan  = strspn($short, $phpcsfile->eolChar);
+
+            if ($short !== '' && $newlinespan > 0) {
+                $line  = ($newlinespan > 1) ? 'newlines' : 'newline';
                 $error = "Extra $line found before file comment short description";
                 $phpcsfile->adderror($error, ($filedoctoken + 1));
             }
 
-            $newlineCount = (substr_count($short, $phpcsfile->eolChar) + 1);
+            $newlinecount = (substr_count($short, $phpcsfile->eolChar) + 1);
 
             // Exactly one blank line between short and long description.
             $long = $comment->getlongcomment();
+
             if (empty($long) === false) {
-                $between        = $comment->getWhiteSpaceBetween();
-                $newlineBetween = substr_count($between, $phpcsfile->eolChar);
-                if ($newlineBetween !== 2) {
+                $between        = $comment->getWhiteSpacebetween();
+                $newlinebetween = substr_count($between, $phpcsfile->eolChar);
+
+                if ($newlinebetween !== 2) {
                     $error = 'There should be exactly one blank line between descriptions in file comment';
-                    $phpcsfile->addwarning($error, ($filedoctoken + $newlineCount + 1));
+                    $phpcsfile->addwarning($error, ($filedoctoken + $newlinecount + 1));
                 }
 
-                $newlineCount += $newlineBetween;
+                $newlinecount += $newlinebetween;
             }
 
             // Exactly one blank line before tags.
-            $tags = $this->commentparser->getTagOrders();
+            $tags = $this->commentparser->gettagOrders();
+
             if (count($tags) > 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 file comment';
+
                     if ($long !== '') {
-                        $newlineCount += (substr_count($long, $phpcsfile->eolChar) - $newlineSpan + 1);
+                        $newlinecount += (substr_count($long, $phpcsfile->eolChar) - $newlinespan + 1);
                     }
 
-                    $phpcsfile->addwarning($error, ($filedoctoken + $newlineCount));
+                    $phpcsfile->addwarning($error, ($filedoctoken + $newlinecount));
                     $short = rtrim($short, $phpcsfile->eolChar.' ');
                 }
             }
@@ -308,12 +324,12 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
             /*
             if (strstr(strtolower($long), 'php version') === false) {
                 $error = 'PHP version not specified';
-                $phpcsfile->addwarning($error, $commentEnd);
+                $phpcsfile->addwarning($error, $commentend);
             }
             */
 
             // Check each tag.
-            $this->processTags($filedoctoken, $commentEnd);
+            $this->processtags($filedoctoken, $commentend);
         }
 
     }
@@ -322,62 +338,68 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
     /**
      * Processes each required or optional tag.
      *
-     * @param int $commentStart The position in the stack where the comment started.
-     * @param int $commentEnd   The position in the stack where the comment ended.
+     * @param int $commentstart The position in the stack where the comment started.
+     * @param int $commentend   The position in the stack where the comment ended.
      *
      * @return void
      */
-    protected function processtags($commentStart, $commentEnd) {
-        $docBlock    = (get_class($this) === 'moodle_sniffs_commenting_filecommentsniff') ? 'file' : 'class';
-        $foundTags   = $this->commentparser->getTagOrders();
-        $orderIndex  = 0;
+    protected function processtags($commentstart, $commentend) {
+        $docblock    = (get_class($this) === 'moodle_sniffs_commenting_filecommentsniff') ? 'file' : 'class';
+        $foundtags   = $this->commentparser->gettagOrders();
+        $orderindex  = 0;
         $indentation = array();
-        $longestTag  = 0;
-        $errorPos    = 0;
+        $longesttag  = 0;
+        $errorpos    = 0;
 
         foreach ($this->tags as $tag => $info) {
 
             // Required tag missing.
-            if ($info['required'] === true && in_array($tag, $foundTags) === false) {
-                $error = "Missing @$tag tag in $docBlock comment";
-                $this->currentfile->adderror($error, $commentEnd);
+            if ($info['required'] === true && in_array($tag, $foundtags) === false) {
+                $error = "Missing @$tag tag in $docblock comment";
+                $this->currentfile->adderror($error, $commentend);
                 continue;
             }
 
              // Get the line number for current tag.
-            $tagName = ucfirst($tag);
+            $tagname = ucfirst($tag);
+
             if ($info['allow_multiple'] === true) {
-                $tagName .= 's';
+                $tagname .= 's';
             }
 
-            $getMethod  = 'get'.$tagName;
-            $tagElement = $this->commentparser->$getMethod();
-            if (is_null($tagElement) === true || empty($tagElement) === true) {
+            $getmethod  = 'get'.$tagname;
+            $tagelement = $this->commentparser->$getmethod();
+
+            if (is_null($tagelement) === true || empty($tagelement) === true) {
                 continue;
             }
 
-            $errorPos = $commentStart;
-            if (is_array($tagElement) === false) {
-                $errorPos = ($commentStart + $tagElement->getline());
+            $errorpos = $commentstart;
+
+            if (is_array($tagelement) === false) {
+                $errorpos = ($commentstart + $tagelement->getline());
             }
 
             // Get the tag order.
-            $foundIndexes = array_keys($foundTags, $tag);
+            $foundindexes = array_keys($foundtags, $tag);
 
-            if (count($foundIndexes) > 1) {
+            if (count($foundindexes) > 1) {
                 // Multiple occurance not allowed.
                 if ($info['allow_multiple'] === false) {
-                    $error = "Only 1 @$tag tag is allowed in a $docBlock comment";
-                    $this->currentfile->adderror($error, $errorPos);
+                    $error = "Only 1 @$tag tag is allowed in a $docblock comment";
+                    $this->currentfile->adderror($error, $errorpos);
+
                 } else {
                     // Make sure same tags are grouped together.
                     $i     = 0;
-                    $count = $foundIndexes[0];
-                    foreach ($foundIndexes as $index) {
+                    $count = $foundindexes[0];
+
+                    foreach ($foundindexes as $index) {
+
                         if ($index !== $count) {
-                            $errorPosIndex = ($errorPos + $tagElement[$i]->getline());
+                            $errorposindex = ($errorpos + $tagelement[$i]->getline());
                             $error         = "@$tag tags must be grouped together";
-                            $this->currentfile->adderror($error, $errorPosIndex);
+                            $this->currentfile->adderror($error, $errorposindex);
                         }
 
                         $i++;
@@ -387,69 +409,82 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
             }
 
             // Check tag order.
-            if ($foundIndexes[0] > $orderIndex) {
-                $orderIndex = $foundIndexes[0];
+            if ($foundindexes[0] > $orderindex) {
+                $orderindex = $foundindexes[0];
+
             } else {
-                if (is_array($tagElement) === true && empty($tagElement) === false) {
-                    $errorPos += $tagElement[0]->getline();
+
+                if (is_array($tagelement) === true && empty($tagelement) === false) {
+                    $errorpos += $tagelement[0]->getline();
                 }
 
-                $orderText = $info['order_text'];
-                $error     = "The @$tag tag is in the wrong order; the tag $orderText";
-                $this->currentfile->adderror($error, $errorPos);
+                $ordertext = $info['order_text'];
+                $error     = "The @$tag tag is in the wrong order; the tag $ordertext";
+                $this->currentfile->adderror($error, $errorpos);
             }
 
             // Store the indentation for checking.
             $len = strlen($tag);
-            if ($len > $longestTag) {
-                $longestTag = $len;
+
+            if ($len > $longesttag) {
+                $longesttag = $len;
             }
 
-            if (is_array($tagElement) === true) {
-                foreach ($tagElement as $key => $element) {
+            if (is_array($tagelement) === true) {
+
+                foreach ($tagelement as $key => $element) {
                     $indentation[] = array(
                                       'tag'   => $tag,
                                       'space' => $this->getIndentation($tag, $element),
                                       'line'  => $element->getline(),
                                      );
                 }
+
             } else {
                 $indentation[] = array(
                                   'tag'   => $tag,
-                                  'space' => $this->getIndentation($tag, $tagElement),
+                                  'space' => $this->getIndentation($tag, $tagelement),
                                  );
             }
 
-            $method = 'process'.$tagName;
+            $method = 'process'.$tagname;
+
             if (method_exists($this, $method) === true) {
                 // Process each tag if a method is defined.
-                call_user_func(array($this, $method), $errorPos);
+                call_user_func(array($this, $method), $errorpos);
+
             } else {
-                if (is_array($tagElement) === true) {
-                    foreach ($tagElement as $key => $element) {
-                        $element->process($this->currentfile, $commentStart, $docBlock);
+
+                if (is_array($tagelement) === true) {
+
+                    foreach ($tagelement as $key => $element) {
+                        $element->process($this->currentfile, $commentstart, $docblock);
                     }
+
                 } else {
-                     $tagElement->process($this->currentfile, $commentStart, $docBlock);
+                     $tagelement->process($this->currentfile, $commentstart, $docblock);
                 }
             }
         }
 
-        foreach ($indentation as $indentInfo) {
-            if ($indentInfo['space'] !== 0 && $indentInfo['space'] !== ($longestTag + 1)) {
-                $expected     = (($longestTag - strlen($indentInfo['tag'])) + 1);
-                $space        = ($indentInfo['space'] - strlen($indentInfo['tag']));
-                $error        = "@$indentInfo[tag] tag comment indented incorrectly. ";
+        foreach ($indentation as $indentinfo) {
+
+            if ($indentinfo['space'] !== 0 && $indentinfo['space'] !== ($longesttag + 1)) {
+                $expected     = (($longesttag - strlen($indentinfo['tag'])) + 1);
+                $space        = ($indentinfo['space'] - strlen($indentinfo['tag']));
+                $error        = "@$indentinfo[tag] tag comment indented incorrectly. ";
                 $error       .= "Expected $expected spaces but found $space.";
-                $getTagMethod = 'get'.ucfirst($indentInfo['tag']);
-                if ($this->tags[$indentInfo['tag']]['allow_multiple'] === true) {
-                    $line = $indentInfo['line'];
+                $gettagmethod = 'get'.ucfirst($indentinfo['tag']);
+
+                if ($this->tags[$indentinfo['tag']]['allow_multiple'] === true) {
+                    $line = $indentinfo['line'];
+
                 } else {
-                    $tagElem = $this->commentparser->$getTagMethod();
-                    $line    = $tagElem->getline();
+                    $tagelem = $this->commentparser->$gettagmethod();
+                    $line    = $tagelem->getline();
                 }
 
-                $this->currentfile->addwarning($error, ($commentStart + $line));
+                $this->currentfile->addwarning($error, ($commentstart + $line));
             }
         }
 
@@ -459,57 +494,63 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
     /**
      * Get the indentation information of each tag.
      *
-     * @param string                                   $tagName    The name of the doc comment element.
-     * @param PHP_CodeSniffer_CommentParser_DocElement $tagElement The doc comment element.
+     * @param string                                   $tagname    The name of the doc comment element.
+     * @param PHP_CodeSniffer_CommentParser_Docelement $tagelement The doc comment element.
      *
      * @return void
      */
-    protected function getindentation($tagName, $tagElement)
-    {
-        if ($tagElement instanceof PHP_CodeSniffer_CommentParser_SingleElement) {
-            if ($tagElement->getcontent() !== '') {
-                return (strlen($tagName) + substr_count($tagElement->getWhitespaceBeforecontent(), ' '));
+    protected function getindentation($tagname, $tagelement) {
+
+        if ($tagelement instanceof PHP_CodeSniffer_CommentParser_Singleelement) {
+
+            if ($tagelement->getcontent() !== '') {
+                return (strlen($tagname) + substr_count($tagelement->getWhitespaceBeforecontent(), ' '));
             }
-        } else if ($tagElement instanceof PHP_CodeSniffer_CommentParser_PairElement) {
-            if ($tagElement->getValue() !== '') {
-                return (strlen($tagName) + substr_count($tagElement->getWhitespaceBeforeValue(), ' '));
+
+        } else if ($tagelement instanceof PHP_CodeSniffer_CommentParser_Pairelement) {
+
+            if ($tagelement->getValue() !== '') {
+                return (strlen($tagname) + substr_count($tagelement->getWhitespaceBeforeValue(), ' '));
             }
         }
 
         return 0;
-
     }
 
 
     /**
      * Process the category tag.
      *
-     * @param int $errorPos The line number where the error occurs.
+     * @param int $errorpos The line number where the error occurs.
      *
      * @return void
      */
-    protected function processcategory($errorPos)
-    {
+    protected function processcategory($errorpos) {
         $category = $this->commentparser->getCategory();
+
         if ($category !== null) {
             $content = $category->getcontent();
+
             if ($content !== '') {
-                if (PHP_CodeSniffer::isUnderscoreName($content) !== true) {
+
+                if (PHP_CodeSniffer::isUnderscorename($content) !== true) {
                     $newcontent = str_replace(' ', '_', $content);
-                    $nameBits   = explode('_', $newcontent);
-                    $firstBit   = array_shift($nameBits);
-                    $newName    = ucfirst($firstBit).'_';
-                    foreach ($nameBits as $bit) {
-                        $newName .= ucfirst($bit).'_';
+                    $namebits   = explode('_', $newcontent);
+                    $firstbit   = array_shift($namebits);
+                    $newname    = ucfirst($firstbit).'_';
+
+                    foreach ($namebits as $bit) {
+                        $newname .= ucfirst($bit).'_';
                     }
 
-                    $validName = trim($newName, '_');
-                    $error     = "Category name \"$content\" is not valid; consider \"$validName\" instead";
-                    // $this->currentfile->adderror($error, $errorPos);
+                    $validname = trim($newname, '_');
+                    $error     = "Category name \"$content\" is not valid; consider \"$validname\" instead";
+                    // $this->currentfile->adderror($error, $errorpos);
                 }
+
             } else {
                 $error = '@category tag must contain a name';
-                $this->currentfile->adderror($error, $errorPos);
+                $this->currentfile->adderror($error, $errorpos);
             }
         }
 
@@ -519,11 +560,11 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
     /**
      * Process the package tag.
      *
-     * @param int $errorPos The line number where the error occurs.
+     * @param int $errorpos The line number where the error occurs.
      *
      * @return void
      */
-    protected function processpackage($errorPos) {
+    protected function processpackage($errorpos) {
         global $CFG;
         $package = $this->commentparser->getPackage();
         $filename = str_replace($CFG->dirroot, '', $this->currentfile->getfilename());
@@ -540,21 +581,24 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
 
         // Remove first dash if present
         $expected_package = ltrim($expected_package, '-');
+
         if ($package !== null) {
             $content = $package->getcontent();
 
             if ($content !== $expected_package) {
                 $error = "Package name \"$content\" is not valid; \"$expected_package\" expected.";
-                $this->currentfile->adderror($error, $errorPos);
+                $this->currentfile->adderror($error, $errorpos);
 
             } else if ($content !== '') {
+
                 if (!preg_match('/^[a-z\-]*$/', $content)) {
                     $error = "Package name \"$content\" is not valid; must be lower-case with optional hyphens.";
-                    $this->currentfile->adderror($error, $errorPos);
+                    $this->currentfile->adderror($error, $errorpos);
                 }
+
             } else {
                 $error = '@package tag must contain a name';
-                $this->currentfile->adderror($error, $errorPos);
+                $this->currentfile->adderror($error, $errorpos);
             }
         }
 
@@ -564,32 +608,36 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
     /**
      * Process the subpackage tag.
      *
-     * @param int $errorPos The line number where the error occurs.
+     * @param int $errorpos The line number where the error occurs.
      *
      * @return void
      */
-    protected function processsubpackage($errorPos)
-    {
+    protected function processsubpackage($errorpos) {
         $package = $this->commentparser->getSubpackage();
+
         if ($package !== null) {
             $content = $package->getcontent();
+
             if ($content !== '') {
-                if (PHP_CodeSniffer::isUnderscoreName($content) !== true) {
+
+                if (PHP_CodeSniffer::isUnderscorename($content) !== true) {
                     $newcontent = str_replace(' ', '_', $content);
-                    $nameBits   = explode('_', $newcontent);
-                    $firstBit   = array_shift($nameBits);
-                    $newName    = strtoupper($firstBit{0}).substr($firstBit, 1).'_';
-                    foreach ($nameBits as $bit) {
-                        $newName .= strtoupper($bit{0}).substr($bit, 1).'_';
+                    $namebits   = explode('_', $newcontent);
+                    $firstbit   = array_shift($namebits);
+                    $newname    = strtoupper($firstbit{0}).substr($firstbit, 1).'_';
+
+                    foreach ($namebits as $bit) {
+                        $newname .= strtoupper($bit{0}).substr($bit, 1).'_';
                     }
 
-                    $validName = trim($newName, '_');
-                    $error     = "Subpackage name \"$content\" is not valid; consider \"$validName\" instead";
-                    $this->currentfile->adderror($error, $errorPos);
+                    $validname = trim($newname, '_');
+                    $error     = "Subpackage name \"$content\" is not valid; consider \"$validname\" instead";
+                    $this->currentfile->adderror($error, $errorpos);
                 }
+
             } else {
                 $error = '@subpackage tag must contain a name';
-                $this->currentfile->adderror($error, $errorPos);
+                $this->currentfile->adderror($error, $errorpos);
             }
         }
 
@@ -600,34 +648,37 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
      * Process the author tag(s) that this header comment has.
      *
      * This function is different from other _process functions
-     * as $authors is an array of SingleElements, so we work out
-     * the errorPos for each element separately
+     * as $authors is an array of Singleelements, so we work out
+     * the errorpos for each element separately
      *
-     * @param int $commentStart The position in the stack where
+     * @param int $commentstart The position in the stack where
      *                          the comment started.
      *
      * @return void
      */
-    protected function processauthors($commentStart)
-    {
+    protected function processauthors($commentstart) {
          $authors = $this->commentparser->getAuthors();
         // Report missing return.
         if (empty($authors) === false) {
+
             foreach ($authors as $author) {
-                $errorPos = ($commentStart + $author->getline());
+                $errorpos = ($commentstart + $author->getline());
                 $content  = $author->getcontent();
+
                 if ($content !== '') {
                     $local = '\da-zA-Z-_+';
                     // Dot character cannot be the first or last character in the local-part.
-                    $localMiddle = $local.'.\w';
-                    if (preg_match('/^([^<]*)\s+<(['.$local.']['.$localMiddle.']*['.$local.']@[\da-zA-Z][-.\w]*[\da-zA-Z]\.[a-zA-Z]{2,7})>$/', $content) === 0) {
-                        $error = 'content of the @author tag must be in the form "Display Name <username@example.com>"';
-                        $this->currentfile->adderror($error, $errorPos);
+                    $localmiddle = $local.'.\w';
+
+                    if (preg_match('/^([^<]*)\s+<(['.$local.']['.$localmiddle.']*['.$local.']@[\da-zA-Z][-.\w]*[\da-zA-Z]\.[a-zA-Z]{2,7})>$/', $content) === 0) {
+                        $error = 'content of the @author tag must be in the form "Display name <username@example.com>"';
+                        $this->currentfile->adderror($error, $errorpos);
                     }
+
                 } else {
-                    $docBlock = (get_class($this) === 'moodle_sniffs_commenting_filecommentsniff') ? 'file' : 'class';
-                    $error    = "content missing for @author tag in $docBlock comment";
-                    $this->currentfile->adderror($error, $errorPos);
+                    $docblock = (get_class($this) === 'moodle_sniffs_commenting_filecommentsniff') ? 'file' : 'class';
+                    $error    = "content missing for @author tag in $docblock comment";
+                    $this->currentfile->adderror($error, $errorpos);
                 }
             }
         }
@@ -638,39 +689,45 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
     /**
      * Process the copyright tags.
      *
-     * @param int $commentStart The position in the stack where
+     * @param int $commentstart The position in the stack where
      *                          the comment started.
      *
      * @return void
      */
-    protected function processcopyrights($commentStart)
-    {
+    protected function processcopyrights($commentstart) {
         $copyrights = $this->commentparser->getCopyrights();
+
         foreach ($copyrights as $copyright) {
-            $errorPos = ($commentStart + $copyright->getline());
+            $errorpos = ($commentstart + $copyright->getline());
             $content  = $copyright->getcontent();
+
             if ($content !== '') {
                 $matches = array();
+
                 if (preg_match('/^([0-9]{4})((.{1})([0-9]{4}))? (.+)$/', $content, $matches) !== 0) {
                     // Check earliest-latest year order.
+
                     if ($matches[3] !== '') {
+
                         if ($matches[3] !== '-') {
                             $error = 'A hyphen must be used between the earliest and latest year';
-                            $this->currentfile->adderror($error, $errorPos);
+                            $this->currentfile->adderror($error, $errorpos);
                         }
 
                         if ($matches[4] !== '' && $matches[4] < $matches[1]) {
                             $error = "Invalid year span \"$matches[1]$matches[3]$matches[4]\" found; consider \"$matches[4]-$matches[1]\" instead";
-                            $this->currentfile->addwarning($error, $errorPos);
+                            $this->currentfile->addwarning($error, $errorpos);
                         }
                     }
+
                 } else {
                     $error = '@copyright tag must contain a year and the name of the copyright holder';
-                    $this->currentfile->adderror($error, $errorPos);
+                    $this->currentfile->adderror($error, $errorpos);
                 }
+
             } else {
                 $error = '@copyright tag must contain a year and the name of the copyright holder';
-                $this->currentfile->adderror($error, $errorPos);
+                $this->currentfile->adderror($error, $errorpos);
             }
         }
 
@@ -680,56 +737,56 @@ class moodle_sniffs_commenting_filecommentsniff implements php_codesniffer_sniff
     /**
      * Process the license tag.
      *
-     * @param int $errorPos The line number where the error occurs.
+     * @param int $errorpos The line number where the error occurs.
      *
      * @return void
      */
-    protected function processlicense($errorPos)
-    {
+    protected function processlicense($errorpos) {
         $license = $this->commentparser->getLicense();
+
         if ($license !== null) {
             $value   = $license->getValue();
             $comment = $license->getComment();
+
             if ($value === '' || $comment === '') {
                 $error = '@license tag must contain a URL and a license name';
-                $this->currentfile->adderror($error, $errorPos);
+                $this->currentfile->adderror($error, $errorpos);
             }
+
             if ($comment != 'GNU GPL v3 or later') {
-                $this->currentfile->adderror('License must be "GNU GPL v3 or later", found "'.$comment.'"', $errorPos);
+                $this->currentfile->adderror('License must be "GNU GPL v3 or later", found "'.$comment.'"', $errorpos);
             }
+
             if ($value != 'http://www.gnu.org/copyleft/gpl.html') {
-                $this->currentfile->adderror('License must be "GNU GPL v3 or later"', $errorPos);
+                $this->currentfile->adderror('License must be "GNU GPL v3 or later"', $errorpos);
             }
         }
-
     }
 
 
     /**
      * Process the version tag.
      *
-     * @param int $errorPos The line number where the error occurs.
+     * @param int $errorpos The line number where the error occurs.
      *
      * @return void
      */
-    protected function processversion($errorPos)
-    {
+    protected function processversion($errorpos) {
         $version = $this->commentparser->getVersion();
+
         if ($version !== null) {
             $content = $version->getcontent();
             $matches = array();
+
             if (empty($content) === true) {
                 $error = 'content missing for @version tag in file comment';
-                $this->currentfile->adderror($error, $errorPos);
+                $this->currentfile->adderror($error, $errorpos);
+
             } else if (strstr($content, 'CVS:') === false && strstr($content, 'SVN:') === false) {
                 $error = "Invalid version \"$content\" in file comment; consider \"CVS: <cvs_id>\" or \"SVN: <svn_id>\" instead";
-                $this->currentfile->addwarning($error, $errorPos);
+                $this->currentfile->addwarning($error, $errorpos);
             }
         }
 
     }
-
-
 }
-
-?>
index ff7febec59715c5614e77c0bba887bd2f9de3b3f..6360a9ce93033885468f7d427f05895c73b445bc 100644 (file)
@@ -55,7 +55,7 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
      *
      * @var string
      */
-    private $_methodName = '';
+    private $_methodname = '';
 
     /**
      * The position in the stack where the fucntion token was found.
@@ -117,9 +117,9 @@ 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) {
+        if ($commentend === false) {
             return;
         }
 
@@ -128,7 +128,7 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
 
         // If the token that we found was a class or a function, then this
         // function has no doc comment.
-        $code = $tokens[$commentEnd]['code'];
+        $code = $tokens[$commentend]['code'];
 
         if ($code === T_COMMENT) {
             $error = 'You must use "/**" style comments for a function comment';
@@ -147,7 +147,7 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
         $ignore[]  = T_ABSTRACT;
         $ignore[]  = T_FINAL;
         $prevtoken = $phpcsfile->findPrevious($ignore, ($stackptr - 1), null, true);
-        if ($prevtoken !== $commentEnd) {
+        if ($prevtoken !== $commentend) {
             $phpcsfile->adderror('Missing function doc comment', $stackptr);
             return;
         }
@@ -163,8 +163,8 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
 
         // 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) {
@@ -173,14 +173,14 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
             }
         }
 
-        $comment           = $phpcsfile->gettokensAsString($commentStart, ($commentEnd - $commentStart + 1));
-        $this->_methodName = $phpcsfile->getDeclarationName($stackptr);
+        $comment           = $phpcsfile->gettokensAsString($commentstart, ($commentend - $commentstart + 1));
+        $this->_methodname = $phpcsfile->getDeclarationname($stackptr);
 
         try {
             $this->commentParser = new PHP_CodeSniffer_CommentParser_FunctionCommentParser($comment, $phpcsfile);
             $this->commentParser->parse();
         } catch (PHP_CodeSniffer_CommentParser_ParserException $e) {
-            $line = ($e->getlinewithinComment() + $commentStart);
+            $line = ($e->getlinewithinComment() + $commentstart);
             $phpcsfile->adderror($e->getMessage(), $line);
             return;
         }
@@ -188,25 +188,25 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
         $comment = $this->commentParser->getComment();
         if (is_null($comment) === true) {
             $error = 'Function doc comment is empty';
-            $phpcsfile->adderror($error, $commentStart);
+            $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;
+        $newlinecount = 0;
         $newlineSpan  = strspn($short, $phpcsfile->eolChar);
         if ($short !== '' && $newlineSpan > 0) {
             $line  = ($newlineSpan > 1) ? 'newlines' : 'newline';
             $error = "Extra $line found before function comment short description";
-            $phpcsfile->adderror($error, ($commentStart + 1));
+            $phpcsfile->adderror($error, ($commentstart + 1));
         }
 
-        $newlineCount = (substr_count($short, $phpcsfile->eolChar) + 1);
+        $newlinecount = (substr_count($short, $phpcsfile->eolChar) + 1);
 
         // Exactly one blank line between short and long description.
         $long = $comment->getlongcomment();
@@ -215,23 +215,23 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
             $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));
+                $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) {
                 $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));
+                $phpcsfile->addwarning($error, ($commentstart + $newlinecount));
                 $short = rtrim($short, $phpcsfile->eolChar.' ');
             }
         }
@@ -242,12 +242,12 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
     /**
      * Process any throw tags that this function comment has.
      *
-     * @param int $commentStart The position in the stack where the
+     * @param int $commentstart The position in the stack where the
      *                          comment started.
      *
      * @return void
      */
-    protected function processThrows($commentStart)
+    protected function processThrows($commentstart)
     {
         if (count($this->commentParser->getThrows()) === 0) {
             return;
@@ -256,11 +256,11 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
         foreach ($this->commentParser->getThrows() as $throw) {
 
             $exception = $throw->getValue();
-            $errorPos  = ($commentStart + $throw->getline());
+            $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);
             }
         }
 
@@ -270,32 +270,32 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
     /**
      * Process the return comment of this function comment.
      *
-     * @param int $commentStart The position in the stack where the comment started.
-     * @param int $commentEnd   The position in the stack where the comment ended.
+     * @param int $commentstart The position in the stack where the comment started.
+     * @param int $commentend   The position in the stack where the comment ended.
      *
      * @return void
      */
-    protected function processReturn($commentStart, $commentEnd)
+    protected function processReturn($commentstart, $commentend)
     {
         // Skip constructor and destructor.
-        $className = '';
+        $classname = '';
         if ($this->_classtoken !== null) {
-            $className = $this->currentFile->getDeclarationName($this->_classtoken);
-            $className = strtolower(ltrim($className, '_'));
+            $classname = $this->currentFile->getDeclarationname($this->_classtoken);
+            $classname = strtolower(ltrim($classname, '_'));
         }
 
-        $methodName      = strtolower(ltrim($this->_methodName, '_'));
-        $isSpecialMethod = ($this->_methodName === '__construct' || $this->_methodName === '__destruct');
+        $methodname      = strtolower(ltrim($this->_methodname, '_'));
+        $isspecialmethod = ($this->_methodname === '__construct' || $this->_methodname === '__destruct');
 
-        if ($isSpecialMethod === false && $methodName !== $className) {
+        if ($isspecialmethod === false && $methodname !== $classname) {
             // Report missing return tag.
             if ($this->commentParser->getReturn() === null) {
                 $error = 'Missing @return tag in function comment';
-                $this->currentFile->adderror($error, $commentEnd);
+                $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);
             }
         }
 
@@ -305,14 +305,14 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
     /**
      * Process the function parameter comments.
      *
-     * @param int $commentStart The position in the stack where
+     * @param int $commentstart The position in the stack where
      *                          the comment started.
      *
      * @return void
      */
-    protected function processParams($commentStart)
+    protected function processParams($commentstart)
     {
-        $realParams = $this->currentFile->getMethodParameters($this->_functiontoken);
+        $realParams = $this->currentFile->getmethodParameters($this->_functiontoken);
 
         $params      = $this->commentParser->getParams();
         $foundParams = array();
@@ -322,15 +322,15 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
             $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.
             if ($params[0]->getOrder() !== 2) {
                 $error    = 'Parameters must appear immediately after the comment';
-                $errorPos = ($params[0]->getline() + $commentStart);
-                $this->currentFile->adderror($error, $errorPos);
+                $errorpos = ($params[0]->getline() + $commentstart);
+                $this->currentFile->adderror($error, $errorpos);
             }
 
             $previousParam      = null;
@@ -342,84 +342,84 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
             foreach ($params as $param) {
 
                 $paramComment = trim($param->getComment());
-                $errorPos     = ($param->getline() + $commentStart);
+                $errorpos     = ($param->getline() + $commentstart);
 
                 // Make sure that there is only one space before the var type.
                 if ($param->getWhitespaceBeforeType() !== ' ') {
                     $error = 'Expected 1 space before variable type';
-                    $this->currentFile->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();
+                $pos = $param->getposition();
 
-                $paramName = ($param->getVarName() !== '') ? $param->getVarName() : '[ UNKNOWN ]';
+                $paramname = ($param->getVarname() !== '') ? $param->getVarname() : '[ UNKNOWN ]';
 
                 if ($previousParam !== null) {
-                    $previousName = ($previousParam->getVarName() !== '') ? $previousParam->getVarName() : 'UNKNOWN';
+                    $previousname = ($previousParam->getVarname() !== '') ? $previousParam->getVarname() : 'UNKNOWN';
 
                     // Check to see if the parameters align properly.
                     if ($param->alignsVariableWith($previousParam) === false) {
-                        $error = 'The variable names for parameters '.$previousName.' ('.($pos - 1).') and '.$paramName.' ('.$pos.') do not align';
-                        $this->currentFile->addwarning($error, $errorPos);
+                        $error = 'The variable names for parameters '.$previousname.' ('.($pos - 1).') and '.$paramname.' ('.$pos.') do not align';
+                        $this->currentFile->addwarning($error, $errorpos);
                     }
 
                     if ($param->alignsCommentWith($previousParam) === false) {
-                        $error = 'The comments for parameters '.$previousName.' ('.($pos - 1).') and '.$paramName.' ('.$pos.') do not align';
-                        $this->currentFile->addwarning($error, $errorPos);
+                        $error = 'The comments for parameters '.$previousname.' ('.($pos - 1).') and '.$paramname.' ('.$pos.') do not align';
+                        $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;
+                    $realname      = $realParams[($pos - 1)]['name'];
+                    $foundParams[] = $realname;
                     // Append ampersand to name if passing by reference.
                     if ($realParams[($pos - 1)]['pass_by_reference'] === true) {
-                        $realName = '&'.$realName;
+                        $realname = '&'.$realname;
                     }
 
-                    if ($realName !== $param->getVarName()) {
-                        $error  = 'Doc comment var "'.$paramName;
-                        $error .= '" does not match actual variable name "'.$realName;
+                    if ($realname !== $param->getVarname()) {
+                        $error  = 'Doc comment var "'.$paramname;
+                        $error .= '" does not match actual variable name "'.$realname;
                         $error .= '" at position '.$pos;
 
-                        $this->currentFile->adderror($error, $errorPos);
+                        $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() === '') {
                     $error = 'Missing type at position '.$pos;
-                    $this->currentFile->adderror($error, $errorPos);
+                    $this->currentFile->adderror($error, $errorpos);
                 }
 
                 if ($paramComment === '') {
-                    $error = 'Missing comment for param "'.$paramName.'" at position '.$pos;
-                    $this->currentFile->adderror($error, $errorPos);
+                    $error = 'Missing comment for param "'.$paramname.'" at position '.$pos;
+                    $this->currentFile->adderror($error, $errorpos);
                 }
 
                 $previousParam = $param;
@@ -438,22 +438,22 @@ class moodle_sniffs_commenting_functioncommentsniff implements php_codesniffer_s
 
         }
 
-        $realNames = array();
+        $realnames = array();
         foreach ($realParams as $realParam) {
-            $realNames[] = $realParam['name'];
+            $realnames[] = $realParam['name'];
         }
 
         // Report and missing comments.
-        $diff = array_diff($realNames, $foundParams);
+        $diff = array_diff($realnames, $foundParams);
         foreach ($diff as $neededParam) {
             if (count($params) !== 0) {
-                $errorPos = ($params[(count($params) - 1)]->getline() + $commentStart);
+                $errorpos = ($params[(count($params) - 1)]->getline() + $commentstart);
             } else {
-                $errorPos = $commentStart;
+                $errorpos = $commentstart;
             }
 
             $error = 'Doc comment for "'.$neededParam.'" missing';
-            $this->currentFile->adderror($error, $errorPos);
+            $this->currentFile->adderror($error, $errorpos);
         }
 
     }
index 56132466e6da18b34693e50fe439e1fe3c49339e..ec182c08a7f48c271bac3bfd8cd3673759b93948 100644 (file)
@@ -78,7 +78,7 @@ class moodle_sniffs_files_lineendingssniff implements php_codesniffer_sniff
             $found    = $phpcsfile->eolChar;
             $found    = str_replace("\n", '\n', $found);
             $found    = str_replace("\r", '\r', $found);
-            $error    = "End of line character is invalid; expected \"$expected\" but found \"$found\"";
+            $error    = "end of line character is invalid; expected \"$expected\" but found \"$found\"";
             $phpcsfile->adderror($error, $stackptr);
         }
 
index 303fe48f0e214108fda944fdabc6798fe24c2bbf..7e3e94c569cea80304e64333a5e48ac30797f93c 100644 (file)
@@ -78,27 +78,27 @@ class moodle_sniffs_files_linelengthsniff implements php_codesniffer_sniff
         $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;
         }
 
-        $tokenCount         = 0;
+        $tokencount         = 0;
         $currentlinecontent = '';
         $currentline        = 1;
 
-        for (; $tokenCount < $phpcsfile->numTokens; $tokenCount++) {
-            if ($tokens[$tokenCount]['line'] === $currentline) {
-                $currentlinecontent .= $tokens[$tokenCount]['content'];
+        for (; $tokencount < $phpcsfile->numTokens; $tokencount++) {
+            if ($tokens[$tokencount]['line'] === $currentline) {
+                $currentlinecontent .= $tokens[$tokencount]['content'];
             } else {
                 $currentlinecontent = trim($currentlinecontent, $phpcsfile->eolChar);
-                $this->checklineLength($phpcsfile, ($tokenCount - 1), $currentlinecontent);
-                $currentlinecontent = $tokens[$tokenCount]['content'];
+                $this->checklineLength($phpcsfile, ($tokencount - 1), $currentlinecontent);
+                $currentlinecontent = $tokens[$tokencount]['content'];
                 $currentline++;
             }
         }
 
-        $this->checklineLength($phpcsfile, ($tokenCount - 1), $currentlinecontent);
+        $this->checklineLength($phpcsfile, ($tokencount - 1), $currentlinecontent);
 
     }
 
index ae4ef7894a5a99b1d4f5dd277bfa76f93025e975..122139212d87ec40170cde04bd18224dfb3fbdcb 100644 (file)
@@ -64,7 +64,7 @@ class moodle_sniffs_functions_functioncallargumentspacingsniff implements php_co
         // function myFunction...
         // "myFunction" is T_STRING but we should skip because it is not a
         // function or method *call*.
-        $functionName    = $stackptr;
+        $functionname    = $stackptr;
         $functionKeyword = $phpcsfile->findPrevious(PHP_CodeSniffer_tokens::$emptyTokens, ($stackptr - 1), null, true);
         if ($tokens[$functionKeyword]['code'] === T_FUNCTION || $tokens[$functionKeyword]['code'] === T_CLASS) {
             return;
@@ -72,7 +72,7 @@ class moodle_sniffs_functions_functioncallargumentspacingsniff implements php_co
 
         // 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);
+        $openBracket = $phpcsfile->findNext(PHP_CodeSniffer_tokens::$emptyTokens, ($functionname + 1), null, true);
         if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
             return;
         }
index 02b83ecbd0a50e90239f62a33c054fe80ef8b68c..835258a788e54506cb622107d2e0d6a14083c7ad 100644 (file)
@@ -60,15 +60,15 @@ class moodle_sniffs_functions_validdefaultvaluesniff implements php_codesniffer_
     {
         $tokens = $phpcsfile->gettokens();
 
-        $argStart = $tokens[$stackptr]['parenthesis_opener'];
-        $argEnd   = $tokens[$stackptr]['parenthesis_closer'];
+        $argstart = $tokens[$stackptr]['parenthesis_opener'];
+        $argend   = $tokens[$stackptr]['parenthesis_closer'];
 
         // Flag for when we have found a default in our arg list.
         // If there is a value without a default after this, it is an error.
         $defaultFound = false;
 
-        $nextArg = $argStart;
-        while (($nextArg = $phpcsfile->findNext(T_VARIABLE, ($nextArg + 1), $argEnd)) !== false) {
+        $nextArg = $argstart;
+        while (($nextArg = $phpcsfile->findNext(T_VARIABLE, ($nextArg + 1), $argend)) !== false) {
             $argHasDefault = self::_argHasDefault($phpcsfile, $nextArg);
             if (($argHasDefault === false) && ($defaultFound === true)) {
                 $error  = 'Arguments with default values must be at the end';
index 4f88456ab5faf389d6ddd6dffd3e1f7a9a8bff87..3c4ddb92ea9192f2ee1a39dc5fe3b409788d4b64 100644 (file)
@@ -58,7 +58,7 @@ class moodle_sniffs_namingconventions_uppercaseconstantnamesniff implements php_
     public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
     {
         $tokens    = $phpcsfile->gettokens();
-        $constName = $tokens[$stackptr]['content'];
+        $constname = $tokens[$stackptr]['content'];
 
         // If this token is in a heredoc, ignore it.
         if ($phpcsfile->hasCondition($stackptr, T_START_HEREDOC) === true) {
@@ -87,8 +87,8 @@ class moodle_sniffs_namingconventions_uppercaseconstantnamesniff implements php_
 
             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";
+                if (strtoupper($constname) !== $constname) {
+                    $error = 'Class constants must be uppercase; expected '.strtoupper($constname)." but found $constname";
                     $phpcsfile->adderror($error, $stackptr);
                 }
 
@@ -121,12 +121,12 @@ class moodle_sniffs_namingconventions_uppercaseconstantnamesniff implements php_
             }
 
             // This is a real constant.
-            if (strtoupper($constName) !== $constName) {
-                $error = 'Constants must be uppercase; expected '.strtoupper($constName)." but found $constName";
+            if (strtoupper($constname) !== $constname) {
+                $error = 'Constants must be uppercase; expected '.strtoupper($constname)." but found $constname";
                 $phpcsfile->adderror($error, $stackptr);
             }
 
-        } else if (strtolower($constName) === 'define' || strtolower($constName) === 'constant') {
+        } else if (strtolower($constname) === 'define' || strtolower($constname) === 'constant') {
 
             /*
                 This may be a "define" or "constant" function call.
@@ -138,9 +138,9 @@ class moodle_sniffs_namingconventions_uppercaseconstantnamesniff implements php_
                 return;
             }
 
-            $constName = $tokens[$constPtr]['content'];
-            if (strtoupper($constName) !== $constName) {
-                $error = 'Constants must be uppercase; expected '.strtoupper($constName)." but found $constName";
+            $constname = $tokens[$constPtr]['content'];
+            if (strtoupper($constname) !== $constname) {
+                $error = 'Constants must be uppercase; expected '.strtoupper($constname)." but found $constname";
                 $phpcsfile->adderror($error, $stackptr);
             }
         }
index 2be9459fc0e0ac3f52e2e6ecb9e8ae93dbad3cd4..9f337aff374a806cc4de770123c17b4bc15f30ad 100644 (file)
@@ -63,8 +63,8 @@ class moodle_sniffs_namingconventions_validclassnamesniff implements php_codesni
     {
         $tokens = $phpcsfile->gettokens();
 
-        $className = $phpcsfile->findNext(T_STRING, $stackptr);
-        $name      = trim($tokens[$className]['content']);
+        $classname = $phpcsfile->findNext(T_STRING, $stackptr);
+        $name      = trim($tokens[$classname]['content']);
 
         // Make sure that the word is all lowercase
 
index 3ca5e689ab09bb546748a1d923b061bb57385b61..d0bfb52943c63239170d97215a4c407d70dbdeaa 100644 (file)
@@ -43,7 +43,7 @@ class moodle_sniffs_namingconventions_validfunctionnamesniff extends php_codesni
      *
      * @var array
      */
-    private $_magicMethods = array(
+    private $_magicmethods = array(
                               'construct',
                               'destruct',
                               'call',
@@ -91,14 +91,14 @@ class moodle_sniffs_namingconventions_validfunctionnamesniff extends php_codesni
      */
     protected function processtokenwithinScope(PHP_CodeSniffer_File $phpcsfile, $stackptr, $currScope)
     {
-        $className  = $phpcsfile->getDeclarationName($currScope);
-        $methodName = $phpcsfile->getDeclarationName($stackptr);
+        $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";
+        if (preg_match('|^__|', $methodname) !== 0) {
+            $magicPart = substr($methodname, 2);
+            if (in_array($magicPart, $this->_magicmethods) === false) {
+                 $error = "method name \"$classname::$methodname\" is invalid; only PHP magic methods should be prefixed with a double underscore";
                  $phpcsfile->adderror($error, $stackptr);
             }
 
@@ -106,26 +106,26 @@ class moodle_sniffs_namingconventions_validfunctionnamesniff extends php_codesni
         }
 
         // PHP4 constructors are allowed to break our rules.
-        if ($methodName === $className) {
+        if ($methodname === $classname) {
             return;
         }
 
         // PHP4 destructors are allowed to break our rules.
-        if ($methodName === '_'.$className) {
+        if ($methodname === '_'.$classname) {
             return;
         }
 
-        $methodProps    = $phpcsfile->getMethodProperties($stackptr);
+        $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 (preg_match('/[A-Z]+/', $methodname)) {
             if ($scopeSpecified === true) {
-                $error = ucfirst($scope)." method name \"$className::$methodName\" must be in lower-case letters only";
+                $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";
+                $error = "method name \"$classname::$methodname\" must be in lower-case letters only";
             }
 
             $phpcsfile->adderror($error, $stackptr);
@@ -133,11 +133,11 @@ class moodle_sniffs_namingconventions_validfunctionnamesniff extends php_codesni
         }
 
         // No numbers accepted
-        if (preg_match('/[0-9]+/', $methodName)) {
+        if (preg_match('/[0-9]+/', $methodname)) {
             if ($scopeSpecified === true) {
-                $error = ucfirst($scope)." method name \"$className::$methodName\" must only contain letters";
+                $error = ucfirst($scope)." method name \"$classname::$methodname\" must only contain letters";
             } else {
-                $error = "Method name \"$className::$methodName\" must only contain letters";
+                $error = "Method name \"$classname::$methodname\" must only contain letters";
             }
 
             $phpcsfile->adderror($error, $stackptr);
@@ -158,13 +158,13 @@ class moodle_sniffs_namingconventions_validfunctionnamesniff extends php_codesni
      */
     protected function processtokenOutsideScope(PHP_CodeSniffer_File $phpcsfile, $stackptr)
     {
-        $functionName = $phpcsfile->getDeclarationName($stackptr);
+        $functionname = $phpcsfile->getDeclarationname($stackptr);
 
         // Is this a magic function. IE. is prefixed with "__".
-        if (preg_match('|^__|', $functionName) !== 0) {
-            $magicPart = substr($functionName, 2);
+        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";
+                 $error = "Function name \"$functionname\" is invalid; only PHP magic methods should be prefixed with a double underscore";
                  $phpcsfile->adderror($error, $stackptr);
             }
 
@@ -172,16 +172,16 @@ class moodle_sniffs_namingconventions_validfunctionnamesniff extends php_codesni
         }
 
         // Only lower-case accepted
-        if (preg_match('/[A-Z]+/', $functionName)) {
-            $error = "function name \"$functionName\" must be lower-case letters only";
+        if (preg_match('/[A-Z]+/', $functionname)) {
+            $error = "function name \"$functionname\" must be lower-case letters only";
 
             $phpcsfile->adderror($error, $stackptr);
             return;
         }
 
         // Only letters accepted
-        if (preg_match('/[0-9]+/', $functionName)) {
-            $error = "function name \"$functionName\" must only contain letters";
+        if (preg_match('/[0-9]+/', $functionname)) {
+            $error = "function name \"$functionname\" must only contain letters";
 
             $phpcsfile->adderror($error, $stackptr);
             return;
index ff8353ccdd8ae0fa48f79f387fbc46a3af14a46e..314e23684ed390e5950211b33cb3ca1907535085 100644 (file)
@@ -38,7 +38,9 @@ if (class_exists('PHP_CodeSniffer_Standards_AbstractVariableSniff', true) === fa
 class moodle_sniffs_namingconventions_validvariablenamesniff extends php_codesniffer_standards_abstractvariablesniff
 {
 
-    private $allowed_global_vars = array('CFG', 'SESSION', 'USER', 'COURSE', 'SITE', 'PAGE', 'DB', 'THEME');
+    private $allowed_global_vars = array('CFG', 'SESSION', 'USER', 'COURSE', 'SITE', 'PAGE', 'DB', 'THEME',
+                                         '_SERVER', '_GET', '_POST', '_FILES', '_REQUEST', '_SESSION',
+                                         '_ENV', '_COOKIE', '_HTTP_RAW_POST_DATA');
 
     /**
      * Processes class member variables.
@@ -52,9 +54,9 @@ class moodle_sniffs_namingconventions_validvariablenamesniff extends php_codesni
     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";
+        $membername     = ltrim($tokens[$stackptr]['content'], '$');
+        if (preg_match('/[A-Z]+/', $membername)) {
+            $error = "Member variable \"$membername\" must be all lower-case";
             $phpcsfile->adderror($error, $stackptr);
             return;
         }
@@ -81,10 +83,10 @@ class moodle_sniffs_namingconventions_validvariablenamesniff extends php_codesni
     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";
+        $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;
             }
@@ -101,15 +103,16 @@ class moodle_sniffs_namingconventions_validvariablenamesniff extends php_codesni
      *
      * @return void
      */
-    protected function processVariableInString(PHP_CodeSniffer_File $phpcsfile, $stackptr)
-    {
+    protected function processvariableinstring(PHP_CodeSniffer_File $phpcsfile, $stackptr) {
         $tokens = $phpcsfile->gettokens();
+
         if (preg_match('/\$([A-Za-z0-9_]+)(\-\>([A-Za-z0-9_]+))?/i', $tokens[$stackptr]['content'], $matches)) {
             $firstvar = $matches[1];
             $objectvar = (empty($matches[3])) ? null : $matches[3];
-            $memberName = $firstvar . $objectvar;
+            $membername = $firstvar . $objectvar;
 
             if (preg_match('/[A-Z]+/', $firstvar, $matches)) {
+
                 if (!in_array($firstvar, $this->allowed_global_vars)) {
                     $error = "Member variable \"$firstvar\" must be all lower-case";
                     $phpcsfile->adderror($error, $stackptr);
@@ -123,12 +126,6 @@ class moodle_sniffs_namingconventions_validvariablenamesniff extends php_codesni
                 return;
             }
         }
-
         return;
-
     }
-
-
 }
-
-?>
index 7933f67a621a2106ef5e805fef38458acbe4d7bb..8e02f317eb659eb3349d204f8f14b88d3f9e069e 100644 (file)
@@ -71,17 +71,17 @@ class moodle_sniffs_php_disallowshortopentagsniff implements php_codesniffer_sni
         }
 
         $tokens  = $phpcsfile->gettokens();
-        $openTag = $tokens[$stackptr];
+        $opentag = $tokens[$stackptr];
 
-        if ($openTag['content'] === '<?') {
-            $error = 'Short PHP opening tag used. Found "'.$openTag['content'].'" Expected "<?php".';
+        if ($opentag['content'] === '<?') {
+            $error = 'Short PHP opening tag used. Found "'.$opentag['content'].'" Expected "<?php".';
             $phpcsfile->adderror($error, $stackptr);
         }
 
-        if ($openTag['code'] === T_OPEN_TAG_WITH_ECHO) {
+        if ($opentag['code'] === T_OPEN_TAG_WITH_ECHO) {
             $nextVar = $tokens[$phpcsfile->findNext(PHP_CodeSniffer_tokens::$emptyTokens, ($stackptr + 1), null, true)];
             $error   = 'Short PHP opening tag used with echo. Found "';
-            $error  .= $openTag['content'].' '.$nextVar['content'].' ..." but expected "<?php echo '.$nextVar['content'].' ...".';
+            $error  .= $opentag['content'].' '.$nextVar['content'].' ..." but expected "<?php echo '.$nextVar['content'].' ...".';
             $phpcsfile->adderror($error, $stackptr);
         }
 
index 14644f3c4064770cfc4f614a3a0a9bd18d276a39..4171f8bcf8f57db6c2a32738f09eb2b81dedbf32 100644 (file)
@@ -39,7 +39,7 @@ class moodle_sniffs_whitespace_controlstructureblanklinesniff implements php_cod
      * @return array
      */
     public function register() {
-        return array(T_IF, T_FOR, T_FOREACH, T_WHILE, T_SWITCH);
+        return array(T_IF, T_FOR, T_FOREACH, T_WHILE, T_SWITCH, T_TRY, T_CATCH);
     }
 
 
@@ -56,12 +56,14 @@ class moodle_sniffs_whitespace_controlstructureblanklinesniff implements php_cod
         $tokens = $phpcsfile->gettokens();
         $previoustoken = $stackptr - 1;
 
-        while ($tokens[$previoustoken]['line'] == $tokens[$stackptr]['line']) {
-            $previoustoken = $phpcsfile->findprevious(T_WHITESPACE, ($previoustoken - 1), null, true);
-        }
+        // 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);
+        } 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);
         }
index 43070359b1c6779333339388c9d5db6c25ee7698..08f79f3a94c75a8a47b1f97deb679e36cbdea768 100644 (file)
@@ -69,38 +69,38 @@ class moodle_sniffs_whitespace_scopeclosingbracesniff implements php_codesniffer
         // as if this is a method with tokens before it (public, static etc)
         // or an if with an else before it, then we need to start the scope
         // checking from there, rather than the current token.
-        $lineStart = ($stackptr - 1);
-        for ($lineStart; $lineStart > 0; $lineStart--) {
-            if (strpos($tokens[$lineStart]['content'], $phpcsfile->eolChar) !== false) {
+        $linestart = ($stackptr - 1);
+        for ($linestart; $linestart > 0; $linestart--) {
+            if (strpos($tokens[$linestart]['content'], $phpcsfile->eolChar) !== false) {
                 break;
             }
         }
 
         // We found a new line, now go forward and find the first non-whitespace
         // token.
-        $lineStart = $phpcsfile->findNext(array(T_WHITESPACE), ($lineStart + 1), null, true);
+        $linestart = $phpcsfile->findNext(array(T_WHITESPACE), ($linestart + 1), null, true);
 
-        $startColumn = $tokens[$lineStart]['column'];
-        $scopeStart  = $tokens[$stackptr]['scope_opener'];
-        $scopeEnd    = $tokens[$stackptr]['scope_closer'];
+        $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);
-        if ($tokens[$lastcontent]['line'] === $tokens[$scopeEnd]['line']) {
+        $lastcontent = $phpcsfile->findPrevious(array(T_WHITESPACE), ($scopeend - 1), $scopestart, true);
+        if ($tokens[$lastcontent]['line'] === $tokens[$scopeend]['line']) {
             $error = 'Closing brace must be on a line by itself';
-            $phpcsfile->adderror($error, $scopeEnd);
+            $phpcsfile->adderror($error, $scopeend);
             return;
         }
 
         // Check now that the closing brace is lined up correctly.
-        $braceIndent   = $tokens[$scopeEnd]['column'];
-        $isBreakCloser = ($tokens[$scopeEnd]['code'] === T_BREAK);
+        $braceIndent   = $tokens[$scopeend]['column'];
+        $isBreakCloser = ($tokens[$scopeend]['code'] === T_BREAK);
         if (in_array($tokens[$stackptr]['code'], array(T_CASE, T_DEFAULT)) === true && $isBreakCloser === true) {
             // BREAK statements should be indented 4 spaces from the
             // CASE or DEFAULT statement.
             if ($braceIndent !== ($startColumn + 4)) {
                 $error = 'Break statement indented incorrectly; expected '.($startColumn + 3).' spaces, found '.($braceIndent - 1);
-                $phpcsfile->adderror($error, $scopeEnd);
+                $phpcsfile->adderror($error, $scopeend);
             }
         } else {
             if (in_array($tokens[$stackptr]['code'], array(T_CASE, T_DEFAULT))) {
@@ -109,7 +109,7 @@ class moodle_sniffs_whitespace_scopeclosingbracesniff implements php_codesniffer
 
             if ($braceIndent !== $startColumn) {
                 $error = 'Closing brace indented incorrectly; expected '.($startColumn - 1).' spaces, found '.($braceIndent - 1);
-                $phpcsfile->adderror($error, $scopeEnd);
+                $phpcsfile->adderror($error, $scopeend);
             }
         }