Skip to content

Commit

Permalink
ESDEV-4533 Better solution for ignore abstract method return type
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbbbauer committed Jun 2, 2017
1 parent 656e3ac commit f83870c
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions Oxid/Sniffs/Commenting/FunctionCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
$methodName = $phpcsFile->getDeclarationName($stackPtr);
$isSpecialMethod = ($methodName === '__construct' || $methodName === '__destruct');

$methodProperties = $phpcsFile->getMethodProperties($stackPtr);
$isAbstractMethod = $methodProperties['is_abstract'];

$return = null;
foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
if ($tokens[$tag]['content'] === '@return') {
Expand All @@ -63,6 +60,10 @@ protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
return;
}

if ($this->isAbstractMethod($phpcsFile, $stackPtr)) {
return;
}

if ($isSpecialMethod === true) {
return;
}
Expand All @@ -73,10 +74,8 @@ protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
$error = 'Return type missing for @return tag in function comment';
$phpcsFile->addError($error, $return, 'MissingReturnType');
} elseif (!$this->functionHasReturnStatement($phpcsFile, $stackPtr)) {
if (!$isAbstractMethod) {
$error = 'Function return type is set, but function has no return statement';
$phpcsFile->addError($error, $return, 'InvalidNoReturn');
}
$error = 'Function return type is set, but function has no return statement';
$phpcsFile->addError($error, $return, 'InvalidNoReturn');
}
} elseif ($this->functionHasReturnStatement($phpcsFile, $stackPtr)) {
$error = 'Missing @return tag in function comment.';
Expand Down Expand Up @@ -136,4 +135,18 @@ protected function isInterface(PHP_CodeSniffer_File $phpcsFile) {

return $this->isFileInterface[$checkFile] = (bool)(empty($interface) == false);
}

/**
* Check, if the given method is abstract.
*
* @param PHP_CodeSniffer_File $phpCsFile
* @param int $stackPointer
*
* @return bool Is the method, given by the file and the pointer, an abstract method?
*/
protected function isAbstractMethod(PHP_CodeSniffer_File $phpCsFile, $stackPointer) {
$methodProperties = $phpCsFile->getMethodProperties($stackPointer);

return $methodProperties['is_abstract'];
}
}

0 comments on commit f83870c

Please sign in to comment.