/** * Check if a comment has a valid 'inheritdoc' annotation. * @param \PHP_CodeSniffer_File $phpcsFile * @param int $stackPtr * @param int $commentStart * @param int $commentEnd * @return bool * @author Safak Ozpinar <*****@*****.**> */ protected function validateInheritdoc(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart, $commentEnd) { $classHelper = new ClassHelper($phpcsFile); $commentString = $phpcsFile->getTokensAsString($commentStart, $commentEnd - $commentStart + 1); if (preg_match('/\\{\\@inheritdoc\\}/', $commentString)) { $classes = $classHelper->getClassParentsAndInterfaces($stackPtr, 'validate {@inheritdoc}'); if (false !== $classes) { $method = $phpcsFile->getDeclarationName($stackPtr); foreach ($classes as $class) { if (method_exists($class, $method)) { return true; } } $error = 'No overrided method found for {@inheritdoc} annotation'; $phpcsFile->addError($error, $commentStart, 'InvalidInheritdoc'); } else { return true; } } return false; }
/** * Check i f a token is a test class method comment. * @param \PHP_CodeSniffer_File $phpcsFile * @param int $commentEnd * @return bool * @author Safak Ozpinar <*****@*****.**> */ protected function isTestClassMethodComment(PHP_CodeSniffer_File $phpcsFile, $commentEnd) { $method = $this->getCommentMethod($phpcsFile, $commentEnd); if (false !== $method) { $classHelper = new ClassHelper($phpcsFile); return $classHelper->isTestClassMethod($method); } return false; }