@param \PHP_CodeSniffer\Files\File $phpCsFile
@param int $docBlockStartIndex
@param int $docBlockEndIndex

@return void
14266
protected function checkAnnotationTagGrouping(File $phpCsFile, int $docBlockStartIndex, int $docBlockEndIndex): void
    {
        $tags = $this->readTags($phpCsFile, $docBlockStartIndex, $docBlockEndIndex);

        $currentTag = null;
        foreach ($tags as $i => $tag) {
            if ($currentTag === null) {
                $currentTag = $tag['tag'];
                continue;
            }

            if ($currentTag === $tag['tag'] || strpos($tag['tag'], $currentTag) === 0) {
                $this->assertNoSpacing($phpCsFile, $tags[$i - 1], $tag);
                continue;
            }

            $this->assertSpacing($phpCsFile, $tags[$i - 1], $tag);
            $currentTag = $tag['tag'];
        }
    }
557215
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();
        $bracketStart = DWS_Helpers_Bracket::bracketStart($phpcsFile, $stackPtr);
        $bracketEnd = DWS_Helpers_Bracket::bracketEnd($phpcsFile, $stackPtr);

        if ($tokens[$bracketStart]['line'] === $tokens[$bracketEnd]['line']) {
            return; // Single-line expressions don't have indentation to worry about.
        }

        $beginningIndent = DWS_Helpers_WhiteSpace::indentOfLine($phpcsFile, $bracketStart);

        if ($tokens[$bracketEnd]['column'] !== $beginningIndent) {
            $data = [$beginningIndent - 1, $tokens[$bracketEnd]['column'] - 1, $tokens[$bracketEnd]['content']];
            $phpcsFile->addError('Expected indentation of %s spaces, %s found for ending bracket "%s"', $bracketEnd, 'EndIndent', $data);
        }

        $nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $bracketStart + 1, $bracketEnd, true);
        if ($nextToken !== false && $tokens[$nextToken]['line'] === $tokens[$bracketStart]['line']) {
            $data = [$tokens[$bracketStart]['content']];
            $phpcsFile->addError('Expected first item after opening "%s" to be indented on a new line', $nextToken, 'OpeningIndent', $data);
        }

        $firstOnLine = $bracketStart + 1;
        for ($line = $tokens[$bracketStart]['line'] + 1; $line < $tokens[$bracketEnd]['line']; $line++) {
            while ($tokens[$firstOnLine]['line'] < $line || in_array($tokens[$firstOnLine]['code'], PHP_CodeSniffer_Tokens::$emptyTokens)) {
                if (array_key_exists('parenthesis_closer', $tokens[$firstOnLine])) {
                    $firstOnLine = $tokens[$firstOnLine]['parenthesis_closer'] + 1;
                    $line = $tokens[$firstOnLine]['line'];
                    continue 2;
                } elseif (array_key_exists('bracket_closer', $tokens[$firstOnLine])) {
                    $firstOnLine = $tokens[$firstOnLine]['bracket_closer'] + 1;
                    $line = $tokens[$firstOnLine]['line'];
                    continue 2;
                }

                $firstOnLine++;
            }

            if ($tokens[$firstOnLine]['line'] === $line && $tokens[$firstOnLine]['column'] !== $beginningIndent + 4) {
                $data = [$beginningIndent + 3, $tokens[$firstOnLine]['column'] - 1];
                $phpcsFile->addError('Expected indentation of %s spaces, %s found', $firstOnLine, 'MultiLineIndent', $data);
            }
        }
    }
202752
private function fixNoReturnFound(File $phpcsFile, int $closingBracePtr): void
    {
        $tokens = $phpcsFile->getTokens();
        $closingBraceToken = $tokens[$closingBracePtr];

        $expectedReturnSpaces = str_repeat($this->identation, $closingBraceToken['level'] + 1);

        $phpcsFile->fixer->beginChangeset();
        $phpcsFile->fixer->addNewlineBefore($closingBracePtr - 1);
        $phpcsFile->fixer->addContentBefore($closingBracePtr - 1, $expectedReturnSpaces . 'return $this;');
        $phpcsFile->fixer->addNewlineBefore($closingBracePtr - 1);
        $phpcsFile->fixer->endChangeset();
    }
711072
protected function addDocBlock(File $phpcsFile, int $index, string $returnType): void
    {
        $tokens = $phpcsFile->getTokens();

        $firstTokenOfLine = $this->getFirstTokenOfLine($tokens, $index);

        $indentation = $this->getIndentationWhitespace($phpcsFile, $index);

        $phpcsFile->fixer->beginChangeset();
        $phpcsFile->fixer->addNewlineBefore($firstTokenOfLine);
        $phpcsFile->fixer->addContentBefore($firstTokenOfLine, $indentation . ' */');
        $phpcsFile->fixer->addNewlineBefore($firstTokenOfLine);
        $phpcsFile->fixer->addContentBefore($firstTokenOfLine, $indentation . ' * @return ' . $returnType);
        $phpcsFile->fixer->addNewlineBefore($firstTokenOfLine);
        $phpcsFile->fixer->addContentBefore($firstTokenOfLine, $indentation . '/**');
        $phpcsFile->fixer->endChangeset();
    }
268363
protected function fixDocCommentCloseTags(File $phpCsFile, int $index): void
    {
        $tokens = $phpCsFile->getTokens();

        $content = $tokens[$index]['content'];
        if ($content === '*/') {
            return;
        }

        $fix = $phpCsFile->addFixableError('Inline Doc Block comment end tag should be `*/`, got `' . $content . '`', $index, 'EndTag');
        if (!$fix) {
            return;
        }

        $phpCsFile->fixer->beginChangeset();

        $phpCsFile->fixer->replaceToken($index, '*/');

        $phpCsFile->fixer->endChangeset();
    }
792165
protected function _addNewTemplateDocBlock(File $file, array $annotations, $phpOpenTagIndex, $docBlockCloseIndex) {
		$helper = new DocBlockHelper(new View());

		$annotationStrings = [];
		foreach ($annotations as $key => $annotation) {
			if (!is_object($annotation)) {
				throw new RuntimeException('Must be object: ' . print_r($annotation, true));
			}
			$annotationStrings[$key] = (string)$annotation;
		}

		$annotationString = $helper->classDescription('', '', $annotationStrings);
		if (PHP_EOL !== "\n") {
			$annotationString = str_replace("\n", PHP_EOL, $annotationString);
		}

		if ($phpOpenTagIndex === null) {
			$annotationString = '<?php' . PHP_EOL . $annotationString . PHP_EOL . '?>';
		}

		$docBlock = $annotationString . PHP_EOL;
		if (!$file->getTokens()) {
			$this->_counter[static::COUNT_ADDED] = count($annotations);

			return $docBlock;
		}

		$fixer = $this->_getFixer($file);
		if ($phpOpenTagIndex === null) {
			$fixer->addContentBefore(0, $docBlock);
		} else {
			$fixer->addContent($phpOpenTagIndex, $docBlock);
		}

		$this->_counter[static::COUNT_ADDED] = count($annotations);

		if ($docBlockCloseIndex && $this->_isInlineDocBlockRedundant($file, $annotations, $docBlockCloseIndex)) {
			$tokens = $file->getTokens();
			$docBlockOpenIndex = $tokens[$docBlockCloseIndex]['comment_opener'];
			for ($i = $docBlockCloseIndex + 1; $i >= $docBlockOpenIndex; $i--) {
				$fixer->replaceToken($i, '');
			}

			$this->_counter[static::COUNT_ADDED]--;
		}

		$newContent = $fixer->getContents();

		return $newContent;
	}
621011
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        $this->currentFile = $phpcsFile;

        $tokens       = $phpcsFile->getTokens();
        $commentStart = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);

        if ($tokens[$commentStart]['code'] === T_COMMENT) {
            $phpcsFile->addError('You must use "/**" style comments for a file comment', $commentStart, 'WrongStyle');
            return ($phpcsFile->numTokens + 1);
        } else if ($commentStart === false || $tokens[$commentStart]['code'] !== T_DOC_COMMENT_OPEN_TAG) {
            $phpcsFile->addError('Missing file doc comment', $stackPtr, 'Missing');
            return ($phpcsFile->numTokens + 1);
        }

        $commentEnd = $tokens[$commentStart]['comment_closer'];

        // No blank line between the open tag and the file comment.
        if ($tokens[$commentStart]['line'] > ($tokens[$stackPtr]['line'] + 1)) {
            $error = 'There must be no blank lines before the file comment';
            $phpcsFile->addError($error, $stackPtr, 'SpacingAfterOpen');
        }

        // Exactly one blank line after the file comment.
        $next = $phpcsFile->findNext(T_WHITESPACE, ($commentEnd + 1), null, true);
        if ($tokens[$next]['line'] !== ($tokens[$commentEnd]['line'] + 2)) {
            $error = 'There must be exactly one blank line after the file comment';
            $phpcsFile->addError($error, $commentEnd, 'SpacingAfterComment');
        }

        // Required tags in correct order.
        $required = array(
                     '@package'    => true,
                     '@subpackage' => true,
                     '@author'     => true,
                     '@copyright'  => true,
                    );

        $foundTags = array();
        foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
            $name       = $tokens[$tag]['content'];
            $isRequired = isset($required[$name]);

            if ($isRequired === true && in_array($name, $foundTags) === true) {
                $error = 'Only one %s tag is allowed in a file comment';
                $data  = array($name);
                $phpcsFile->addError($error, $tag, 'Duplicate'.ucfirst(substr($name, 1)).'Tag', $data);
            }

            $foundTags[] = $name;

            if ($isRequired === false) {
                continue;
            }

            $string = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $tag, $commentEnd);
            if ($string === false || $tokens[$string]['line'] !== $tokens[$tag]['line']) {
                $error = 'Content missing for %s tag in file comment';
                $data  = array($name);
                $phpcsFile->addError($error, $tag, 'Empty'.ucfirst(substr($name, 1)).'Tag', $data);
                continue;
            }

        }//end foreach

        // Check if the tags are in the correct position.
        $pos = 0;
        foreach ($required as $tag => $true) {
            if (in_array($tag, $foundTags) === false) {
                $error = 'Missing %s tag in file comment';
                $data  = array($tag);
                $phpcsFile->addError($error, $commentEnd, 'Missing'.ucfirst(substr($tag, 1)).'Tag', $data);
            }

            if (isset($foundTags[$pos]) === false) {
                break;
            }

            if ($foundTags[$pos] !== $tag) {
                $error = 'The tag in position %s should be the %s tag';
                $data  = array(
                          ($pos + 1),
                          $tag,
                         );
                $phpcsFile->addError($error, $tokens[$commentStart]['comment_tags'][$pos], ucfirst(substr($tag, 1)).'TagOrder', $data);
            }

            $pos++;
        }//end foreach

        // Ignore the rest of the file.
        return ($phpcsFile->numTokens + 1);

    }
802238
protected function fixOrder(File $phpCsFile, int $docBlockStartIndex, int $docBlockEndIndex, array $tags): void
    {
        $errors = [];
        foreach ($tags as $i => $tag) {
            if (isset($tag['error'])) {
                $errors[$i] = $tag['error'];
            }
        }

        if (!$errors) {
            return;
        }

        $fix = $phpCsFile->addFixableError('Invalid order of tags: ' . implode(', ', $errors), $docBlockEndIndex, 'OrderInvalid');
        if (!$fix) {
            return;
        }

        $tokens = $phpCsFile->getTokens();

        $phpCsFile->fixer->beginChangeset();

        $order = $this->getTagOrderMap();

        $newOrder = [];
        foreach ($tags as $tag) {
            $tagOrder = isset($order[$tag['tag']]) ? $order[$tag['tag']] : -1;
            $newOrder[$tagOrder][] = $this->getContent($tokens, $tag['start'], $tag['end']);
        }

        ksort($newOrder);
        if (isset($newOrder[-1])) {
            ksort($newOrder[-1]);
        }

        $content = '';
        foreach ($newOrder as $tagGroup) {
            $content .= implode('', $tagGroup);
        }

        $firstTagTokenIndex = $tags[0]['start'];
        $lastTagTokenIndex = $tags[count($tags) - 1]['end'];

        for ($i = $firstTagTokenIndex; $i < $lastTagTokenIndex; $i++) {
            $phpCsFile->fixer->replaceToken($i, '');
        }

        $phpCsFile->fixer->replaceToken($lastTagTokenIndex, $content);

        $phpCsFile->fixer->endChangeset();
    }
163102
protected function checkConstantsInterface(File $phpCsFile, int $stackPointer): void
    {
        $docBlockEndIndex = $this->findDocBlock($phpCsFile, $stackPointer);

        if (!$docBlockEndIndex) {
            $this->addNewDocBlock($phpCsFile, $stackPointer);
            return;
        }

        $this->checkExistingDocBlock($phpCsFile, $docBlockEndIndex);
    }
253738
protected function clearWhitespacesBeforeIndex(File $phpcsFile, int $index): void
    {
        $tokens = $phpcsFile->getTokens();

        if ($tokens[$index - 1]['code'] !== T_WHITESPACE) {
            return;
        }

        $phpcsFile->fixer->replaceToken($index - 1, '');
    }
72486
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        // If this is a function/class/interface doc block comment, skip it.
        // We are only interested in inline doc block comments, which are
        // not allowed.
        if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_OPEN_TAG) {
            $nextToken = $phpcsFile->findNext(
                PHP_CodeSniffer_Tokens::$emptyTokens,
                ($stackPtr + 1),
                null,
                true
            );

            $ignore = array(
                       T_CLASS,
                       T_INTERFACE,
                       T_TRAIT,
                       T_FUNCTION,
                       T_CLOSURE,
                       T_PUBLIC,
                       T_PRIVATE,
                       T_PROTECTED,
                       T_FINAL,
                       T_STATIC,
                       T_ABSTRACT,
                       T_CONST,
                       T_PROPERTY,
                       T_OBJECT,
                      );

            // We allow phpdoc before all those tokens.
            if (in_array($tokens[$nextToken]['code'], $ignore) === true) {
                return;
            }

            // Allow phpdoc before define() token (see CONTRIB-4150).
            if ($tokens[$nextToken]['code'] == T_STRING and $tokens[$nextToken]['content'] == 'define') {
                return;
            }

            if ($phpcsFile->tokenizerType === 'JS') {
                // We allow block comments if a function or object
                // is being assigned to a variable.
                $ignore    = PHP_CodeSniffer_Tokens::$emptyTokens;
                $ignore[]  = T_EQUAL;
                $ignore[]  = T_STRING;
                $ignore[]  = T_OBJECT_OPERATOR;
                $nextToken = $phpcsFile->findNext($ignore, ($nextToken + 1), null, true);
                if ($tokens[$nextToken]['code'] === T_FUNCTION
                    || $tokens[$nextToken]['code'] === T_CLOSURE
                    || $tokens[$nextToken]['code'] === T_OBJECT
                    || $tokens[$nextToken]['code'] === T_PROTOTYPE
                ) {
                    return;
                }
            }

            // Allow php docs after php open tag (file phpdoc).
            $prevToken = $phpcsFile->findPrevious(
                PHP_CodeSniffer_Tokens::$emptyTokens,
                ($stackPtr - 1),
                null,
                true
            );
            if ($tokens[$prevToken]['code'] === T_OPEN_TAG) {
                return;
            }

            // Allow @var (type hinting) phpdocs matching beginning of next line.
            $nextToken = $phpcsFile->findNext(
                T_DOC_COMMENT_WHITESPACE,
                ($stackPtr + 1),
                null,
                true
            );
            // Is it a @var tag in the comment?
            if ($tokens[$nextToken]['code'] === T_DOC_COMMENT_TAG &&
                    $tokens[$nextToken]['content'] == '@var') {
                $nextToken = $phpcsFile->findNext(
                    T_DOC_COMMENT_WHITESPACE,
                    ($nextToken + 1),
                    null,
                    true
                );
                // Does the @var comment string end with a variable?
                if ($tokens[$nextToken]['code'] === T_DOC_COMMENT_STRING) {
                    if (preg_match('/\$[^ ]+ *$/', $tokens[$nextToken]['content'], $matches)) {
                        $foundvar = trim($matches[0]);
                        // Does the found variable match any next line beginning with any of:
                        //   - a list() statement containing the variable.
                        //   - the variable.
                        $nextToken = $phpcsFile->findNext(
                            PHP_CodeSniffer_Tokens::$emptyTokens,
                            ($nextToken + 1),
                            null,
                            true
                        );
                        if ($tokens[$nextToken]['code'] === T_LIST) {
                            // Let's look within the list for the variable,
                            // calculating its start and end.
                            $liststart = $phpcsFile->findNext(
                                T_OPEN_PARENTHESIS,
                                ($nextToken + 1)
                            );
                            $listend = $phpcsFile->findNext(
                                T_CLOSE_PARENTHESIS,
                                ($liststart + 1)
                            );
                            // Now look for the var within the list used variables.
                            $nextToken = $phpcsFile->findNext(
                                T_VARIABLE,
                                $liststart,
                                $listend,
                                false,
                                $foundvar,
                                true
                            );
                            if (!$nextToken) {
                                // Not valid type-hinting, specialised error.
                                $error = 'Inline doc block type-hinting for \'%s\' does not match next list() variables';
                                $data = array($foundvar);
                                $phpcsFile->addError($error, $stackPtr, 'TypeHintingList', $data);
                            }
                        } else if ($tokens[$nextToken]['content'] !== $foundvar) {
                            // Not valid type-hinting, specialised error.
                            $error = 'Inline doc block type-hinting for \'%s\' does not match next code line \'%s...\'';
                            $data = array($foundvar, $tokens[$nextToken]['content']);
                            $phpcsFile->addError($error, $stackPtr, 'TypeHintingMatch', $data);
                        }
                        return; // Have finished.
                    }
                }
            }


            if ($tokens[$stackPtr]['content'] === '/**') {
                $error = 'Inline doc block comments are not allowed; use "// Comment." instead';
                $phpcsFile->addError($error, $stackPtr, 'DocBlock');
            }
        }//end if

        if ($tokens[$stackPtr]['content']{0} === '#') {
            $error = 'Perl-style comments are not allowed; use "// Comment." instead';
            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'WrongStyle');
            if ($fix === true) {
                $comment = ltrim($tokens[$stackPtr]['content'], "# \t");
                $phpcsFile->fixer->replaceToken($stackPtr, "// $comment");
            }
        }

        // We don't want end of block comments. If the last comment is a closing
        // curly brace.
        $previousContent = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
        if ($tokens[$previousContent]['line'] === $tokens[$stackPtr]['line']) {
            if ($tokens[$previousContent]['code'] === T_CLOSE_CURLY_BRACKET) {
                return;
            }

            // Special case for JS files.
            if ($tokens[$previousContent]['code'] === T_COMMA
                || $tokens[$previousContent]['code'] === T_SEMICOLON
            ) {
                $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($previousContent - 1), null, true);
                if ($tokens[$lastContent]['code'] === T_CLOSE_CURLY_BRACKET) {
                    return;
                }
            }
        }

        $comment = rtrim($tokens[$stackPtr]['content']);

        // Only want inline comments.
        if (substr($comment, 0, 2) !== '//') {
            return;
        }

        // Allow pure comment separators only (look for comments having at least 10 hyphens).
        if (preg_match('!^// (.*?)(-{10})(.*)$!', $comment, $matches)) {
            // It's a comment separator.
            // Verify it's pure.
            $wrongcharsfound = trim(str_replace('-', '', $matches[1] . $matches[3]));
            if ($wrongcharsfound !== '') {
                $error = 'Comment separators are not allowed to contain other chars buy hyphens (-). Found: (%s)';
                // Basic clean dupes for notification
                $wrongcharsfound = implode(array_keys(array_flip(preg_split('//', $wrongcharsfound, -1, PREG_SPLIT_NO_EMPTY))));
                $data = array($wrongcharsfound);
                $phpcsFile->addWarning($error, $stackPtr, 'IncorrectCommentSeparator', $data);
            }
            // Verify length between 20 and 120
            $hyphencount = strlen($matches[1] . $matches[2] . $matches[3]);
            if ($hyphencount < 20 or $hyphencount > 120) {
                $error = 'Comment separators length must contain 20-120 chars, %s found';
                $phpcsFile->addWarning($error, $stackPtr, 'WrongCommentSeparatorLength', array($hyphencount));
            }
            // Verify it's the first token in the line.
            $prevToken = $phpcsFile->findPrevious(
                PHP_CodeSniffer_Tokens::$emptyTokens,
                ($stackPtr - 1),
                null,
                true
            );
            if (!empty($prevToken) and $tokens[$prevToken]['line'] == $tokens[$stackPtr]['line']) {
                $error = 'Comment separators must be the unique text in the line, code found before';
                $phpcsFile->addWarning($error, $stackPtr, 'WrongCommentCodeFoundBefore', array());
            }
            // Don't want to continue processing the comment separator.
            return;
        }

        // Count slashes.
        $slashCount = strlen(preg_replace('!^(/*).*!', '\\1', trim($comment)));

        // Three or more slashes not allowed.
        if ($slashCount > 2) {
            $error = '%s slashes comments are not allowed; use "// Comment." instead';
            $data = array($slashCount);
            $phpcsFile->addError($error, $stackPtr, 'WrongStyle', $data);
        }

        if (trim(substr($comment, $slashCount)) !== '') {
            $spaceCount = 0;
            $tabFound   = false;

            $commentLength = strlen($comment);
            for ($i = $slashCount; $i < $commentLength; $i++) {
                if ($comment[$i] === "\t") {
                    $tabFound = true;
                    break;
                }

                if ($comment[$i] !== ' ') {
                    break;
                }

                $spaceCount++;
            }

            $fix = false;
            if ($tabFound === true) {
                $error = 'Tab found before comment text; expected "// %s" but found "%s"';
                $data  = array(
                          ltrim(substr($comment, $slashCount)),
                          $comment,
                         );
                $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'TabBefore', $data);
            } else if ($spaceCount === 0) {
                $error = 'No space found before comment text; expected "// %s" but found "%s"';
                $data  = array(
                          substr($comment, $slashCount),
                          $comment,
                         );
                $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpaceBefore', $data);
            } else if ($spaceCount > 1) {
                $error = 'Expected 1 space before comment text but found %s; use block comment if you need indentation';
                $data  = array(
                          $spaceCount,
                          substr($comment, ($slashCount + $spaceCount)),
                          $comment,
                         );
                $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBefore', $data);
            }//end if

            if ($fix === true) {
                $newComment = '// '.ltrim($tokens[$stackPtr]['content'], "/\t ");
                $phpcsFile->fixer->replaceToken($stackPtr, $newComment);
            }
        }//end if

        // The below section determines if a comment block is correctly capitalised,
        // and ends in a full-stop. It will find the last comment in a block, and
        // work its way up.
        $nextComment = $phpcsFile->findNext(array(T_COMMENT), ($stackPtr + 1), null, false);
        if (($nextComment !== false)
            && (($tokens[$nextComment]['line']) === ($tokens[$stackPtr]['line'] + 1))
        ) {
            return;
        }

        $topComment  = $stackPtr;
        $lastComment = $stackPtr;
        while (($topComment = $phpcsFile->findPrevious(array(T_COMMENT), ($lastComment - 1), null, false)) !== false) {
            if ($tokens[$topComment]['line'] !== ($tokens[$lastComment]['line'] - 1)) {
                break;
            }

            $lastComment = $topComment;
        }

        $topComment  = $lastComment;
        $commentText = '';

        for ($i = $topComment; $i <= $stackPtr; $i++) {
            if ($tokens[$i]['code'] === T_COMMENT) {
                $otherSlashCount = strlen(preg_replace('!^(/*).*!', '\\1', trim($tokens[$i]['content'])));
                $commentText .= trim(substr($tokens[$i]['content'], $otherSlashCount));
            }
        }

        // Now rtrim parenthesis and quotes, English can have the full-stop
        // within them if they are full sentences.
        $commentText = rtrim($commentText, "'\")");

        if ($commentText === '') {
            $error = 'Blank comments are not allowed';
            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'Empty');
            if ($fix === true) {
                $phpcsFile->fixer->replaceToken($stackPtr, '');
            }

            return;
        }

        // Start with upper case, digit or 3-dots sequence.
        if (preg_match('!^([A-Z0-9]|\.{3})!', $commentText) === 0) {
            $error = 'Inline comments must start with a capital letter, digit or 3-dots sequence';
            $phpcsFile->addWarning($error, $topComment, 'NotCapital');
        }

        // End with .!?
        $commentCloser   = $commentText[(strlen($commentText) - 1)];
        $acceptedClosers = array(
                            'full-stops'        => '.',
                            'exclamation marks' => '!',
                            'or question marks' => '?',
                           );

        if (in_array($commentCloser, $acceptedClosers) === false) {
            $error = 'Inline comments must end in %s';
            $ender = '';
            foreach ($acceptedClosers as $closerName => $symbol) {
                $ender .= ' '.$closerName.',';
            }

            $ender = trim($ender, ' ,');
            $data  = array($ender);
            $phpcsFile->addWarning($error, $stackPtr, 'InvalidEndChar', $data);
        }

        // Finally, the line below the last comment cannot be empty if this inline
        // comment is on a line by itself.
        if ($tokens[$previousContent]['line'] < $tokens[$stackPtr]['line']) {
            $start = false;
            for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) {
                if ($tokens[$i]['line'] === ($tokens[$stackPtr]['line'] + 1)) {
                    if ($tokens[$i]['code'] !== T_WHITESPACE) {
                        return;
                    }
                } else if ($tokens[$i]['line'] > ($tokens[$stackPtr]['line'] + 1)) {
                    break;
                }
            }

            $error = 'There must be no blank line following an inline comment';
            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingAfter');
            if ($fix === true) {
                $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
                $phpcsFile->fixer->beginChangeset();
                for ($i = ($stackPtr + 1); $i < $next; $i++) {
                    if ($tokens[$i]['line'] === $tokens[$next]['line']) {
                        break;
                    }

                    $phpcsFile->fixer->replaceToken($i, '');
                }

                $phpcsFile->fixer->endChangeset();
            }
        }//end if

    }
828080
protected function getNamespaceAsString(File $phpCsFile, $startIndex, $endIndex) {
		$tokens = $phpCsFile->getTokens();

		$namespace = '';
		for ($i = $startIndex; $i <= $endIndex; $i++) {
			$namespace .= $tokens[$i]['content'];
		}

		return trim($namespace);
	}
449032
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        // If this is a function/class/interface doc block comment, skip it.
        // We are only interested in inline doc block comments, which are
        // not allowed.
        if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_OPEN_TAG) {
            $nextToken = $phpcsFile->findNext(
                Tokens::$emptyTokens,
                ($stackPtr + 1),
                null,
                true
            );

            $ignore = array(
                       T_CLASS,
                       T_INTERFACE,
                       T_TRAIT,
                       T_FUNCTION,
                       T_CLOSURE,
                       T_PUBLIC,
                       T_PRIVATE,
                       T_PROTECTED,
                       T_FINAL,
                       T_STATIC,
                       T_ABSTRACT,
                       T_CONST,
                       T_PROPERTY,
                      );

            if (in_array($tokens[$nextToken]['code'], $ignore) === true) {
                return;
            }

            if ($phpcsFile->tokenizerType === 'JS') {
                // We allow block comments if a function or object
                // is being assigned to a variable.
                $ignore    = Tokens::$emptyTokens;
                $ignore[]  = T_EQUAL;
                $ignore[]  = T_STRING;
                $ignore[]  = T_OBJECT_OPERATOR;
                $nextToken = $phpcsFile->findNext($ignore, ($nextToken + 1), null, true);
                if ($tokens[$nextToken]['code'] === T_FUNCTION
                    || $tokens[$nextToken]['code'] === T_CLOSURE
                    || $tokens[$nextToken]['code'] === T_OBJECT
                    || $tokens[$nextToken]['code'] === T_PROTOTYPE
                ) {
                    return;
                }
            }

            $prevToken = $phpcsFile->findPrevious(
                Tokens::$emptyTokens,
                ($stackPtr - 1),
                null,
                true
            );

            if ($tokens[$prevToken]['code'] === T_OPEN_TAG) {
                return;
            }

            // Only error once per comment.
            if ($tokens[$stackPtr]['content'] === '/**') {
                $commentEnd  = $phpcsFile->findNext(T_DOC_COMMENT_CLOSE_TAG, ($stackPtr + 1));
                $commentText = $phpcsFile->getTokensAsString($stackPtr, (($commentEnd - $stackPtr) + 1));

                if (strpos($commentText, '@var') === false && strpos($commentText, '@type') === false) {
                    $error = 'Inline doc block comments are not allowed; use "/* Comment */" or "// Comment" instead';
                    $phpcsFile->addError($error, $stackPtr, 'DocBlock');
                }
            }
        }//end if

        if ($tokens[$stackPtr]['content']{0} === '#') {
            $error = 'Perl-style comments are not allowed; use "// Comment" instead';
            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'WrongStyle');
            if ($fix === true) {
                $comment = ltrim($tokens[$stackPtr]['content'], "# \t");
                $phpcsFile->fixer->replaceToken($stackPtr, "// $comment");
            }
        }

        // We don't want:
        // - end of block comments, if the last comment is a closing curly brace
        // - closing comment of previous control structure (see "WhiteSpace.ControlStructureSpacing")
        $previousContent = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
        if ($tokens[$previousContent]['line'] === $tokens[$stackPtr]['line']
            || $tokens[$previousContent]['line'] === ($tokens[$stackPtr]['line'] - 1)
        ) {
            if ($tokens[$previousContent]['code'] === T_CLOSE_CURLY_BRACKET) {
                return;
            }

            // Special case for JS files.
            if ($tokens[$previousContent]['code'] === T_COMMA
                || $tokens[$previousContent]['code'] === T_SEMICOLON
            ) {
                $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($previousContent - 1), null, true);
                if ($tokens[$lastContent]['code'] === T_CLOSE_CURLY_BRACKET) {
                    return;
                }
            }
        }

        $comment = rtrim($tokens[$stackPtr]['content']);

        // Only want inline comments.
        if (substr($comment, 0, 2) !== '//') {
            return;
        }

        if (trim(substr($comment, 2)) !== '') {
            $spaceCount = 0;
            $tabFound   = false;

            $commentLength = strlen($comment);
            for ($i = 2; $i < $commentLength; $i++) {
                if ($comment[$i] === "\t") {
                    $tabFound = true;
                    break;
                }

                if ($comment[$i] !== ' ') {
                    break;
                }

                $spaceCount++;
            }

            $fix = false;
            if ($tabFound === true) {
                $error = 'Tab found before comment text; expected "// %s" but found "%s"';
                $data  = array(
                          ltrim(substr($comment, 2)),
                          $comment,
                         );
                $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'TabBefore', $data);
            } elseif ($spaceCount === 0) {
                $error = 'No space found before comment text; expected "// %s" but found "%s"';
                $data  = array(
                          substr($comment, 2),
                          $comment,
                         );
                $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpaceBefore', $data);
            } elseif ($spaceCount > 1) {
                $error = 'Expected 1 space before comment text but found %s; use block comment if you need indentation';
                $data  = array(
                          $spaceCount,
                          substr($comment, (2 + $spaceCount)),
                          $comment,
                         );
                $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBefore', $data);
            }//end if

            if ($fix === true) {
                $newComment = '// '.ltrim($tokens[$stackPtr]['content'], "/\t ");
                $phpcsFile->fixer->replaceToken($stackPtr, $newComment);
            }
        }//end if

        // The below section determines if a comment block is correctly capitalised,
        // and ends in a full-stop. It will find the last comment in a block, and
        // work its way up.
        $nextComment = $phpcsFile->findNext(array(T_COMMENT), ($stackPtr + 1), null, false);

        if (($nextComment !== false) && (($tokens[$nextComment]['line']) === ($tokens[$stackPtr]['line'] + 1))) {
            return;
        }

        $lastComment = $stackPtr;
        while (($topComment = $phpcsFile->findPrevious(array(T_COMMENT), ($lastComment - 1), null, false)) !== false) {
            if ($tokens[$topComment]['line'] !== ($tokens[$lastComment]['line'] - 1)) {
                break;
            }

            $lastComment = $topComment;
        }

        $topComment  = $lastComment;
        $commentText = '';

        for ($i = $topComment; $i <= $stackPtr; $i++) {
            if ($tokens[$i]['code'] === T_COMMENT) {
                $commentText .= trim(substr($tokens[$i]['content'], 2));
            }
        }

        if ($commentText === '') {
            $error = 'Blank comments are not allowed';
            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'Empty');
            if ($fix === true) {
                $phpcsFile->fixer->replaceToken($stackPtr, '');
            }

            return;
        }

        // If the first character is now uppercase and is not
        // a non-letter character, throw an error.
        // \p{Lu} : an uppercase letter that has a lowercase variant.
        // \P{L}  : a non-letter character.
        if (preg_match('/\p{Lu}|\P{L}/u', $commentText[0]) === 0) {
            $error = 'Inline comments must start with a capital letter';
            $phpcsFile->addError($error, $topComment, 'NotCapital');
        }

        // Only check the end of comment character if the start of the comment
        // is a letter, indicating that the comment is just standard text.
        if (preg_match('/\P{L}/u', $commentText[0]) === 0) {
            $commentCloser   = $commentText[(strlen($commentText) - 1)];
            $acceptedClosers = array(
                                'full-stops'        => '.',
                                'exclamation marks' => '!',
                                'or question marks' => '?',
                               );

            if (in_array($commentCloser, $acceptedClosers) === false) {
                $error = 'Inline comments must end in %s';
                $ender = '';
                foreach ($acceptedClosers as $closerName => $symbol) {
                    $ender .= ' '.$closerName.',';
                }

                $ender = trim($ender, ' ,');
                $data  = array($ender);
                $phpcsFile->addError($error, $stackPtr, 'InvalidEndChar', $data);
            }
        }

        // Finally, the line below the last comment cannot be empty if this inline
        // comment is on a line by itself.
        if ($tokens[$previousContent]['line'] < $tokens[$stackPtr]['line']) {
            for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) {
                if ($tokens[$i]['line'] === ($tokens[$stackPtr]['line'] + 1)) {
                    if ($tokens[$i]['code'] !== T_WHITESPACE) {
                        return;
                    }
                } elseif ($tokens[$i]['line'] > ($tokens[$stackPtr]['line'] + 1)) {
                    break;
                }
            }

            $error = 'There must be no blank line following an inline comment';
            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingAfter');
            if ($fix === true) {
                $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
                $phpcsFile->fixer->beginChangeset();
                for ($i = ($stackPtr + 1); $i < $next; $i++) {
                    if ($tokens[$i]['line'] === $tokens[$next]['line']) {
                        break;
                    }

                    $phpcsFile->fixer->replaceToken($i, '');
                }

                $phpcsFile->fixer->endChangeset();
            }
        }//end if
    }
1361353
protected function addFileDocBlock(File $phpCsFile, int $stackPointer): void
    {
        $phpCsFile->fixer->beginChangeset();

        $this->clearFileDocBlock($phpCsFile, $stackPointer);

        $tokens = $phpCsFile->getTokens();
        $line = $tokens[$stackPointer]['line'];
        $fileDocBlockStartPosition = $stackPointer;
        while ($tokens[$fileDocBlockStartPosition + 1]['line'] === $line) {
            $fileDocBlockStartPosition++;
        }

        $phpCsFile->fixer->addNewline($fileDocBlockStartPosition);
        $phpCsFile->fixer->addContent($fileDocBlockStartPosition, '/**');
        $phpCsFile->fixer->addNewline($fileDocBlockStartPosition);
        $phpCsFile->fixer->addContent($fileDocBlockStartPosition, ' * ' . sprintf(static::EXPECTED_COMMENT_FIRST_LINE_STRING, static::YEAR));
        $phpCsFile->fixer->addNewline($fileDocBlockStartPosition);
        $phpCsFile->fixer->addContent($fileDocBlockStartPosition, ' * ' . static::EXPECTED_COMMENT_SECOND_LINE_STRING);
        $phpCsFile->fixer->addNewline($fileDocBlockStartPosition);
        $phpCsFile->fixer->addContent($fileDocBlockStartPosition, ' */');
        $phpCsFile->fixer->addNewline($fileDocBlockStartPosition);
        $phpCsFile->fixer->addNewline($fileDocBlockStartPosition);

        $phpCsFile->fixer->endChangeset();
    }
141111
protected function removeDefaultArgument(File $phpcsFile, int $startIndex, int $endIndex): void
    {
        $this->clearWhitespacesBeforeIndex($phpcsFile, $startIndex);
        for ($i = $startIndex; $i <= $endIndex; ++$i) {
            $phpcsFile->fixer->replaceToken($i, '');
        }
    }
613991
protected function assertNewLineAtTheBeginning(File $phpCsFile, int $stackPointer): void
    {
        $tokens = $phpCsFile->getTokens();

        $line = $tokens[$stackPointer]['line'];
        $firstTokenInLineIndex = $stackPointer;
        while ($tokens[$firstTokenInLineIndex - 1]['line'] === $line) {
            $firstTokenInLineIndex--;
        }

        $prevContentIndex = $phpCsFile->findPrevious(T_WHITESPACE, $firstTokenInLineIndex - 1, null, true);
        if ($tokens[$prevContentIndex]['type'] === 'T_DOC_COMMENT_CLOSE_TAG') {
            $firstTokenInLineIndex = $tokens[$prevContentIndex]['comment_opener'];
            while ($tokens[$firstTokenInLineIndex - 1]['line'] === $line) {
                $firstTokenInLineIndex--;
            }
        }

        $prevContentIndex = $phpCsFile->findPrevious(T_WHITESPACE, $firstTokenInLineIndex - 1, null, true);

        // Do not mess with the start of the class
        if ($tokens[$prevContentIndex]['type'] === 'T_OPEN_CURLY_BRACKET') {
            return;
        }

        if ($tokens[$prevContentIndex]['line'] < $tokens[$firstTokenInLineIndex]['line'] - 1) {
            return;
        }

        $fix = $phpCsFile->addFixableError('Every function/method needs a newline before', $firstTokenInLineIndex, 'Concrete');
        if ($fix) {
            $phpCsFile->fixer->addNewline($prevContentIndex);
        }
    }
381600
protected function checkFirstAnnotationTag(File $phpCsFile, int $docBlockStartIndex, int $docBlockEndIndex): void
    {
        $tokens = $phpCsFile->getTokens();

        $nextIndex = $phpCsFile->findNext(T_DOC_COMMENT_TAG, $docBlockStartIndex + 1, $docBlockEndIndex);
        if (!$nextIndex) {
            return;
        }

        $prevIndex = $phpCsFile->findPrevious(T_DOC_COMMENT_STRING, $nextIndex - 1, $docBlockStartIndex + 1);
        if (!$prevIndex) {
            $this->checkBeginningOfDocBlock($phpCsFile, $docBlockStartIndex, $nextIndex);
            return;
        }

        $diff = $tokens[$nextIndex]['line'] - $tokens[$prevIndex]['line'];
        if ($diff === 2) {
            return;
        }

        $fix = $phpCsFile->addFixableError('Expected 1 extra new line before tags, got ' . ($diff - 1), $nextIndex, 'ExtraLineMissing');
        if (!$fix) {
            return;
        }

        if ($diff > 2) {
            $phpCsFile->fixer->beginChangeset();

            for ($i = $prevIndex; $i < $nextIndex; $i++) {
                if ($tokens[$i]['line'] <= $tokens[$prevIndex]['line'] + 1 || $tokens[$i]['line'] >= $tokens[$nextIndex]['line']) {
                    continue;
                }
                $phpCsFile->fixer->replaceToken($i, '');
            }

            $phpCsFile->fixer->endChangeset();

            return;
        }

        $i = $nextIndex;
        while ($tokens[$i]['line'] === $tokens[$nextIndex]['line']) {
            $i--;
        }

        $phpCsFile->fixer->beginChangeset();

        $indentation = $this->getIndentationWhitespace($phpCsFile, $docBlockEndIndex);
        $phpCsFile->fixer->addContentBefore($i, $indentation . '*');
        $phpCsFile->fixer->addNewlineBefore($i);

        $phpCsFile->fixer->endChangeset();
    }