Ongr/Sniffs/Commenting/FunctionCommentSniff.php
protected function processComments(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart)
    {
        $tokens = $phpcsFile->getTokens();
        $empty = array(
            T_DOC_COMMENT_WHITESPACE,
            T_DOC_COMMENT_STAR,
        );

        $find = [
            T_DOC_COMMENT_CLOSE_TAG,
            T_DOC_COMMENT_TAG,
        ];

        $commentEnd = $phpcsFile->findNext($find, $commentStart);

        $methodName      = $phpcsFile->getDeclarationName($stackPtr);
        $short = $phpcsFile->findNext($empty, ($commentStart + 1), $commentEnd, true);
        $shortEnd     = $short;
        $shortContent = $tokens[$short]['content'];
        $lastChar = $shortContent[(strlen($shortContent) - 1)];

        // Check for a comment description.
        if (trim($short) === '') {
            // ONGR Comments are not necessary for magic methods.
            $magicMethods = [
                '__call',
                '__callStatic',
                '__clone',
                '__construct',
                '__destruct',
                '__get',
                '__invoke',
                '__isset',
                '__set',
                '__set_state',
                '__sleep',
                '__toString',
                '__unset',
                '__wakeup',
            ];
            $magicRegExp = implode('|', $magicMethods);
            if (preg_match('/^(set|get|has|add|is)[A-Z]|' . $magicRegExp . '/', $methodName) !== 1) {
                $error = 'Missing short description in function doc comment';
                $phpcsFile->addError($error, $commentStart, 'MissingShort');
            }

            return;
        }
        if (preg_match('#^(\p{Lu}|{@inheritdoc})#u', $shortContent) === 0) {
            $error = 'Function comment short description must start with a capital letter';
            $phpcsFile->addError($error, ($commentStart + 1), 'ShortNotCapital');
        }
        if (preg_match('#{@inheritdoc}$#u', $shortContent) === 0 && $lastChar !== '.') {
            $error = 'Function comment short description must end with a full stop';
            $phpcsFile->addError($error, ($commentStart + 1), 'ShortFullStop');
        }

        //Check whitespaces beetween '*' and short comment.
        $foundShort = strlen($tokens[$short-1]['content']);
        if ($foundShort > 1) {
            $phpcsFile->addError(
                "Expected one whitespace before short description. Found {$foundShort}.",
                $short,
                'ExtraWhitespace'
            );
        }

        $long = $phpcsFile->findNext($empty, ($shortEnd + 1), ($commentEnd - 1), true);
        if ($long === false) {
            return;
        }

        //Check whitespaces beetween '*' and long comment.
        $foundLong = strlen($tokens[$long-1]['content']);
        if ($foundLong > 1) {
            $phpcsFile->addError(
                "Expected one whitespace before long description. Found {$foundLong}.",
                $long,
                'ExtraWhitespace'
            );
        }

        if ($tokens[$long]['code'] === T_DOC_COMMENT_STRING) {
            if ($tokens[$long]['line'] !== ($tokens[$shortEnd]['line'] + 2)) {
                $error = 'There must be exactly one blank line between descriptions in a doc comment';
                $phpcsFile->addError($error, $long, 'SpacingBetween');
            }

            if (preg_match('/\p{Lu}|\P{L}/u', $tokens[$long]['content'][0]) === 0) {
                $error = 'Doc comment long description must start with a capital letter';
                $phpcsFile->addError($error, $long, 'LongNotCapital');
            }
        }//end if
    }
protected function processComments(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart)
    {
        $tokens = $phpcsFile->getTokens();
        $empty = array(
            T_DOC_COMMENT_WHITESPACE,
            T_DOC_COMMENT_STAR,
        );

        $find = [
            T_DOC_COMMENT_CLOSE_TAG,
            T_DOC_COMMENT_TAG,
        ];

        $commentEnd = $phpcsFile->findNext($find, $commentStart);

        $methodName      = $phpcsFile->getDeclarationName($stackPtr);
        $short = $phpcsFile->findNext($empty, ($commentStart + 1), $commentEnd, true);
        $shortEnd     = $short;
        $shortContent = $tokens[$short]['content'];
        $lastChar = $shortContent[(strlen($shortContent) - 1)];

        // Check for a comment description.
        if (trim($short) === '') {
            // ONGR Comments are not necessary for magic methods.
            $magicMethods = [
                '__call',
                '__callStatic',
                '__clone',
                '__construct',
                '__destruct',
                '__get',
                '__invoke',
                '__isset',
                '__set',
                '__set_state',
                '__sleep',
                '__toString',
                '__unset',
                '__wakeup',
            ];
            $magicRegExp = implode('|', $magicMethods);
            if (preg_match('/^(set|get|has|add|is)[A-Z]|' . $magicRegExp . '/', $methodName) !== 1) {
                $error = 'Missing short description in function doc comment';
                $phpcsFile->addError($error, $commentStart, 'MissingShort');
            }

            return;
        }
        if (preg_match('#^(\p{Lu}|{@inheritdoc})#u', $shortContent) === 0) {
            $error = 'Function comment short description must start with a capital letter';
            $phpcsFile->addError($error, ($commentStart + 1), 'ShortNotCapital');
        }
        if (preg_match('#{@inheritdoc}$#u', $shortContent) === 0 && $lastChar !== '.') {
            $error = 'Function comment short description must end with a full stop';
            $phpcsFile->addError($error, ($commentStart + 1), 'ShortFullStop');
        }

        //Check whitespaces beetween '*' and short comment.
        $foundShort = strlen($tokens[$short-1]['content']);
        if ($foundShort > 1) {
            $phpcsFile->addError(
                "Expected one whitespace before short description. Found {$foundShort}.",
                $short,
                'ExtraWhitespace'
            );
        }

        $long = $phpcsFile->findNext($empty, ($shortEnd + 1), ($commentEnd - 1), true);
        if ($long === false) {
            return;
        }

        //Check whitespaces beetween '*' and long comment.
        $foundLong = strlen($tokens[$long-1]['content']);
        if ($foundLong > 1) {
            $phpcsFile->addError(
                "Expected one whitespace before long description. Found {$foundLong}.",
                $long,
                'ExtraWhitespace'
            );
        }

        if ($tokens[$long]['code'] === T_DOC_COMMENT_STRING) {
            if ($tokens[$long]['line'] !== ($tokens[$shortEnd]['line'] + 2)) {
                $error = 'There must be exactly one blank line between descriptions in a doc comment';
                $phpcsFile->addError($error, $long, 'SpacingBetween');
            }

            if (preg_match('/\p{Lu}|\P{L}/u', $tokens[$long]['content'][0]) === 0) {
                $error = 'Doc comment long description must start with a capital letter';
                $phpcsFile->addError($error, $long, 'LongNotCapital');
            }
        }//end if
    }
@param PHP_CodeSniffer_File $phpcsFile
@param                      $stackPtr
@param                      $commentStart

@throws PHP_CodeSniffer_Exception