diff --git a/Oxid/Sniffs/Commenting/FunctionCommentSniff.php b/Oxid/Sniffs/Commenting/FunctionCommentSniff.php index 1cc6602..3d131ef 100644 --- a/Oxid/Sniffs/Commenting/FunctionCommentSniff.php +++ b/Oxid/Sniffs/Commenting/FunctionCommentSniff.php @@ -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') { @@ -63,6 +60,10 @@ protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co return; } + if ($this->isAbstractMethod($phpcsFile, $stackPtr)) { + return; + } + if ($isSpecialMethod === true) { return; } @@ -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.'; @@ -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']; + } }