Returns leading non-whitespace/comment token.

@param File $phpcsFile All the tokens found in the document.
@param int  $stackPtr  The position of the current token
in the stack passed in $tokens.

@return int|bool
760490
protected function getLeadingContent(File $phpcsFile, $stackPtr)
    {
        $prevNonWhitespace = $phpcsFile->findPrevious(
            array(
             T_WHITESPACE,
             T_COMMENT,
            ),
            ($stackPtr - 1),
            null,
            true
        );

        return $prevNonWhitespace;
    }
432788
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        // Deal with older PHPCS version which don't recognize return type hints
        // as well as newer PHPCS versions (3.3.0+) where the tokenization has changed.
        if ($tokens[$stackPtr]['code'] === \T_FUNCTION || $tokens[$stackPtr]['code'] === \T_CLOSURE) {
            $returnTypeHint = $this->getReturnTypeHintToken($phpcsFile, $stackPtr);
            if ($returnTypeHint !== false) {
                $stackPtr = $returnTypeHint;
            }
        }

        if (isset($this->newTypes[$tokens[$stackPtr]['content']]) === true) {
            $itemInfo = array(
                'name' => $tokens[$stackPtr]['content'],
            );
            $this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
        }
        // Handle class name based return types.
        elseif ($tokens[$stackPtr]['code'] === \T_STRING
            || (\defined('T_RETURN_TYPE') && $tokens[$stackPtr]['code'] === \T_RETURN_TYPE)
        ) {
            $itemInfo = array(
                'name'   => 'Class name',
            );
            $this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
        }
    }
345037
protected function checkBracketSpacing(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        if (isset($tokens[$stackPtr]['parenthesis_opener']) === false) {
            return;
        }

        $parenOpener    = $tokens[$stackPtr]['parenthesis_opener'];
        $parenCloser    = $tokens[$stackPtr]['parenthesis_closer'];
        $spaceAfterOpen = 0;
        if ($tokens[($parenOpener + 1)]['code'] === T_WHITESPACE) {
            $spaceAfterOpen = $tokens[($parenOpener + 1)]['length'];
        }

        if ($spaceAfterOpen !== $this->requiredSpacesAfterOpen) {
            $error = 'Expected %s spaces after "%s" opening bracket; %s found';
            $data  = array(
                      $this->requiredSpacesAfterOpen,
                      $tokens[$stackPtr]['content'],
                      $spaceAfterOpen,
                     );
            $fix   = $phpcsFile->addFixableError($error, ($parenOpener + 1), 'SpacingAfterOpenBrace', $data);

            if ($fix === true) {
                $phpcsFile->fixer->beginChangeset();

                for ($i = $spaceAfterOpen; $i < $this->requiredSpacesAfterOpen; $i++) {
                    $phpcsFile->fixer->addContent($parenOpener, ' ');
                }

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

        if ($tokens[$parenOpener]['line'] === $tokens[$parenCloser]['line']) {
            $spaceBeforeClose = 0;
            if ($tokens[($parenCloser - 1)]['code'] === T_WHITESPACE) {
                $spaceBeforeClose = $tokens[($parenCloser - 1)]['length'];
            }

            if ($spaceBeforeClose !== $this->requiredSpacesBeforeClose) {
                $error = 'Expected %s spaces before "%s" closing bracket; %s found';
                $data  = array(
                          $this->requiredSpacesBeforeClose,
                          $tokens[$stackPtr]['content'],
                          $spaceBeforeClose,
                         );
                $fix   = $phpcsFile->addFixableError($error, ($parenCloser - 1), 'SpaceBeforeCloseBrace', $data);

                if ($fix === true) {
                    $phpcsFile->fixer->beginChangeset();

                    for ($i = $spaceBeforeClose; $i < $this->requiredSpacesBeforeClose; $i++) {
                        $phpcsFile->fixer->addContentBefore($parenCloser, ' ');
                    }

                    $phpcsFile->fixer->endChangeset();
                }
            }
        }//end if
    }
139049
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        // Scope keyword should be on a new line.
        if (isset($tokens[$stackPtr]['scope_opener']) === true
            || $tokens[$stackPtr]['code'] === T_WHILE
            || $tokens[($stackPtr)]['code'] === T_ELSE
        ) {
            // If this is alternate syntax ":" instead of "{" then skip it.
            if (isset($tokens[$stackPtr]['scope_opener']) === true) {
                $openingBracePtr = $tokens[$stackPtr]['scope_opener'];
                if ($tokens[$openingBracePtr]['code'] === T_COLON) {
                    return;
                }
            }

            $prevContentPtr = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);

            // Skip if this T_IF is part of an else if.
            if ($tokens[($stackPtr)]['code'] !== T_IF
                && $tokens[($prevContentPtr)]['code'] !== T_ELSE
            ) {
                $keywordLine     = $tokens[($stackPtr)]['line'];
                $prevContentLine = $tokens[($prevContentPtr)]['line'];

                if ($keywordLine === $prevContentLine) {
                    $data  = array($tokens[$stackPtr]['content']);
                    $error = 'Scope keyword "%s" should be on a new line';
                    $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'ScopeKeywordOnNewLine', $data);
                    if ($fix === true) {
                        $phpcsFile->fixer->beginChangeset();
                        $phpcsFile->fixer->addNewlineBefore($stackPtr);
                        $phpcsFile->fixer->endChangeset();
                    }
                }
            }
        }//end if

        // Expect 1 space after keyword, Skip T_ELSE, T_DO, T_TRY.
        if (isset($tokens[$stackPtr]['scope_opener']) === true
            && $tokens[($stackPtr)]['code'] !== T_ELSE
            && $tokens[($stackPtr)]['code'] !== T_DO
            && $tokens[($stackPtr)]['code'] !== T_TRY
        ) {
            $found = 1;
            if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
                $found = 0;
            } else if ($tokens[($stackPtr + 1)]['content'] !== ' ') {
                if (strpos($tokens[($stackPtr + 1)]['content'], $phpcsFile->eolChar) !== false) {
                    $found = 'newline';
                } else {
                    $found = strlen($tokens[($stackPtr + 1)]['content']);
                }
            }

            if ($found !== 1) {
                $error = 'Expected 1 space after scope keyword "%s", found %s';
                $data  = array(
                          strtoupper($tokens[$stackPtr]['content']),
                          $found,
                         );

                $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceAfterScopeKeyword', $data);
                if ($fix === true) {
                    if ($found === 0) {
                        $phpcsFile->fixer->addContent($stackPtr, ' ');
                    } else {
                        $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' ');
                    }
                }
            }
        }//end if

        // Opening brace should be on a new line.
        if (isset($tokens[$stackPtr]['scope_opener']) === true) {
            $openingBracePtr = $tokens[$stackPtr]['scope_opener'];
            $braceLine       = $tokens[$openingBracePtr]['line'];

            // If this is alternate syntax ":" instead of "{" then skip it.
            if (isset($tokens[$stackPtr]['scope_opener']) === true) {
                $openingBracePtr = $tokens[$stackPtr]['scope_opener'];
                if ($tokens[$openingBracePtr]['code'] === T_COLON) {
                    return;
                }
            }

            if ($tokens[($stackPtr)]['code'] === T_ELSE
                || $tokens[($stackPtr)]['code'] === T_TRY
                || $tokens[($stackPtr)]['code'] === T_DO
            ) {
                $scopeLine = $tokens[$stackPtr]['line'];
                // Measure from the scope opener.
                $lineDifference = ($braceLine - $scopeLine);
            } else {
                $closerLine = $tokens[$tokens[$stackPtr]['parenthesis_closer']]['line'];
                // Measure from the scope closing parenthesis.
                $lineDifference = ($braceLine - $closerLine);
            }

            if ($lineDifference !== 1) {
                $data = array(
                         $tokens[$openingBracePtr]['content'],
                         $tokens[$stackPtr]['content'],
                        );
                if (isset($closerLine) === true) {
                    $error = 'Opening brace "%s" should be on a new line after "%s (...)"';
                } else {
                    $error = 'Opening brace "%s" should be on a new line after the keyword "%s"';
                }

                $fix = $phpcsFile->addFixableError($error, $openingBracePtr, 'ScopeOpeningBraceOnNewLine', $data);
                if ($fix === true) {
                    $prevContentPtr = $phpcsFile->findPrevious(T_WHITESPACE, ($openingBracePtr - 1), null, true);
                    $phpcsFile->fixer->beginChangeset();
                    for ($i = ($prevContentPtr + 1); $i < $openingBracePtr; $i++) {
                        $phpcsFile->fixer->replaceToken($i, '');
                    }

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

        // No empty lines after opening brace.
        if (isset($tokens[$stackPtr]['scope_opener']) === true) {
            $openerPtr = $tokens[$stackPtr]['scope_opener'];

            $nextContentPtr = $phpcsFile->findNext(T_WHITESPACE, ($openerPtr + 1), null, true);

            $braceLine       = $tokens[$openerPtr]['line'];
            $nextContentLine = $tokens[$nextContentPtr]['line'];

            $lineDifference = ($nextContentLine - $braceLine);

            if ($lineDifference === 0 || $lineDifference > 1) {
                $data  = array($tokens[$openerPtr]['content']);
                $error = 'Expected content on line after "%s"';
                $fix   = $phpcsFile->addFixableError($error, $openerPtr, 'NewlineAfterOpeningBrace', $data);
                if ($fix === true) {
                    $phpcsFile->fixer->beginChangeset();
                    for ($i = ($openerPtr + 1); $i < $nextContentPtr; $i++) {
                        $phpcsFile->fixer->replaceToken($i, '');
                    }

                    $phpcsFile->fixer->addContent($openerPtr, $phpcsFile->eolChar);
                    $phpcsFile->fixer->endChangeset();
                }
            }
        }//end if

        // Closing brace should be on a new line.
        if (isset($tokens[$stackPtr]['scope_closer']) === true) {
            $closerPtr = $tokens[$stackPtr]['scope_closer'];

            $prevContentPtr = $phpcsFile->findPrevious(T_WHITESPACE, ($closerPtr - 1), null, true);

            $braceLine       = $tokens[$closerPtr]['line'];
            $prevContentLine = $tokens[$prevContentPtr]['line'];

            $lineDifference = ($braceLine - $prevContentLine);

            if ($lineDifference !== 1) {
                $data  = array($tokens[$closerPtr]['content']);
                $error = 'Closing brace "%s" should be on a new line';
                $fix   = $phpcsFile->addFixableError($error, $closerPtr, 'ClosingBraceOnNewLine', $data);
                if ($fix === true) {
                    $phpcsFile->fixer->beginChangeset();
                    for ($i = ($prevContentPtr + 1); $i < $closerPtr; $i++) {
                        $phpcsFile->fixer->replaceToken($i, '');
                    }

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

    }
525097
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

		$valid = false;

		if (preg_match('|//\s|', $tokens[$stackPtr]['content']))
		{
			$valid = true;
		}

		if (preg_match('|\*[\s/]|', $tokens[$stackPtr]['content']))
		{
			$valid = true;
		}

		if ($valid === false)
		{
            $error = 'A space is required at the start of the comment %s';
            $data  = array(trim($tokens[$stackPtr]['content']));
            $phpcsFile->addError($error, $stackPtr, 'Found', $data);
        }

    }
297112
public function process(File $phpcsFile, $stackPtr)
    {
        if ($this->supportsAbove('7.0') === false) {
            return;
        }

        $tokens         = $phpcsFile->getTokens();
        $tokenCode      = $tokens[$stackPtr]['code'];
        $tokenType      = $tokens[$stackPtr]['type'];
        $tokenContentLc = strtolower($tokens[$stackPtr]['content']);

        // For string tokens we only care about 'trait' as that is the only one
        // which may not be correctly recognized as it's own token.
        // This only happens in older versions of PHP where the token doesn't exist yet as a keyword.
        if ($tokenCode === \T_STRING && $tokenContentLc !== 'trait') {
            return;
        }

        if (\in_array($tokenType, array('T_CLASS', 'T_INTERFACE', 'T_TRAIT'), true)) {
            // Check for the declared name being a name which is not tokenized as T_STRING.
            $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
            if ($nextNonEmpty !== false && isset($this->forbiddenTokens[$tokens[$nextNonEmpty]['code']]) === true) {
                $name = $tokens[$nextNonEmpty]['content'];
            } else {
                // Get the declared name if it's a T_STRING.
                $name = $phpcsFile->getDeclarationName($stackPtr);
            }
            unset($nextNonEmpty);

            if (isset($name) === false || \is_string($name) === false || $name === '') {
                return;
            }

            $nameLc = strtolower($name);
            if (isset($this->allForbiddenNames[$nameLc]) === false) {
                return;
            }

        } elseif ($tokenCode === \T_NAMESPACE) {
            $namespaceName = $this->getDeclaredNamespaceName($phpcsFile, $stackPtr);

            if ($namespaceName === false || $namespaceName === '') {
                return;
            }

            $namespaceParts = explode('\\', $namespaceName);
            foreach ($namespaceParts as $namespacePart) {
                $partLc = strtolower($namespacePart);
                if (isset($this->allForbiddenNames[$partLc]) === true) {
                    $name   = $namespacePart;
                    $nameLc = $partLc;
                    break;
                }
            }
        } elseif ($tokenCode === \T_STRING) {
            // Traits which are not yet tokenized as T_TRAIT.
            $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
            if ($nextNonEmpty === false) {
                return;
            }

            $nextNonEmptyCode = $tokens[$nextNonEmpty]['code'];

            if ($nextNonEmptyCode !== \T_STRING && isset($this->forbiddenTokens[$nextNonEmptyCode]) === true) {
                $name   = $tokens[$nextNonEmpty]['content'];
                $nameLc = strtolower($tokens[$nextNonEmpty]['content']);
            } elseif ($nextNonEmptyCode === \T_STRING) {
                $endOfStatement = $phpcsFile->findNext(array(\T_SEMICOLON, \T_OPEN_CURLY_BRACKET), ($stackPtr + 1));
                if ($endOfStatement === false) {
                    return;
                }

                do {
                    $nextNonEmptyLc = strtolower($tokens[$nextNonEmpty]['content']);

                    if (isset($this->allForbiddenNames[$nextNonEmptyLc]) === true) {
                        $name   = $tokens[$nextNonEmpty]['content'];
                        $nameLc = $nextNonEmptyLc;
                        break;
                    }

                    $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonEmpty + 1), $endOfStatement, true);
                } while ($nextNonEmpty !== false);
            }
            unset($nextNonEmptyCode, $nextNonEmptyLc, $endOfStatement);
        }

        if (isset($name, $nameLc) === false) {
            return;
        }

        // Still here, so this is one of the reserved words.
        // Build up the error message.
        $error     = "'%s' is a";
        $isError   = null;
        $errorCode = $this->stringToErrorCode($nameLc) . 'Found';
        $data      = array(
            $nameLc,
        );

        if (isset($this->softReservedNames[$nameLc]) === true
            && $this->supportsAbove($this->softReservedNames[$nameLc]) === true
        ) {
            $error  .= ' soft reserved keyword as of PHP version %s';
            $isError = false;
            $data[]  = $this->softReservedNames[$nameLc];
        }

        if (isset($this->forbiddenNames[$nameLc]) === true
            && $this->supportsAbove($this->forbiddenNames[$nameLc]) === true
        ) {
            if (isset($isError) === true) {
                $error .= ' and a';
            }
            $error  .= ' reserved keyword as of PHP version %s';
            $isError = true;
            $data[]  = $this->forbiddenNames[$nameLc];
        }

        if (isset($isError) === true) {
            $error .= ' and should not be used to name a class, interface or trait or as part of a namespace (%s)';
            $data[] = $tokens[$stackPtr]['type'];

            $this->addMessage($phpcsFile, $error, $stackPtr, $isError, $errorCode, $data);
        }
    }
267397
public function process(File $phpcsFile, $stackPtr)
    {
        $this->phpcsFile = $phpcsFile;

        $tokens = $phpcsFile->getTokens();
        $find = Tokens::$methodPrefixes;
        $find[] = T_WHITESPACE;

        $commentEnd = $phpcsFile->findPrevious($find, $stackPtr - 1, null, true);
        if ($tokens[$commentEnd]['code'] === T_COMMENT) {
            // Inline comments might just be closing comments for
            // control structures or functions instead of function comments
            // using the wrong comment type. If there is other code on the line,
            // assume they relate to that code.
            $prev = $phpcsFile->findPrevious($find, $commentEnd - 1, null, true);
            if ($prev !== false && $tokens[$prev]['line'] === $tokens[$commentEnd]['line']) {
                $commentEnd = $prev;
            }
        }

        if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG && $tokens[$commentEnd]['code'] !== T_COMMENT) {
            $phpcsFile->addError('Missing function doc comment', $stackPtr, 'Missing');
            $phpcsFile->recordMetric($stackPtr, 'Function has doc comment', 'no');

            return;
        }

        $phpcsFile->recordMetric($stackPtr, 'Function has doc comment', 'yes');

        if ($tokens[$commentEnd]['code'] === T_COMMENT) {
            $phpcsFile->addError('You must use "/**" style comments for a function comment', $stackPtr, 'WrongStyle');

            return;
        }

        if ($tokens[$commentEnd]['line'] !== ($tokens[$stackPtr]['line'] - 1)) {
            $error = 'There must be no blank lines after the function comment';
            $phpcsFile->addError($error, $commentEnd, 'SpacingAfter');
        }

        $commentStart = $tokens[$commentEnd]['comment_opener'];
        foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
            if ($tokens[$tag]['content'] === '@see') {
                // Make sure the tag isn't empty.
                $string = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $tag, $commentEnd);
                if ($string === false || $tokens[$string]['line'] !== $tokens[$tag]['line']) {
                    $error = 'Content missing for @see tag in function comment';
                    $phpcsFile->addError($error, $tag, 'EmptySees');
                }
            }
        }

        // [2] Added {@inheritdoc} validation for override methods.
        if ($this->validateInheritdoc($phpcsFile, $stackPtr, $commentStart, $commentEnd)) {
            return;
        }

        parent::process($phpcsFile, $stackPtr);
    }
401868
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();
        $open   = $tokens[$stackPtr];

        if ($open['code'] === T_ARRAY) {
            $closePtr = $open['parenthesis_closer'];
        } else {
            $closePtr = $open['bracket_closer'];
        }

        if ($open['line'] <> $tokens[$closePtr]['line']) {
            $arrayIsNotEmpty = $phpcsFile->findPrevious(
                array(
                    T_WHITESPACE,
                    T_COMMENT,
                    T_ARRAY,
                    T_OPEN_PARENTHESIS,
                    T_OPEN_SHORT_ARRAY,
                ),
                $closePtr - 1,
                $stackPtr,
                true
            );
            if ($arrayIsNotEmpty !== false) {
                $lastCommaPtr = $phpcsFile->findPrevious(
                    T_COMMA,
                    $closePtr,
                    $stackPtr
                );
                while ($lastCommaPtr < $closePtr -1) {
                    $lastCommaPtr++;

                    if ($tokens[$lastCommaPtr]['code'] !== T_WHITESPACE
                        && $tokens[$lastCommaPtr]['code'] !== T_COMMENT
                    ) {
                        $fix = $phpcsFile->addFixableError(
                            'Add a comma after each item in a multi-line array',
                            $stackPtr,
                            'Invalid'
                        );

                        if ($fix === true) {
                            $ptr = $phpcsFile->findPrevious(
                                array(T_WHITESPACE, T_COMMENT),
                                $closePtr-1,
                                $stackPtr,
                                true
                            );

                            $phpcsFile->fixer->addContent($ptr, ',');
                            $phpcsFile->fixer->endChangeset();
                        }

                        break;
                    }
                }
            }
        }
    }
535090
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
	{
		$tokens     = $phpcsFile->getTokens();
		$singleLine = false;
		$comment    = trim($tokens[$stackPtr]['content']);

		// Hash comments are not allowed.
		if ($tokens[$stackPtr]['content']{0} === '#')
		{
			$phpcsFile->recordMetric($stackPtr, 'Inline comment style', '# ...');

			$error  = 'Perl-style Hash comments are prohibited. Use "// Comment."';
			$error .= ' or "/* comment */" instead.';
			$fix    = $phpcsFile->addFixableError($error, $stackPtr, 'WrongStyle');

			if ($fix === true)
			{
				$newComment = ltrim($tokens[$stackPtr]['content'], '# ');
				$newComment = '// ' . $newComment;
				$phpcsFile->fixer->replaceToken($stackPtr, $newComment);
			}
		}
		elseif ($tokens[$stackPtr]['content']{0} === '/' && $tokens[$stackPtr]['content']{1} === '/')
		{
			$phpcsFile->recordMetric($stackPtr, 'Inline comment style', '// ...');
			$singleLine = true;
		}
		elseif ($tokens[$stackPtr]['content']{0} === '/' && $tokens[$stackPtr]['content']{1} === '*')
		{
			$phpcsFile->recordMetric($stackPtr, 'Inline comment style', '/* ... */');
		}

		// Always have a space between // and the start of the comment text.
		// The exception to this is if the preceding line consists of a single open bracket.
		if ($tokens[$stackPtr]['content']{0} === '/' && $tokens[$stackPtr]['content']{1} === '/' && isset($tokens[$stackPtr]['content']{2})
			&& $tokens[$stackPtr]['content']{2} !== ' ' && isset($tokens[($stackPtr - 1)]['content']{0})
			&& $tokens[($stackPtr - 1)]['content']{0} !== '}'
		)
		{
			$error = 'Missing space between the // and the start of the comment text.';
			$fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpace');

			if ($fix === true)
			{
				$newComment = ltrim($tokens[$stackPtr]['content'], '\//');
				$newComment = '// ' . $newComment;

				$phpcsFile->fixer->replaceToken($stackPtr, $newComment);
			}
		}

		/*
		 * New lines should always start with an upper case letter, unless
		 * the line is a continuation of a complete sentence,
		 * the term is code and is case sensitive.(@todo)
		 */
		if (($singleLine === true && isset($tokens[$stackPtr]['content']{3}) && $tokens[$stackPtr]['content']{2} === ' '
			&& $tokens[$stackPtr]['content']{3} !== strtoupper($tokens[$stackPtr]['content']{3})) || (isset($comment{2}) && $comment{0} === '*'
			&& $comment{1} === ' ' && $comment{2} !== strtoupper($comment{2}))
		)
		{
			$error = 'Comment must start with a capital letter; found "%s"';
			$previous = $phpcsFile->findPrevious(T_COMMENT, $stackPtr - 1);

			if ($singleLine === true)
			{
				$data       = array($comment{3});
				$newComment = ltrim($tokens[$stackPtr]['content'], '\// ');
				$newComment = '// ' . ucfirst($newComment);
			}
			else
			{
				$data       = array($comment{2});
				$padding    = (strlen($tokens[$stackPtr]['content']) - strlen($comment));
				$padding    = str_repeat("\t", $padding - 2);
				$newComment = ltrim($comment, '* ');
				$newComment = $padding . ' * ' . ucfirst($newComment) . $phpcsFile->eolChar;
			}

			// Check for a comment on the previous line.
			if ($tokens[$previous]['line'] === $tokens[$stackPtr]['line'] - 1 && '/*' !== substr(ltrim($tokens[$previous]['content']), 0, 2))
			{
				$test = trim($tokens[$previous]['content']);

				if ('.' === $test{(strlen($test) - 1)})
				{
					$fix = $phpcsFile->addFixableError($error, $stackPtr, 'LowerCaseAfterSentenceEnd', $data);

					if ($fix === true)
					{
						$phpcsFile->fixer->replaceToken($stackPtr, $newComment);
					}
				}
			}
			else
			{
				$fix = $phpcsFile->addFixableError($error, $stackPtr, 'LowerCaseStart', $data);

				if ($fix === true)
				{
					$phpcsFile->fixer->replaceToken($stackPtr, $newComment);
				}
			}
		}

		/*
		 * Comments should not be on the same line as the code to which they refer
		 * (which puts them after the code they reference).
		 * They should be on their own lines.
		 * @todo Add fixer
		 */
		$previous = $phpcsFile->findPrevious(T_SEMICOLON, $stackPtr);

		if (isset($tokens[$previous]['line']) && $tokens[$previous]['line'] === $tokens[$stackPtr]['line'])
		{
			$error = 'Please put your comment on a separate line *preceding* your code; found "%s"';
			$data = array($comment);
			$phpcsFile->addError($error, $stackPtr, 'SameLine', $data);
		}

		/*
		 * Always have a single blank line before a comment or block of comments.
		 * Don't allow preceding "code" - identified by a semicolon ;)
		 */
		if (isset($tokens[$previous]['line']) && $tokens[$previous]['line'] === $tokens[$stackPtr]['line'] - 1
			&& $tokens[($stackPtr - 1)]['content'] !== '}'
		)
		{
			$error = 'Please consider a blank line preceding your comment.';
			$fix = $phpcsFile->addFixableError($error, $stackPtr, 'BlankBefore');

			if ($fix === true)
			{
				$phpcsFile->fixer->addContent(($previous + 1), $phpcsFile->eolChar);
			}
		}

		/*
		 * Comment blocks that introduce large sections of code and are more than 2 lines long
		 * should use /* * / and should use * on each line with the same space/tab rules as doc
		 * blocks.
		 * If you need a large introduction consider whether this block should be separated into a
		 * method to reduce complexity and therefore providing a full docblock.
		 */
		$next = $phpcsFile->findNext(T_COMMENT, $stackPtr + 1);

		if ($singleLine === true && isset($tokens[$next]['line']) && $tokens[$next]['line'] === $tokens[$stackPtr]['line'] + 1
			&& $tokens[($stackPtr - 1)]['content'] !== '}'
		)
		{
			// The following line contains also a comment.
			$nextNext = $phpcsFile->findNext(T_COMMENT, $next + 1);

			if ($tokens[$nextNext]['line'] === $tokens[$next]['line'] + 1)
			{
				// Found 3 lines of // comments - too much.
				$error = 'Use the /* */ style for comments that span over multiple lines.';
				$phpcsFile->addError($error, $stackPtr, 'MultiLine');
			}
		}
	}
507635
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();
        $arrayStart = DWS_Helpers_Bracket::bracketStart($phpcsFile, $stackPtr);
        $arrayEnd = DWS_Helpers_Bracket::bracketEnd($phpcsFile, $stackPtr);

        $isSingleLine = $tokens[$arrayStart]['line'] === $tokens[$arrayEnd]['line'];

        foreach (DWS_Helpers_Array::commaPositions($phpcsFile, $arrayStart) as $comma) {
            if ($tokens[$comma - 1]['code'] === T_WHITESPACE) {
                $phpcsFile->addError('No whitespace allowed before commas in an array', $comma, 'SpaceBeforeComma');
            }

            if ($isSingleLine) {
                if ($tokens[$comma + 1]['content'] !== ' ') {
                    $phpcsFile->addError('Expected 1 space after comma in single-line array', $comma, 'SingleLineSpaceAfterComma');
                }
            } elseif ($tokens[$comma + 1]['content'][0] !== "\n") {
                $nextMember = $phpcsFile->findNext([T_WHITESPACE, T_COMMENT], $comma + 1, $arrayEnd, true);
                if ($nextMember !== false && $tokens[$nextMember]['line'] === $tokens[$comma]['line']) {
                    $phpcsFile->addError('Comma in multi-line array was not last token on line', $comma, 'MultiLineNewlineAfterComma');
                }
            }
        }
    }
560210
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens    = $phpcsFile->getTokens();
        $tokenType = $tokens[$stackPtr]['type'];

        // Detect incorrectly tokenized binary casts.
        if (isset($this->newTypeCasts[$tokenType]) === false) {
            $tokenContent = $tokens[$stackPtr]['content'];
            switch ($tokenType) {
                case 'T_STRING_CAST':
                    if (preg_match('`^\(\s*binary\s*\)$`i', $tokenContent) !== 1) {
                        return;
                    }

                    $tokenType = 'T_BINARY_CAST';
                    break;

                case 'T_CONSTANT_ENCAPSED_STRING':
                    if ((strpos($tokenContent, 'b"') === 0 && substr($tokenContent, -1) === '"')
                        || (strpos($tokenContent, "b'") === 0 && substr($tokenContent, -1) === "'")
                    ) {
                        $tokenType = 'T_BINARY_CAST';
                    } else {
                        return;
                    }
                    break;

            }
        }

        // If the translation did not yield one of the tokens we are looking for, bow out.
        if (isset($this->newTypeCasts[$tokenType]) === false) {
            return;
        }

        $itemInfo = array(
            'name'    => $tokenType,
            'content' => $tokens[$stackPtr]['content'],
        );
        $this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
    }
744123
protected function getMethodSignature(File $phpCsFile, $stackPtr) {
		$tokens = $phpCsFile->getTokens();

		$startIndex = $phpCsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr + 1);
		$endIndex = $tokens[$startIndex]['parenthesis_closer'];

		$arguments = [];
		$i = $startIndex;
		while ($nextVariableIndex = $phpCsFile->findNext(T_VARIABLE, $i + 1, $endIndex)) {
			$typehintIndex = $defaultIndex = $default = null;
			$possibleTypeHint = $phpCsFile->findPrevious([T_ARRAY_HINT, T_CALLABLE], $nextVariableIndex - 1, $nextVariableIndex - 3);
			if ($possibleTypeHint) {
				$typehintIndex = $possibleTypeHint;
			}

			$possibleEqualIndex = $phpCsFile->findNext([T_EQUAL], $nextVariableIndex + 1, $nextVariableIndex + 3);
			if ($possibleEqualIndex) {
				$whitelist = [T_CONSTANT_ENCAPSED_STRING, T_TRUE, T_FALSE, T_NULL, T_OPEN_SHORT_ARRAY, T_LNUMBER, T_DNUMBER];
				$possibleDefaultValue = $phpCsFile->findNext($whitelist, $possibleEqualIndex + 1, $possibleEqualIndex + 3);
				if ($possibleDefaultValue) {
					$defaultIndex = $possibleDefaultValue;
					//$default = $tokens[$defaultIndex]['content'];
					if ($tokens[$defaultIndex]['code'] === T_CONSTANT_ENCAPSED_STRING) {
						$default = 'string';
					} elseif ($tokens[$defaultIndex]['code'] === T_OPEN_SHORT_ARRAY) {
						$default = 'array';
					} elseif ($tokens[$defaultIndex]['code'] === T_FALSE || $tokens[$defaultIndex]['code'] === T_TRUE) {
						$default = 'bool';
					} elseif ($tokens[$defaultIndex]['code'] === T_LNUMBER) {
						$default = 'int';
					} elseif ($tokens[$defaultIndex]['code'] === T_DNUMBER) {
						$default = 'float';
					} elseif ($tokens[$defaultIndex]['code'] === T_NULL) {
						$default = 'null';
					} else {
						//die('Invalid default type: ' . $default);
					}
				}
			}

			$arguments[] = [
				'variable' => $nextVariableIndex,
				'typehintIndex' => $typehintIndex,
				'defaultIndex' => $defaultIndex,
				'default' => $default,
			];

			$i = $nextVariableIndex;
		}

		return $arguments;
	}
204878
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        // Make sure this is trailing whitespace.
        $line = $tokens[$stackPtr]['line'];
        if (($stackPtr < count($tokens) - 1)
            && $tokens[($stackPtr + 1)]['line'] === $line
        ) {
            return;
        }

        if (strpos($tokens[$stackPtr]['content'], "\n") > 0
            || strpos($tokens[$stackPtr]['content'], "\r") > 0
        ) {
            $warning = 'Please trim any trailing whitespace';
            $phpcsFile->addWarning($warning, $stackPtr, 'Invalid');
        }
    }
1258722
public function process(File $phpcsFile, $stackPtr)
    {
        if ($this->supportsBelow('7.0') === false) {
            return;
        }

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

        // Is the previous token a visibility indicator ?
        if ($prevToken === false || isset(Tokens::$scopeModifiers[$tokens[$prevToken]['code']]) === false) {
            return;
        }

        // Is this a class constant ?
        if ($this->isClassConstant($phpcsFile, $stackPtr) === false) {
            // This may be a constant declaration in the global namespace with visibility,
            // but that would throw a parse error, i.e. not our concern.
            return;
        }

        $phpcsFile->addError(
            'Visibility indicators for class constants are not supported in PHP 7.0 or earlier. Found "%s const"',
            $stackPtr,
            'Found',
            array($tokens[$prevToken]['content'])
        );
    }
150545
public function process(File $phpcsFile, $stackPtr)
    {
        if ($this->supportsBelow('7.0') === false) {
            return;
        }

        $tokens = $phpcsFile->getTokens();
        $token  = $tokens[$stackPtr];

        // Bow out during live coding.
        if (isset($token['parenthesis_opener'], $token['parenthesis_closer']) === false) {
            return;
        }

        $hasBitwiseOr = $phpcsFile->findNext(\T_BITWISE_OR, $token['parenthesis_opener'], $token['parenthesis_closer']);

        if ($hasBitwiseOr === false) {
            return;
        }

        $phpcsFile->addError(
            'Catching multiple exceptions within one statement is not supported in PHP 7.0 or earlier.',
            $hasBitwiseOr,
            'Found'
        );
    }
939875
protected function checkContentInside(File $phpcsFile, $stackPtr)
    {
        $tokens      = $phpcsFile->getTokens();
        $scopeOpener = $tokens[$stackPtr]['scope_opener'];
        $scopeCloser = $tokens[$stackPtr]['scope_closer'];

        $firstContent = $phpcsFile->findNext(
            T_WHITESPACE,
            ($scopeOpener + 1),
            null,
            true
        );

        if ($tokens[$firstContent]['line'] !== ($tokens[$scopeOpener]['line'] + 1)) {
            $data = array($tokens[$stackPtr]['content']);
            $diff = $tokens[$firstContent]['line'] - ($tokens[$scopeOpener]['line'] + 1);
            if ($diff < 0) {
                $error = 'Opening brace of the "%s" control structure must be last content on the line';
                $fix   = $phpcsFile->addFixableError($error, $scopeOpener, 'ContentAfterOpen', $data);
            } else {
                $data[] = $diff;
                $error  = 'Expected 0 blank lines at start of "%s" control structure; %s found';
                $fix    = $phpcsFile->addFixableError($error, $scopeOpener, 'SpacingBeforeOpen', $data);
            }

            if ($fix === true) {
                $phpcsFile->fixer->beginChangeset();

                for ($i = ($firstContent - 1); $i > $scopeOpener; $i--) {
                    if ($tokens[$i]['line'] === $tokens[$firstContent]['line']
                        || $tokens[$i]['line'] === $tokens[$scopeOpener]['line']
                    ) {
                        // Keep existing indentation.
                        continue;
                    }

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

                if ($diff < 0) {
                    $phpcsFile->fixer->addNewline($scopeOpener);
                }

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

        if ($firstContent !== $scopeCloser) {
            // Not an empty control structure.
            $lastContent = $phpcsFile->findPrevious(
                T_WHITESPACE,
                ($scopeCloser - 1),
                null,
                true
            );

            if ($tokens[$lastContent]['line'] !== ($tokens[$scopeCloser]['line'] - 1)) {
                $data = array($tokens[$stackPtr]['content']);
                $diff = (($tokens[$scopeCloser]['line'] - 1) - $tokens[$lastContent]['line']);

                if ($diff < 0) {
                    $error = 'Closing brace of the "%s" control structure must be first content on the line';
                    $fix   = $phpcsFile->addFixableError($error, $scopeCloser, 'SpacingAfterClose', $data);
                } else {
                    $data[] = $diff;
                    $error  = 'Expected 0 blank lines at end of "%s" control structure; %s found';
                    $fix    = $phpcsFile->addFixableError($error, $scopeCloser, 'SpacingAfterClose', $data);
                }

                if ($fix === true) {
                    $phpcsFile->fixer->beginChangeset();

                    for ($i = ($lastContent + 1); $i < $scopeCloser; $i++) {
                        if ($tokens[$i]['line'] === $tokens[$scopeCloser]['line']
                            || $tokens[$i]['line'] === $tokens[$lastContent]['line']
                        ) {
                            // Keep existing indentation.
                            continue;
                        }

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

                    if ($diff < 0) {
                        $phpcsFile->fixer->addNewline($lastContent);
                    }

                    $phpcsFile->fixer->endChangeset();
                }
            }//end if
        }//end if
    }
769482
public function process(File $phpcsFile, $stackPtr) {
		$utils = \PHPCS_SecurityAudit\Sniffs\UtilsFactory::getInstance();

		$tokens = $phpcsFile->getTokens();
		if ($tokens[$stackPtr]['content'] == 'preg_replace') {
			$s = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr);
			$closer = $tokens[$s]['parenthesis_closer'];
			$s = $phpcsFile->findNext(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, $s + 1, $closer, true);
			if ($tokens[$s]['code'] == T_CONSTANT_ENCAPSED_STRING) {
				$pattern = $tokens[$s]['content'];
				if (substr($pattern, 1, 1) === '/') {
					// $pattern is a regex
					if (preg_match('/(\/|\))\w*e\w*"$/', $pattern)) {
						$phpcsFile->addWarning("Usage of preg_replace with /e modifier is not recommended.", $stackPtr, 'PregReplaceE');

						$s = $phpcsFile->findNext(array(T_COMMA, T_WHITESPACE, T_COMMENT, T_DOC_COMMENT), $s + 1, $closer, true);
						if ($utils::is_token_user_input($tokens[$s]))
							$phpcsFile->addError("User input and /e modifier found in preg_replace, remote code execution possible.", $stackPtr, 'PregReplaceUserInputE');
					}

				} else {
					$phpcsFile->addWarning("Weird usage of preg_replace, please check manually for /e modifier.", $stackPtr, 'PregReplaceWeird');
				}
			} elseif ($tokens[$s]['code'] == T_VARIABLE && $utils::is_token_user_input($tokens[$s])) {
				$phpcsFile->addError("User input found in preg_replace, /e modifier could be used for malicious intent.", $stackPtr, 'PregReplaceUserInput');
			} else {
				$phpcsFile->addWarning("Dynamic usage of preg_replace, please check manually for /e modifier or user input.", $stackPtr, 'PregReplaceDyn');
			}
		}

	}