/**
  * Process any throw tags that this function comment has.
  *
  * @param int $commentStart The position in the stack where the
  *                          comment started.
  *
  * @return void
  */
 protected function processThrows($commentStart)
 {
     if (count($this->commentParser->getThrows()) === 0) {
         return;
     }
     foreach ($this->commentParser->getThrows() as $throw) {
         $exception = $throw->getValue();
         $errorPos = $commentStart + $throw->getLine();
         if ($exception === '') {
             $error = '@throws tag must contain the exception class name';
             $this->currentFile->addError($error, $errorPos, 'EmptyThrows');
         }
     }
 }
 /**
  * Process any throw tags that this function comment has.
  *
  * @param int $commentStart The position in the stack where the comment started.
  *
  * @return void
  */
 private function _processThrows($commentStart)
 {
     if (count($this->commentParser->getThrows()) === 0) {
         return;
     }
     foreach ($this->commentParser->getThrows() as $throw) {
         $comment = $throw->getComment();
         $errorPos = $commentStart + $throw->getLine();
         if ($comment === '') {
             $error = '@throws tag must contain a comment';
             $this->currentFile->addError($error, $errorPos);
         }
     }
 }
 /**
  * Process any throw tags that this function comment has.
  *
  * @param int $commentStart The position in the stack where the
  *                          comment started.
  *
  * @return void
  */
 protected function processThrows($commentStart)
 {
     if (count($this->commentParser->getThrows()) === 0) {
         return;
     }
     foreach ($this->commentParser->getThrows() as $throw) {
         $exception = $throw->getValue();
         $errorPos = $commentStart + $throw->getLine();
         if ($exception === '') {
             //$error = '@throws tag must contain the exception class name';
             //$this->currentFile->addError($error, $errorPos);
             $this->currentFile->addEvent('XP_FUNCTION_COMMENT_THROWS_MUST_CONTAIN_CLASSNAME', array(), $errorPos);
         }
     }
 }
 /**
  * Process any throw tags that this function comment has.
  *
  * @param int $commentStart The position in the stack where the
  *                          comment started.
  *
  * @return void
  */
 protected function processThrows($commentStart)
 {
     //@TODO implement Drupal/Doxygen specific sniffs
     return;
     if (count($this->commentParser->getThrows()) === 0) {
         return;
     }
     foreach ($this->commentParser->getThrows() as $throw) {
         $exception = $throw->getValue();
         $errorPos = $commentStart + $throw->getLine();
         if ($exception === '') {
             $error = '@throws tag must contain the exception class name';
             $this->currentFile->addError($error, $errorPos);
         }
     }
 }
 /**
  * Process any throw tags that this function comment has.
  *
  * @param int $commentStart The position in the stack where the comment started.
  *
  * @return void
  */
 protected function processThrows($commentStart)
 {
     if (count($this->commentParser->getThrows()) === 0) {
         return;
     }
     $tagOrder = $this->commentParser->getTagOrders();
     $index = array_keys($this->commentParser->getTagOrders(), 'throws');
     foreach ($this->commentParser->getThrows() as $i => $throw) {
         $exception = $throw->getValue();
         $content = trim($throw->getComment());
         $errorPos = $commentStart + $throw->getLine();
         if (empty($exception) === true) {
             $error = 'Exception type and comment missing for @throws tag in function comment';
             $this->currentFile->addError($error, $errorPos, 'InvalidThrows');
         } else {
             if (empty($content) === true) {
                 $error = 'Comment missing for @throws tag in function comment';
                 $this->currentFile->addError($error, $errorPos, 'EmptyThrows');
             } else {
                 // Starts with a capital letter and ends with a fullstop.
                 $firstChar = $content[0];
                 if (strtoupper($firstChar) !== $firstChar) {
                     $error = '@throws tag comment must start with a capital letter';
                     $this->currentFile->addError($error, $errorPos, 'ThrowsNotCapital');
                 }
                 $lastChar = $content[strlen($content) - 1];
                 if ($lastChar !== '.') {
                     $error = '@throws tag comment must end with a full stop';
                     $this->currentFile->addError($error, $errorPos, 'ThrowsNoFullStop');
                 }
             }
         }
         $since = array_keys($tagOrder, 'since');
         if (count($since) === 1 && $this->_tagIndex !== 0) {
             $this->_tagIndex++;
             if ($index[$i] !== $this->_tagIndex) {
                 $error = 'The @throws tag is in the wrong order; the tag follows @return';
                 $this->currentFile->addError($error, $errorPos, 'ThrowsOrder');
             }
         }
     }
     //end foreach
 }
 /**
  * Process the function parameter comments
  *
  * @param  integer $commentStart The position in the stack where the comment started
  * @param  integer $commentEnd   The position in the stack where the comment ended
  * @return void
  */
 protected function _processParams($commentStart, $commentEnd)
 {
     $realParams = $this->_currentFile->getMethodParameters($this->_functionToken);
     $params = $this->_commentParser->getParams();
     $foundParams = array();
     if (empty($params) === false) {
         $isSpecialMethod = ($this->_methodName === '__construct' or $this->_methodName === '__destruct');
         if (substr_count($params[count($params) - 1]->getWhitespaceAfter(), $this->_currentFile->eolChar) !== 1 and $isSpecialMethod === false) {
             $error = 'No empty line after last parameter comment allowed';
             $errorPos = $params[count($params) - 1]->getLine() + $commentStart;
             $this->_currentFile->addError($error, $errorPos + 1);
         }
         // Parameters must appear immediately after the comment
         if ($params[0]->getOrder() !== 2) {
             $error = 'Parameters must appear immediately after the comment';
             $errorPos = $params[0]->getLine() + $commentStart;
             $this->_currentFile->addError($error, $errorPos);
         }
         $previousParam = null;
         $spaceBeforeVar = 10000;
         $spaceBeforeComment = 10000;
         $longestType = 0;
         $longestVar = 0;
         if (count($this->_commentParser->getThrows()) !== 0) {
             $isSpecialMethod = false;
         }
         foreach ($params as $param) {
             $paramComment = trim($param->getComment());
             $errorPos = $param->getLine() + $commentStart;
             // Make sure that there is only one or two space before the var type
             if ($isSpecialMethod === false and $param->getWhitespaceBeforeType() !== '  ') {
                 $error = 'Expected 2 spaces before variable type';
                 $this->_currentFile->addError($error, $errorPos);
             }
             if ($isSpecialMethod === true and $param->getWhitespaceBeforeType() !== ' ') {
                 $error = 'Expected 1 space before variable type';
                 $this->_currentFile->addError($error, $errorPos);
             }
             $spaceCount = substr_count($param->getWhitespaceBeforeVarName(), ' ');
             if ($spaceCount < $spaceBeforeVar) {
                 $spaceBeforeVar = $spaceCount;
                 $longestType = $errorPos;
             }
             $spaceCount = substr_count($param->getWhitespaceBeforeComment(), ' ');
             if ($spaceCount < $spaceBeforeComment and $paramComment !== '') {
                 $spaceBeforeComment = $spaceCount;
                 $longestVar = $errorPos;
             }
             // Make sure they are in the correct order, and have the correct name
             $pos = $param->getPosition();
             $paramName = $param->getVarName() !== '' ? $param->getVarName() : '[ UNKNOWN ]';
             if ($previousParam !== null) {
                 $previousName = $previousParam->getVarName() !== '' ? $previousParam->getVarName() : 'UNKNOWN';
                 // Check to see if the parameters align properly
                 if ($param->alignsVariableWith($previousParam) === false) {
                     $error = 'The variable names for parameters ' . $previousName . ' (' . ($pos - 1) . ') and ' . $paramName . ' (' . $pos . ') do not align';
                     $this->_currentFile->addError($error, $errorPos);
                 }
                 if ($param->alignsCommentWith($previousParam) === false) {
                     $error = 'The comments for parameters ' . $previousName . ' (' . ($pos - 1) . ') and ' . $paramName . ' (' . $pos . ') do not align';
                     $this->_currentFile->addError($error, $errorPos);
                 }
             }
             // Variable must be one of the supported standard type
             $typeNames = explode('|', $param->getType());
             foreach ($typeNames as $typeName) {
                 $suggestedName = PHP_CodeSniffer::suggestType($typeName);
                 if ($typeName !== $suggestedName) {
                     $error = "Expected \"{$suggestedName}\"; found \"{$typeName}\" for {$paramName} at position {$pos}";
                     $this->_currentFile->addError($error, $errorPos);
                     continue;
                 }
                 if (count($typeNames) !== 1) {
                     continue;
                 }
                 // Check type hint for array and custom type
                 $suggestedTypeHint = '';
                 if (strpos($suggestedName, 'array') !== false) {
                     $suggestedTypeHint = 'array';
                 } else {
                     if (in_array($typeName, PHP_CodeSniffer::$allowedTypes) === false) {
                         $suggestedTypeHint = $suggestedName;
                     }
                 }
                 if ($suggestedTypeHint !== '' and isset($realParams[$pos - 1]) === true) {
                     $typeHint = $realParams[$pos - 1]['type_hint'];
                     if ($typeHint === '') {
                         $error = "Type hint \"{$suggestedTypeHint}\" missing for {$paramName} at position {$pos}";
                         $this->_currentFile->addError($error, $commentEnd + 2);
                     } else {
                         if ($typeHint !== $suggestedTypeHint) {
                             $error = "Expected type hint \"{$suggestedTypeHint}\"; found \"{$typeHint}\"" . " for {$paramName} at position {$pos}";
                             $this->_currentFile->addError($error, $commentEnd + 2);
                         }
                     }
                 } else {
                     if ($suggestedTypeHint === '' and isset($realParams[$pos - 1]) === true) {
                         $typeHint = $realParams[$pos - 1]['type_hint'];
                         if ($typeHint !== '') {
                             $error = "Unknown type hint \"{$typeHint}\" found for {$paramName} at position {$pos}";
                             $this->_currentFile->addError($error, $commentEnd + 2);
                         }
                     }
                 }
             }
             // Make sure the names of the parameter comment matches the
             // actual parameter
             if (isset($realParams[$pos - 1]) === true) {
                 $realName = $realParams[$pos - 1]['name'];
                 $foundParams[] = $realName;
                 // Append ampersand to name if passing by reference
                 if ($realParams[$pos - 1]['pass_by_reference'] === true) {
                     $realName = '&' . $realName;
                 }
                 if ($realName !== $param->getVarName()) {
                     $error = 'Doc comment var "' . $paramName;
                     $error .= '" does not match actual variable name "' . $realName;
                     $error .= '" at position ' . $pos;
                     $this->_currentFile->addError($error, $errorPos);
                 }
             } else {
                 // We must have an extra parameter comment
                 $error = 'Superfluous doc comment at position ' . $pos;
                 $this->_currentFile->addError($error, $errorPos);
             }
             if ($param->getVarName() === '') {
                 $error = 'Missing parameter name at position ' . $pos;
                 $this->_currentFile->addError($error, $errorPos);
             }
             if ($param->getType() === '') {
                 $error = 'Missing type at position ' . $pos;
                 $this->_currentFile->addError($error, $errorPos);
             }
             if ($paramComment === '') {
                 $error = 'Missing comment for param "' . $paramName . '" at position ' . $pos;
                 $this->_currentFile->addError($error, $errorPos);
             } else {
                 // Param comments must start with a capital letter
                 $firstChar = $paramComment[0];
                 if (preg_match('|[A-Z]|', $firstChar) === 0 and $firstChar !== '(') {
                     $error = 'Param comment must start with a capital letter';
                     $this->_currentFile->addError($error, $errorPos);
                 }
                 // Check if optional params include (Optional) within their description
                 $functionBegin = $this->_currentFile->findNext(array(T_FUNCTION), $commentStart);
                 $functionName = $this->_currentFile->findNext(array(T_STRING), $functionBegin);
                 $openBracket = $this->_tokens[$functionBegin]['parenthesis_opener'];
                 $closeBracket = $this->_tokens[$functionBegin]['parenthesis_closer'];
                 $nextParam = $this->_currentFile->findNext(T_VARIABLE, $openBracket + 1, $closeBracket);
                 while ($nextParam !== false) {
                     $nextToken = $this->_currentFile->findNext(T_WHITESPACE, $nextParam + 1, $closeBracket + 1, true);
                     if ($nextToken === false and $this->_tokens[$nextParam + 1]['code'] === T_CLOSE_PARENTHESIS) {
                         break;
                     }
                     $nextCode = $this->_tokens[$nextToken]['code'];
                     $arg = $this->_tokens[$nextParam]['content'];
                     if ($nextCode === T_EQUAL and $paramName === $arg) {
                         if (substr($paramComment, 0, 11) !== '(Optional) ') {
                             $error = "Optional param comment for '{$paramName}' must start with '(Optional)'";
                             $this->_currentFile->addError($error, $errorPos);
                         } else {
                             if (preg_match('|[A-Z]|', $paramComment[11]) === 0) {
                                 $error = 'Param comment must start with a capital letter';
                                 $this->_currentFile->addError($error, $errorPos);
                             }
                         }
                     }
                     $nextParam = $this->_currentFile->findNext(T_VARIABLE, $nextParam + 1, $closeBracket);
                 }
             }
             $previousParam = $param;
         }
         if ($spaceBeforeVar !== 1 and $spaceBeforeVar !== 10000 and $spaceBeforeComment !== 10000) {
             $error = 'Expected 1 space after the longest type';
             $this->_currentFile->addError($error, $longestType);
         }
         if ($spaceBeforeComment !== 1 and $spaceBeforeComment !== 10000) {
             $error = 'Expected 1 space after the longest variable name';
             $this->_currentFile->addError($error, $longestVar);
         }
     }
     $realNames = array();
     foreach ($realParams as $realParam) {
         $realNames[] = $realParam['name'];
     }
     // Report missing comments
     $diff = array_diff($realNames, $foundParams);
     foreach ($diff as $neededParam) {
         if (count($params) !== 0) {
             $errorPos = $params[count($params) - 1]->getLine() + $commentStart;
         } else {
             $errorPos = $commentStart;
         }
         $error = 'Doc comment for "' . $neededParam . '" missing';
         $this->_currentFile->addError($error, $errorPos);
     }
 }
 /**
  * Process the function parameter comments
  *
  * @param  integer $commentStart The position in the stack where the comment started
  * @param  integer $commentEnd   The position in the stack where the comment ended
  * @return void
  */
 protected function _processParams($commentStart, $commentEnd)
 {
     $realParams = $this->_currentFile->getMethodParameters($this->_functionToken);
     $params = $this->_commentParser->getParams();
     $foundParams = array();
     if (empty($params) === false) {
         $isSpecialMethod = ($this->_methodName === '__construct' or $this->_methodName === '__destruct');
         if (substr_count($params[count($params) - 1]->getWhitespaceAfter(), $this->_currentFile->eolChar) !== 1 and $isSpecialMethod === false) {
             $errorPos = $params[count($params) - 1]->getLine() + $commentStart;
             $this->_currentFile->addEvent('EMPTY_LINE_LAST_PARAMETER_FUNCTION_COMMENT', array(), $errorPos + 1);
         }
         // Parameters must appear immediately after the comment
         if ($params[0]->getOrder() !== 2) {
             $errorPos = $params[0]->getLine() + $commentStart;
             $this->_currentFile->addEvent('PARAMETER_AFTER_COMMENT_FUNCTION_COMMENT', array(), $errorPos);
         }
         $previousParam = null;
         $spaceBeforeVar = 10000;
         $spaceBeforeComment = 10000;
         $longestType = 0;
         $longestVar = 0;
         if (count($this->_commentParser->getThrows()) !== 0) {
             $isSpecialMethod = false;
         }
         foreach ($params as $param) {
             $paramComment = trim($param->getComment());
             $errorPos = $param->getLine() + $commentStart;
             if ($isSpecialMethod === true and $param->getWhitespaceBeforeType() !== ' ') {
                 $this->_currentFile->addEvent('ONE_SPACE_VARIABLE_FUNCTION_COMMENT', array(), $errorPos);
             }
             $spaceCount = substr_count($param->getWhitespaceBeforeVarName(), ' ');
             if ($spaceCount < $spaceBeforeVar) {
                 $spaceBeforeVar = $spaceCount;
                 $longestType = $errorPos;
             }
             $spaceCount = substr_count($param->getWhitespaceBeforeComment(), ' ');
             if ($spaceCount < $spaceBeforeComment and $paramComment !== '') {
                 $spaceBeforeComment = $spaceCount;
                 $longestVar = $errorPos;
             }
             // Make sure they are in the correct order, and have the correct name
             $pos = $param->getPosition();
             $paramName = $param->getVarName() !== '' ? $param->getVarName() : '[ UNKNOWN ]';
             if ($previousParam !== null) {
                 $previousName = $previousParam->getVarName() !== '' ? $previousParam->getVarName() : 'UNKNOWN';
                 // Check to see if the parameters align properly
                 if ($param->alignsVariableWith($previousParam) === false) {
                     $this->_currentFile->addEvent('VARIABLES_NAMES_NOT_ALIGN_FUNCTION_COMMENT', array('previousname' => $previousName, 'previousnamepos' => $pos - 1, 'paramname' => $paramName, 'paramnamepos' => $pos), $errorPos);
                 }
                 if ($param->alignsCommentWith($previousParam) === false) {
                     $this->_currentFile->addEvent('COMMENTS_NOT_ALIGN_FUNCTION_COMMENT', array('previousname' => $previousName, 'previousnamepos' => $pos - 1, 'paramname' => $paramName, 'paramnamepos' => $pos), $errorPos);
                 }
             }
             // Variable must be one of the supported standard type
             $typeNames = explode('|', $param->getType());
             foreach ($typeNames as $typeName) {
                 $suggestedName = PHP_CodeSniffer::suggestType($typeName);
                 if ($typeName !== $suggestedName) {
                     $this->_currentFile->addEvent('EXPECTED_FOUND_FUNCTION_COMMENT', array('suggestedname' => $suggestedName, 'paramname' => $paramName, 'typename' => $paramName, 'paramnamepos' => $pos), $errorPos);
                     continue;
                 }
                 if (count($typeNames) !== 1) {
                     continue;
                 }
                 // Check type hint for array and custom type
                 $suggestedTypeHint = '';
                 if (strpos($suggestedName, 'array') !== false) {
                     $suggestedTypeHint = 'array';
                 } else {
                     if (in_array($typeName, PHP_CodeSniffer::$allowedTypes) === false) {
                         $suggestedTypeHint = $suggestedName;
                     }
                 }
                 if ($suggestedTypeHint !== '' and isset($realParams[$pos - 1]) === true) {
                     $typeHint = $realParams[$pos - 1]['type_hint'];
                     if ($typeHint === '') {
                         $this->_currentFile->addEvent('TYPEHINT_MISSING_FUNCTION_COMMENT', array('suggestedtypehint' => $suggestedTypeHint, 'paramname' => $paramName, 'paramnamepos' => $pos), $commentEnd + 2);
                     } else {
                         if ($typeHint !== $suggestedTypeHint) {
                             $this->_currentFile->addEvent('EXPECTED_TYPEHINT_FOUND_FUNCTION_COMMENT', array('suggestedtypehint' => $suggestedTypeHint, 'typehint' => $typeHint, 'paramname' => $paramName, 'paramnamepos' => $pos), $commentEnd + 2);
                         }
                     }
                 } else {
                     if ($suggestedTypeHint === '' and isset($realParams[$pos - 1]) === true) {
                         $typeHint = $realParams[$pos - 1]['type_hint'];
                         if ($typeHint !== '') {
                             $this->_currentFile->addEvent('UNKNOW_TYPEHINT_FOUND_FUNCTION_COMMENT', array('typehint' => $typeHint, 'paramname' => $paramName, 'paramnamepos' => $pos), $commentEnd + 2);
                         }
                     }
                 }
             }
             // Make sure the names of the parameter comment matches the
             // actual parameter
             if (isset($realParams[$pos - 1]) === true) {
                 $realName = $realParams[$pos - 1]['name'];
                 $foundParams[] = $realName;
                 // Append ampersand to name if passing by reference
                 if ($realParams[$pos - 1]['pass_by_reference'] === true) {
                     $realName = '&' . $realName;
                 }
                 if ($realName !== $param->getVarName()) {
                     $this->_currentFile->addEvent('DOCCOMMENT_NOT_MATCH_FUNCTION_COMMENT', array('paramname' => $paramName, 'realname' => $realName, 'paramnamepos' => $pos), $errorPos);
                 }
             } else {
                 // We must have an extra parameter comment
                 $this->_currentFile->addEvent('SUPERFLUOUS_DOCCOMMENT_FUNCTION_COMMENT', array('doccommentpos' => $pos), $errorPos);
             }
             if ($param->getVarName() === '') {
                 $this->_currentFile->addEvent('MISSING_PARAMETER_FUNCTION_COMMENT', array('parameterpos' => $pos), $errorPos);
             }
             if ($param->getType() === '') {
                 $this->_currentFile->addEvent('MISSING_TYPE_FUNCTION_COMMENT', array('typepos' => $pos), $errorPos);
             }
             if ($paramComment === '') {
                 $this->_currentFile->addEvent('MISSING_COMMENT_PARAM_FUNCTION_COMMENT', array('paramname' => $paramName, 'paramnamepos' => $pos), $errorPos);
             } else {
                 // Check if optional params include (Optional) within their description
                 $functionBegin = $this->_currentFile->findNext(array(T_FUNCTION), $commentStart);
                 $functionName = $this->_currentFile->findNext(array(T_STRING), $functionBegin);
                 $openBracket = $this->_tokens[$functionBegin]['parenthesis_opener'];
                 $closeBracket = $this->_tokens[$functionBegin]['parenthesis_closer'];
                 $nextParam = $this->_currentFile->findNext(T_VARIABLE, $openBracket + 1, $closeBracket);
                 while ($nextParam !== false) {
                     $nextToken = $this->_currentFile->findNext(T_WHITESPACE, $nextParam + 1, $closeBracket + 1, true);
                     if ($nextToken === false and $this->_tokens[$nextParam + 1]['code'] === T_CLOSE_PARENTHESIS) {
                         break;
                     }
                     $nextCode = $this->_tokens[$nextToken]['code'];
                     $arg = $this->_tokens[$nextParam]['content'];
                     if ($nextCode === T_EQUAL and $paramName === $arg) {
                         if (substr($paramComment, 0, 11) !== '(Optional) ') {
                             $this->_currentFile->addEvent('OPTIONAL_PARAM_START_FUNCTION_COMMENT', array('paramname' => $paramName), $errorPos);
                         }
                     }
                     $nextParam = $this->_currentFile->findNext(T_VARIABLE, $nextParam + 1, $closeBracket);
                 }
             }
             $previousParam = $param;
         }
         if ($spaceBeforeVar !== 1 and $spaceBeforeVar !== 10000 and $spaceBeforeComment !== 10000) {
             $this->_currentFile->addEvent('ONE_SPACE_LONGEST_TYPE_FUNCTION_COMMENT', array(), $longestType);
         }
         if ($spaceBeforeComment !== 1 and $spaceBeforeComment !== 10000) {
             $this->_currentFile->addEvent('ONE_SPACE_LONGEST_VARIABLE_FUNCTION_COMMENT', array(), $longestVar);
         }
     }
     $realNames = array();
     foreach ($realParams as $realParam) {
         $realNames[] = $realParam['name'];
     }
     // Report missing comments
     $diff = array_diff($realNames, $foundParams);
     foreach ($diff as $neededParam) {
         if (count($params) !== 0) {
             $errorPos = $params[count($params) - 1]->getLine() + $commentStart;
         } else {
             $errorPos = $commentStart;
         }
         $this->_currentFile->addEvent('DOCCOMMENT_MISSING_FUNCTION_COMMENT', array('param' => $neededParam), $errorPos);
     }
 }
 /**
  * Process the function parameter comments
  *
  * @param  integer $commentStart The position in the stack where the comment started
  * @param  integer $commentEnd   The position in the stack where the comment ended
  * @return void
  */
 protected function _processParams($commentStart, $commentEnd)
 {
     $realParams = $this->_currentFile->getMethodParameters($this->_functionToken);
     $params = $this->_commentParser->getParams();
     $foundParams = array();
     if (empty($params) === false) {
         $isSpecialMethod = ($this->_methodName === '__construct' or $this->_methodName === '__destruct');
         if (substr_count($params[count($params) - 1]->getWhitespaceAfter(), $this->_currentFile->eolChar) !== 1 and $isSpecialMethod === false) {
             $errorPos = $params[count($params) - 1]->getLine() + $commentStart;
             $this->_currentFile->addError("No empty line after last parameter comment allowed", $errorPos + 1, 'EmptyLineLastParameterFunctionComment');
         }
         // Parameters must appear immediately after the comment
         if ($params[0]->getOrder() !== 2) {
             $errorPos = $params[0]->getLine() + $commentStart;
             $this->_currentFile->addError("Parameters must appear immediately after the comment", $errorPos, 'ParameterAfterCommentFunctionComment');
         }
         $previousParam = null;
         $spaceBeforeVar = 10000;
         $spaceBeforeComment = 10000;
         $longestType = 0;
         $longestVar = 0;
         if (count($this->_commentParser->getThrows()) !== 0) {
             $isSpecialMethod = false;
         }
         foreach ($params as $param) {
             $paramComment = trim($param->getComment());
             $errorPos = $param->getLine() + $commentStart;
             if ($isSpecialMethod === true and $param->getWhitespaceBeforeType() !== ' ') {
                 $this->_currentFile->addError("Expected 1 space before variable type", $errorPos, 'OneSpaceVariableFunctionComment');
             }
             $spaceCount = substr_count($param->getWhitespaceBeforeVarName(), ' ');
             if ($spaceCount < $spaceBeforeVar) {
                 $spaceBeforeVar = $spaceCount;
                 $longestType = $errorPos;
             }
             $spaceCount = substr_count($param->getWhitespaceBeforeComment(), ' ');
             if ($spaceCount < $spaceBeforeComment and $paramComment !== '') {
                 $spaceBeforeComment = $spaceCount;
                 $longestVar = $errorPos;
             }
             // Make sure they are in the correct order, and have the correct name
             $pos = $param->getPosition();
             $paramName = $param->getVarName() !== '' ? $param->getVarName() : '[ UNKNOWN ]';
             if ($previousParam !== null) {
                 $previousName = $previousParam->getVarName() !== '' ? $previousParam->getVarName() : 'UNKNOWN';
                 // Check to see if the parameters align properly
                 if ($param->alignsVariableWith($previousParam) === false) {
                     $this->_currentFile->addError("The variable names for parameters {$previousName} (" . ($pos - 1) . ") and {$paramName} ({$pos}) do not align", $errorPos, 'VariablesNamesNotAlignFunctionComment');
                 }
                 if ($param->alignsCommentWith($previousParam) === false) {
                     $this->_currentFile->addError("The comments for parameters {$previousName} (" . ($pos - 1) . ") and {$paramName} ({$pos}) do not align", $errorPos, 'CommentsNotAlignFunctionComment');
                 }
             }
             // Variable must be one of the supported standard type
             $typeNames = explode('|', $param->getType());
             foreach ($typeNames as $typeName) {
                 $suggestedName = PHP_CodeSniffer::suggestType($typeName);
                 if ($typeName !== $suggestedName) {
                     $this->_currentFile->addError("Expected {$suggestedName} found {$typeName} for {$paramName} at position {$pos}", $errorPos, 'ExpectedFoundFunctionComment');
                     continue;
                 }
                 if (count($typeNames) !== 1) {
                     continue;
                 }
                 // Check type hint for array and custom type
                 $suggestedTypeHint = '';
                 if (strpos($suggestedName, 'array') !== false) {
                     $suggestedTypeHint = 'array';
                 } else {
                     if (in_array($typeName, PHP_CodeSniffer::$allowedTypes) === false) {
                         $suggestedTypeHint = $suggestedName;
                     }
                 }
                 if ($suggestedTypeHint !== '' and isset($realParams[$pos - 1]) === true) {
                     $typeHint = $realParams[$pos - 1]['type_hint'];
                     if ($typeHint === '') {
                         $this->_currentFile->addError("Type hint {$suggestedTypeHint} missing for {$paramName} at position {$pos}", $commentEnd + 2, 'TypehintMissingFunctionComment');
                     } else {
                         if ($typeHint !== $suggestedTypeHint) {
                             $this->_currentFile->addError("Expected type hint {$suggestedTypeHint} found {$typeHint} for {$paramName} at position {$pos}", $commentEnd + 2, 'ExpectedTypehintFoundFunctionComment');
                         }
                     }
                 } else {
                     if ($suggestedTypeHint === '' and isset($realParams[$pos - 1]) === true) {
                         $typeHint = $realParams[$pos - 1]['type_hint'];
                         if ($typeHint !== '') {
                             $this->_currentFile->addError("Unknown type hint {$typeHint} found for {$paramName} at position {$pos}", $commentEnd + 2, 'UnknowTypehintFoundFunctionComment');
                         }
                     }
                 }
             }
             // Make sure the names of the parameter comment matches the
             // actual parameter
             if (isset($realParams[$pos - 1]) === true) {
                 $realName = $realParams[$pos - 1]['name'];
                 $foundParams[] = $realName;
                 // Append ampersand to name if passing by reference
                 if ($realParams[$pos - 1]['pass_by_reference'] === true) {
                     $realName = '&' . $realName;
                 }
                 if ($realName !== $param->getVarName()) {
                     $this->_currentFile->addError("Doc comment var {$paramName} does not match actual variable name {$realName} at position {$pos}", $errorPos, 'DoccommentNotMatchFunctionComment');
                 }
             } else {
                 // We must have an extra parameter comment
                 $this->_currentFile->addError("Superfluous doc comment at position {$pos}", $errorPos, 'SuperfluousDoccommentFunctionComment');
             }
             if ($param->getVarName() === '') {
                 $this->_currentFile->addError("Missing parameter name at position {$pos}", $errorPos, 'MissingParameterFunctionComment');
             }
             if ($param->getType() === '') {
                 $this->_currentFile->addError("Missing type at position {$pos}", $errorPos, 'MissingTypeFunctionComment');
             }
             if ($paramComment === '') {
                 $this->_currentFile->addError("Missing comment for param {$paramName} at position {$pos}", $errorPos, 'MissingCommentParamFunctionComment');
             } else {
                 // Check if optional params include (Optional) within their description
                 $functionBegin = $this->_currentFile->findNext(array(T_FUNCTION), $commentStart);
                 $functionName = $this->_currentFile->findNext(array(T_STRING), $functionBegin);
                 $openBracket = $this->_tokens[$functionBegin]['parenthesis_opener'];
                 $closeBracket = $this->_tokens[$functionBegin]['parenthesis_closer'];
                 $nextParam = $this->_currentFile->findNext(T_VARIABLE, $openBracket + 1, $closeBracket);
                 while ($nextParam !== false) {
                     $nextToken = $this->_currentFile->findNext(T_WHITESPACE, $nextParam + 1, $closeBracket + 1, true);
                     if ($nextToken === false and $this->_tokens[$nextParam + 1]['code'] === T_CLOSE_PARENTHESIS) {
                         break;
                     }
                     $nextCode = $this->_tokens[$nextToken]['code'];
                     $arg = $this->_tokens[$nextParam]['content'];
                     if ($nextCode === T_EQUAL and $paramName === $arg) {
                         if (substr($paramComment, 0, 11) !== '(Optional) ') {
                             $this->_currentFile->addError("Le commentaire pour le parametre {$paramName} doit commencer avec \"(Optional)\"", $errorPos, 'OptionalParamStartFunctionComment');
                         }
                     }
                     $nextParam = $this->_currentFile->findNext(T_VARIABLE, $nextParam + 1, $closeBracket);
                 }
             }
             $previousParam = $param;
         }
         if ($spaceBeforeVar !== 1 and $spaceBeforeVar !== 10000 and $spaceBeforeComment !== 10000) {
             $this->_currentFile->addError("1 espace attendu après la définition du type pour les paramètres", $longestType, 'OneSpaceLongestTypeFunctionComment');
         }
         if ($spaceBeforeComment !== 1 and $spaceBeforeComment !== 10000) {
             $this->_currentFile->addError("1 espace attendu après le nom de la variable pour les paramètres", $longestVar, 'OneSpaceLongestTypeFunctionComment');
         }
     }
     $realNames = array();
     foreach ($realParams as $realParam) {
         $realNames[] = $realParam['name'];
     }
     // Report missing comments
     $diff = array_diff($realNames, $foundParams);
     foreach ($diff as $neededParam) {
         if (count($params) !== 0) {
             $errorPos = $params[count($params) - 1]->getLine() + $commentStart;
         } else {
             $errorPos = $commentStart;
         }
         $this->_currentFile->addError("Commentaire de fonction manquant ({$neededParam})", $errorPos, 'DoccommentMissingFunctionComment');
     }
 }