/**
* Process the var 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.
*
* @return void
*/
protected function processVar($commentStart, $commentEnd)
{
$var = $this->commentParser->getVar();
if ($var !== null) {
$errorPos = $commentStart + $var->getLine();
$index = array_keys($this->commentParser->getTagOrders(), 'var');
if (count($index) > 1) {
$error = 'Only 1 @var tag is allowed in variable comment';
$this->currentFile->addError($error, $errorPos, 'DuplicateVar');
return;
}
if ($index[0] !== 1) {
$error = 'The @var tag must be the first tag in a variable comment';
$this->currentFile->addError($error, $errorPos, 'VarOrder');
}
$content = $var->getContent();
if (empty($content) === true) {
$error = 'Var type missing for @var tag in variable comment';
$this->currentFile->addError($error, $errorPos, 'MissingVarType');
return;
} else {
$suggestedType = PHP_CodeSniffer::suggestType($content);
if ($suggestedType !== $content) {
// Hotfix - somehow they do not like "int" and "bool".
switch ($content) {
case 'int':
$suggestedType = 'int';
break;
case 'bool':
$suggestedType = 'bool';
break;
default:
}
}
if ($content !== $suggestedType) {
$error = 'Expected "%s"; found "%s" for @var tag in variable comment';
$data = array($suggestedType, $content);
$this->currentFile->addError($error, $errorPos, 'IncorrectVarType', $data);
}
}
$spacing = substr_count($var->getWhitespaceBeforeContent(), ' ');
if ($spacing !== 1) {
$error = '@var tag indented incorrectly; expected 1 space but found %s';
$data = array($spacing);
$this->currentFile->addError($error, $errorPos, 'VarIndent', $data);
}
} else {
$error = 'Missing @var tag in variable comment';
$this->currentFile->addError($error, $commentEnd, 'MissingVar');
}
//end if
}