/** * Process the function parameter comments. * * @param int $commentstart The position in the stack where * the comment started. * * @return void */ protected function processparams($commentstart) { $realparams = $this->currentfile->getmethodparameters($this->_functiontoken); $params = $this->commentparser->getparams(); $foundparams = array(); if (empty($params) === false) { $lastparm = count($params) - 1; if (substr_count($params[$lastparm]->getwhitespaceafter(), $this->currentfile->eolChar) !== 2) { $error = 'Last parameter comment requires a blank newline after it'; $errorpos = $params[$lastparm]->getline() + $commentstart; $this->currentfile->addwarning($error, $errorpos); } $previousparam = null; $spacebeforevar = 10000; $spacebeforecomment = 10000; $longesttype = 0; $longestvar = 0; foreach ($params as $param) { $paramcomment = trim($param->getcomment()); $errorpos = $param->getline() + $commentstart; // Make sure that there is only one space before the var type. if ($param->getwhitespacebeforetype() !== ' ') { $error = 'Expected 1 space before variable type'; $this->currentfile->addwarning($error, $errorpos); } $spacecount = substr_count($param->getwhitespacebeforevarname(), ' '); if ($spacecount < $spacebeforevar) { $spacebeforevar = $spacecount; $longesttype = $errorpos; } $spacecount = substr_count($param->getwhitespacebeforecomment(), ' '); if ($spacecount < $spacebeforecomment && $paramcomment !== '') { $spacebeforecomment = $spacecount; $longestvar = $errorpos; } // Make sure they are in the correct order, // and have the correct name. $pos = $param->getposition(); $paramname = $param->getvarname() !== '' ? $param->getvarname() : '[ UNKNOWN ]'; if ($previousparam !== null) { $previousname = $previousparam->getvarname() !== '' ? $previousparam->getvarname() : 'UNKNOWN'; // Check to see if the parameters align properly. if ($param->alignsvariablewith($previousparam) === false) { $error = 'The variable names for parameters ' . $previousname . ' (' . ($pos - 1) . ') and ' . $paramname . ' (' . $pos . ') do not align'; $this->currentfile->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); } } // Make sure the names of the parameter comment matches the // actual parameter. if (isset($realparams[$pos - 1]) === true) { $realname = $realparams[$pos - 1]['name']; $foundparams[] = $realname; // Append ampersand to name if passing by reference. if ($realparams[$pos - 1]['pass_by_reference'] === true) { $realname = '&' . $realname; } if ($realname !== $param->getvarname()) { $error = 'Doc comment var "' . $paramname; $error .= '" does not match actual variable name "' . $realname; $error .= '" at position ' . $pos; $this->currentfile->adderror($error, $errorpos); } } else { // We must have an extra parameter comment. $error = 'Superfluous doc comment at position ' . $pos; $this->currentfile->adderror($error, $errorpos); } if ($param->getvarname() === '') { $error = 'Missing parameter name at position ' . $pos; $this->currentfile->adderror($error, $errorpos); } if ($param->gettype() === '') { $error = 'Missing type at position ' . $pos; $this->currentfile->adderror($error, $errorpos); } if ($paramcomment === '') { $error = 'Missing comment for param "' . $paramname . '" at position ' . $pos; $this->currentfile->adderror($error, $errorpos); } $previousparam = $param; } if ($spacebeforevar !== 1 && $spacebeforevar !== 10000 && $spacebeforecomment !== 10000) { $error = 'Expected 1 space after the longest type'; $this->currentfile->adderror($error, $longesttype); } if ($spacebeforecomment !== 1 && $spacebeforecomment !== 10000) { $error = 'Expected 1 space after the longest variable name'; $this->currentfile->adderror($error, $longestvar); } } $realnames = array(); foreach ($realparams as $realparam) { $realnames[] = $realparam['name']; } // Report and missing comments. $diff = array_diff($realnames, $foundparams); foreach ($diff as $neededparam) { if (count($params) !== 0) { $errorpos = $params[count($params) - 1]->getline() + $commentstart; } else { $errorpos = $commentstart; } $error = 'Doc comment for "' . $neededparam . '" missing'; $this->currentfile->adderror($error, $errorpos); } }