/** * 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) { $this->helper->addMessage($errorPos, M2_Sniffs_Annotations_Helper::DUPLICATE_VAR); return; } if ($index[0] !== 1) { $this->helper->addMessage($errorPos, M2_Sniffs_Annotations_Helper::VAR_ORDER); } $content = $var->getContent(); if (empty($content) === true) { $this->helper->addMessage($errorPos, M2_Sniffs_Annotations_Helper::MISSING_VAR_TYPE); return; } else { $suggestedType = $this->helper->suggestType($content); if ($content !== $suggestedType) { $data = [$suggestedType, $content]; $this->helper->addMessage($errorPos, M2_Sniffs_Annotations_Helper::INCORRECT_VAR_TYPE, $data); } elseif ($this->helper->isAmbiguous($content, $matches)) { // Warn about ambiguous types ie array or mixed $data = [$matches[1], '@var']; $this->helper->addMessage($errorPos, M2_Sniffs_Annotations_Helper::AMBIGUOUS_TYPE, $data); } } $spacing = substr_count($var->getWhitespaceBeforeContent(), ' '); if ($spacing !== 1) { $data = [$spacing]; $this->helper->addMessage($errorPos, M2_Sniffs_Annotations_Helper::VAR_INDENT, $data); } } else { $this->helper->addMessage($commentEnd, M2_Sniffs_Annotations_Helper::MISSING_VAR); } }