Skip to content
This repository was archived by the owner on Oct 13, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ class XLite_Sniffs_PHP_Commenting_ClassCommentSniff extends XLite_Sniffs_PHP_Com
'allow_multiple' => false,
'order_text' => 'any place',
),
'LC_Dependencies' => array(
'required' => false,
'allow_multiple' => false,
'order_text' => 'any place',
),
);

protected $reqCodeRequire = 'REQ.PHP.4.4.3';
Expand Down
45 changes: 42 additions & 3 deletions devkit/codesniffer/sniffs/XLite/TagsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,8 @@ protected function processVar($errorPos)
$var = $this->commentParser->getVar()->getContent();

// Check type
$r = $this->checkType($var, $this->allowedParamTypes, 'var');
$allowedParamTypes = array_merge($this->allowedParamTypes, $this->getClassAliases($this->currentFile, $errorPos));
$r = $this->checkType($var, $allowedParamTypes, 'var');
if (true !== $r) {
$this->currentFile->addError($this->getReqPrefix('REQ.PHP.3.5.15') . $r, $errorPos);
}
Expand Down Expand Up @@ -840,7 +841,8 @@ protected function processReturn($commentStart, $commentEnd)

// Check type
if ($this->commentParser->getReturn()) {
$r = $this->checkType($this->commentParser->getReturn()->getValue(), $this->allowedReturnTypes, 'return');
$allowedReturnTypes = array_merge($this->allowedReturnTypes, $this->getClassAliases($this->currentFile, $commentStart));
$r = $this->checkType($this->commentParser->getReturn()->getValue(), $allowedReturnTypes, 'return');
if (true !== $r) {
$this->currentFile->addError($this->getReqPrefix('REQ.PHP.3.5.15') . $r, $commentStart + $this->commentParser->getReturn()->getLine());
}
Expand Down Expand Up @@ -913,7 +915,8 @@ protected function processParams($commentStart, $commentEnd, $tagElements)
$errorPos = ($param->getLine() + $commentStart);

// Check type
$r = $this->checkType($param->getType(), $this->allowedParamTypes, 'param');
$allowedParamTypes = array_merge($this->allowedParamTypes, $this->getClassAliases($this->currentFile, $commentStart));
$r = $this->checkType($param->getType(), $allowedParamTypes, 'param');
if (true !== $r) {
$this->currentFile->addError($this->getReqPrefix('REQ.PHP.3.5.15') . $r, $errorPos);
}
Expand Down Expand Up @@ -1143,4 +1146,40 @@ protected function getTagRule(array $tagInfo, $name)
? $tagInfo['internal'][$name]
: $tagInfo[$name];
}

/**
* Get array of uset class aliases in current namespace
*
* @param PHP_CodeSniffer_File $phpcsFile File
* @param integer $position Start position
*
* @return array
*/
protected function getClassAliases($phpcsFile, $position)
{
$startPosition = $phpcsFile->findPrevious(T_NAMESPACE, $position + 1);
$endPosition = $phpcsFile->findPrevious(T_CLASS, $position + 1);

$result = array();

$tokens = $phpcsFile->getTokens();

while ($startPosition < $endPosition) {
$startPosition = $phpcsFile->findNext(T_AS, $startPosition + 1);

if (!$startPosition || $startPosition > $endPosition) {
break;
}

$startPosition = $phpcsFile->findNext(T_STRING, $startPosition + 1);

if (!$startPosition || $startPosition > $endPosition) {
break;
}

$result[] = $tokens[$startPosition]['content'];
}

return $result;
}
}