@param \PHP_CodeSniffer\Files\File $phpCsFile
@param int $stackPtr

@return array
965836
protected function getMethodSignature(File $phpCsFile, int $stackPtr): array
    {
        $parameters = $phpCsFile->getMethodParameters($stackPtr);
        $tokens = $phpCsFile->getTokens();

        $arguments = [];
        foreach ($parameters as $parameter) {
            $defaultIndex = $default = null;

            $possibleEqualIndex = $phpCsFile->findNext([T_EQUAL], $parameter['token'] + 1, $parameter['token'] + 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 = null;
                    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';
                    }
                }
            }

            $typehint = $parameter['type_hint'];
            if (substr($typehint, 0, 1) === '?') {
                $typehint = substr($typehint, 1);
            }

            $arguments[] = [
                'variableIndex' => $parameter['token'],
                'variable' => $parameter['name'],
                'typehint' => $typehint,
                'typehintFull' => $parameter['type_hint'],
                'nullable' => $parameter['nullable_type'],
                'defaultIndex' => $defaultIndex,
                'default' => $default,
            ];
        }

        return $arguments;
    }
163137
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens          = $phpcsFile->getTokens();
        $current         = $stackPtr;
        $previousLine    = $tokens[$stackPtr]['line'] - 1;
        $prevLineTokens  = array();

        while ($current >= 0 && $tokens[$current]['line'] >= $previousLine) {
            if ($tokens[$current]['line'] == $previousLine
                && $tokens[$current]['type'] !== 'T_WHITESPACE'
                && $tokens[$current]['type'] !== 'T_COMMENT'
                && $tokens[$current]['type'] !== 'T_DOC_COMMENT_CLOSE_TAG'
                && $tokens[$current]['type'] !== 'T_DOC_COMMENT_WHITESPACE'
            ) {
                $prevLineTokens[] = $tokens[$current]['type'];
            }
            $current--;
        }

        if (isset($prevLineTokens[0])
            && ($prevLineTokens[0] === 'T_OPEN_CURLY_BRACKET'
            || $prevLineTokens[0] === 'T_COLON')
        ) {
            return;
        } else if (count($prevLineTokens) > 0) {
            $fix = $phpcsFile->addFixableError(
                'Missing blank line before return statement',
                $stackPtr,
                'MissedBlankLineBeforeReturn'
            );

            if ($fix === true) {
                $phpcsFile->fixer->beginChangeset();
                $i = 1;
                while ($tokens[$stackPtr-$i]['type'] === "T_WHITESPACE") {
                    $i++;
                }

                $phpcsFile->fixer->addNewline($stackPtr-$i);
                $phpcsFile->fixer->endChangeset();
            }
        }

        return;
    }
612732
public function process(File $phpcsFile, $stackPtr)
    {

        $tokens = $phpcsFile->getTokens();

        $fileName = basename($phpcsFile->getFilename());

        if (strpos($fileName, '_helper.php') !== false) {
            return;
        }

        $className = trim($phpcsFile->getDeclarationName($stackPtr));

        if (strpos($className, 'Migration') === 0 && strpos($fileName, '_') !== false) {
            return;
        }

        $nextContentPtr = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
        $type           = $tokens[$stackPtr]['content'];

        if ($fileName !== $className.'.php' && $this->badFilename === false) {
            $data  = array(
                      $fileName,
                      $className.'.php',
                     );
            $error = 'Filename "%s" doesn\'t match the expected filename "%s"';
            $phpcsFile->addError($error, $nextContentPtr, ucfirst($type).'BadFilename', $data);
            $phpcsFile->recordMetric($nextContentPtr, 'Filename matches '.$type, 'no');
            $this->badFilename = true;
        } else {
            $phpcsFile->recordMetric($nextContentPtr, 'Filename matches '.$type, 'yes');
        }

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

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

        // Find the next non-empty token.
        $openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);

        if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
            // Not a function call.
            return;
        }

        if (isset($tokens[$openBracket]['parenthesis_closer']) === false) {
            // Not a function call.
            return;
        }

        // Find the previous non-empty token.
        $search   = Tokens::$emptyTokens;
        $search[] = T_BITWISE_AND;
        $previous = $phpcsFile->findPrevious($search, ($stackPtr - 1), null, true);
        if ($tokens[$previous]['code'] === T_FUNCTION) {
            // It's a function definition, not a function call.
            return;
        }

        if ($tokens[$previous]['code'] === T_NEW) {
            // We are creating an object, not calling a function.
            return;
        }

        $closeBracket = $tokens[$openBracket]['parenthesis_closer'];

        if (($stackPtr + 1) !== $openBracket) {
            // Checking this: $value = my_function[*](...).
            $error = 'Space before opening parenthesis of function call prohibited';
            $phpcsFile->addError($error, $stackPtr, 'SpaceBeforeOpenBracket');
        }

        $next = $phpcsFile->findNext(T_WHITESPACE, ($closeBracket + 1), null, true);
        if ($tokens[$next]['code'] === T_SEMICOLON) {
            if (in_array($tokens[($closeBracket + 1)]['code'], Tokens::$emptyTokens) === true) {
                $error = 'Space after closing parenthesis of function call prohibited';
                $phpcsFile->addError($error, $closeBracket, 'SpaceAfterCloseBracket');
            }
        }

        // Check if this is a single line or multi-line function call.
        if ($tokens[$openBracket]['line'] === $tokens[$closeBracket]['line']) {
            $this->processSingleLineCall($phpcsFile, $stackPtr, $openBracket, $tokens);
        } else {
            $this->processMultiLineCall($phpcsFile, $stackPtr, $openBracket, $tokens);
        }
    }
1143838
public function process(File $phpcsFile, $stackPtr) {
		$utils = \PHPCS_SecurityAudit\Sniffs\UtilsFactory::getInstance();
		$tokens = $phpcsFile->getTokens();
		$s = $phpcsFile->findNext(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, $stackPtr, null, true, null, true);

		if ($tokens[$s]['code'] == T_OPEN_PARENTHESIS) {
			$closer = $tokens[$s]['parenthesis_closer'];
		} else {
			$closer = $phpcsFile->findNext(T_SEMICOLON, $stackPtr);
			$s = $stackPtr;
		}
		while ($s) {
			$s = $phpcsFile->findNext(array_merge(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, \PHP_CodeSniffer\Util\Tokens::$bracketTokens, \PHPCS_SecurityAudit\Sniffs\Utils::$staticTokens), $s + 1, $closer, true);
			if ($s && $utils::is_token_user_input($tokens[$s])) {
				if (\PHP_CodeSniffer\Config::getConfigData('ParanoiaMode') || !$utils::is_token_false_positive($tokens[$s], $tokens[$s+2])) {
					$phpcsFile->addError('Easy RFI detected because of direct user input with ' . $tokens[$s]['content'] . ' on ' . $tokens[$stackPtr]['content'], $s, 'ErrEasyRFI');
				}
			} elseif ($s && \PHP_CodeSniffer\Config::getConfigData('ParanoiaMode') && $tokens[$s]['content'] != '.') {
				$phpcsFile->addWarning('Possible RFI detected with ' . $tokens[$s]['content'] . ' on ' . $tokens[$stackPtr]['content'], $s, 'WarnEasyRFI');
			}
		}
	}
1233506
public function process(File $phpcsFile, $stackPtr) {
		$utils = new Utils();

		$tokens = $phpcsFile->getTokens();
		if ($tokens[$stackPtr]['content'] == 'drupal_http_request') {
			$closer = $phpcsFile->findNext(T_SEMICOLON, $stackPtr);
			$s = $closer;
			$warn = 1;
			while ($s) {
				$s = $phpcsFile->findPrevious(array(T_CONSTANT_ENCAPSED_STRING,T_DOUBLE_QUOTED_STRING), $s - 1);
				if($tokens[$s]['content'] == "'verify_peer'" || $tokens[$s]['content'] == '"verify_peer"') {
					$warn = 0;
				}
			}
			if ($warn) {
				$phpcsFile->addWarning('Verify that drupal_http_request uses HTTPS and is called with verify_peer in order to validate the certificate', $stackPtr, 'D7HttpRequestSSL');
			}

			$d = $utils::findDirtyParam($phpcsFile, $stackPtr);
			if ($d && $utils::is_token_user_input($tokens[$d])) {
				$phpcsFile->addError('drupal_http_request called with direct user input ' . $tokens[$d]['content'], $stackPtr, 'D7HttpRequestUserInputErr');
			} elseif ($d && \PHP_CodeSniffer\Config::getConfigData('ParanoiaMode')) {
				$phpcsFile->addWarning('drupal_http_request called with variable ' . $tokens[$d]['content'], $stackPtr, 'D7HttpRequestUserInputErr');
			}

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

        $ignore = array(
            \T_DOUBLE_COLON    => true,
            \T_OBJECT_OPERATOR => true,
            \T_FUNCTION        => true,
            \T_CONST           => true,
        );

        $prevToken = $phpcsFile->findPrevious(\T_WHITESPACE, ($stackPtr - 1), null, true);
        if (isset($ignore[$tokens[$prevToken]['code']]) === true) {
            // Not a call to a PHP function.
            return;
        }

        $function   = $tokens[$stackPtr]['content'];
        $functionLc = strtolower($function);

        if (isset($this->functionParameters[$functionLc]) === false) {
            return;
        }

        $parameterCount  = $this->getFunctionCallParameterCount($phpcsFile, $stackPtr);
        $openParenthesis = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);

        // If the parameter count returned > 0, we know there will be valid open parenthesis.
        if ($parameterCount === 0 && $tokens[$openParenthesis]['code'] !== \T_OPEN_PARENTHESIS) {
            return;
        }

        $parameterOffsetFound = $parameterCount - 1;

        foreach ($this->functionParameters[$functionLc] as $offset => $parameterDetails) {
            if ($offset > $parameterOffsetFound) {
                $itemInfo = array(
                    'name'   => $function,
                    'nameLc' => $functionLc,
                    'offset' => $offset,
                );
                $this->handleFeature($phpcsFile, $openParenthesis, $itemInfo);
            }
        }
    }
351923
public function process(File $phpcsFile, $stackPtr)
    {
        $matches = array();
        $tokens  = $phpcsFile->getTokens();

        if (strpos($tokens[$stackPtr]['content'], "\n") != strrpos($tokens[$stackPtr]['content'], "\n")) {
            $error = 'Only use 1 blank line between objects';

            $phpcsFile->addError($error, $stackPtr, 'NoMultipleBlankLines');
        }
    }
928174
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        if ($tokens[$stackPtr]['code'] === T_IS_NOT_EQUAL) {
            $error = '"%s" is not allowed, use "!==" instead';
            $data  = array($tokens[$stackPtr]['content']);
            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'IsNotEqualNotAllowed', $data);
            if ($fix === true) {
                $phpcsFile->fixer->beginChangeset();
                $phpcsFile->fixer->replaceToken($stackPtr, '!==');
                $phpcsFile->fixer->endChangeset();
            }
        }

    }
842573
protected function processMemberVar(
        PHP_CodeSniffer_File $phpcsFile,
        $stackPtr
    ) {
        $tokens = $phpcsFile->getTokens();
        $token  = $tokens[$stackPtr];
        // TODO: don't care for now
    }
1373368
public function process(File $phpcsFile, $stackPtr)
    {
        if ($this->supportsBelow('5.2') === false) {
            return;
        }

        $tokens = $phpcsFile->getTokens();

        // Get next non-whitespace token, and check it isn't the related inline else
        // symbol, which is not allowed prior to PHP 5.3.
        $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);

        if ($next !== false && $tokens[$next]['code'] === \T_INLINE_ELSE) {
            $phpcsFile->addError(
                'Middle may not be omitted from ternary operators in PHP < 5.3',
                $stackPtr,
                'MiddleMissing'
            );
        }
    }
657883
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        $fileName = $phpcsFile->getFilename();
        if ($this->shouldIgnoreMissingNamespace($fileName)) {
            return;
        }

        $tokens = $phpcsFile->getTokens();
        $errorData = array(strtolower($tokens[$stackPtr]['content']));
        $namespace = $phpcsFile->findPrevious(T_NAMESPACE, ($stackPtr - 1));
        if ($namespace === false) {
            $error = 'Each %s must be in a namespace of at least one level (a top-level vendor name)';
            $phpcsFile->addError($error, $stackPtr, 'MissingNamespace', $errorData);
        }
    }
466432
public function process(File $phpcsFile, $stackPtr) {
		$utils = \PHPCS_SecurityAudit\Sniffs\UtilsFactory::getInstance();
		$tokens = $phpcsFile->getTokens();
		if (preg_match('/<|>/', $tokens[$stackPtr]['content'])) {
			$end = $phpcsFile->findNext(T_SEMICOLON, $stackPtr + 1);
			$next = $stackPtr;
			while($next && $next = $phpcsFile->findNext(array_merge(array(T_STRING_CONCAT), \PHP_CodeSniffer\Util\Tokens::$emptyTokens), $next + 1, $end, true)) {
				// Next token will be checked with this sniff, no need to go further
				if (in_array($tokens[$next]['code'], $this->register())) {
					return;
				}
				if ($next && !in_array($tokens[$next]['content'], $utils::getXSSMitigationFunctions())) {
					if ($utils::is_direct_user_input($tokens[$next]['content'])) {
						$phpcsFile->addError('HTML construction with direct user input '.$tokens[$next]['content'].' detected.', $stackPtr, 'D7XSSHTMLConstructErr');
					} elseif (\PHP_CodeSniffer\Config::getConfigData('ParanoiaMode') && !in_array($tokens[$next]['code'], array_merge(array(T_INLINE_ELSE, T_COMMA), \PHP_CodeSniffer\Util\Tokens::$booleanOperators))) {
						if ($tokens[$next]['code'] == T_CLOSE_PARENTHESIS) {
							$f = $phpcsFile->findPrevious(T_STRING, $next);
							if ($f) {
								$phpcsFile->addWarning('HTML construction with '.$tokens[$f]['content'].'() detected.', $stackPtr, 'D7XSSHTMLConstructWarnF');
							}
						} else {
							$phpcsFile->addWarning('HTML construction with '.$tokens[$next]['content'].' detected.', $stackPtr, 'D7XSSHTMLConstructWarn');
						}
					}
				}
				$next = $phpcsFile->findNext(T_STRING_CONCAT, $next + 1, $end);
			}
		}
	}
640418
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        $end = null;
        if (isset($tokens[$stackPtr]['scope_closer'])) {
            $end = $tokens[$stackPtr]['scope_closer'];
        }

        $scope = $phpcsFile->findNext(
            T_FUNCTION,
            $stackPtr,
            $end
        );

        $wantedTokens = array(
            T_PUBLIC,
            T_PROTECTED,
            T_PRIVATE
        );

        while ($scope) {
            $scope = $phpcsFile->findNext(
                $wantedTokens,
                $scope + 1,
                $end
            );

            if ($scope && $tokens[$scope + 2]['code'] === T_VARIABLE) {
                $phpcsFile->addError(
                    'Declare class properties before methods',
                    $scope,
                    'Invalid'
                );
            }
        }
    }
688324
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === true) {
            $openParenthesis  = $tokens[$stackPtr]['parenthesis_opener'];
            $closeParenthesis = $tokens[$stackPtr]['parenthesis_closer'];
        } else {
            if (version_compare(PHPCSHelper::getVersion(), '2.3.4', '>=')) {
                return;
            }

            // Deal with PHPCS 2.3.0-2.3.3 which do not yet set the parenthesis properly for declare statements.
            $openParenthesis = $phpcsFile->findNext(\T_OPEN_PARENTHESIS, ($stackPtr + 1), null, false, null, true);
            if ($openParenthesis === false || isset($tokens[$openParenthesis]['parenthesis_closer']) === false) {
                return;
            }
            $closeParenthesis = $tokens[$openParenthesis]['parenthesis_closer'];
        }

        $directivePtr = $phpcsFile->findNext(\T_STRING, ($openParenthesis + 1), $closeParenthesis, false);
        if ($directivePtr === false) {
            return;
        }

        $directiveContent = $tokens[$directivePtr]['content'];

        if (isset($this->newDirectives[$directiveContent]) === false) {
            $error = 'Declare can only be used with the directives %s. Found: %s';
            $data  = array(
                implode(', ', array_keys($this->newDirectives)),
                $directiveContent,
            );

            $phpcsFile->addError($error, $stackPtr, 'InvalidDirectiveFound', $data);

        } else {
            // Check for valid directive for version.
            $itemInfo = array(
                'name'   => $directiveContent,
            );
            $this->handleFeature($phpcsFile, $stackPtr, $itemInfo);

            // Check for valid directive value.
            $valuePtr = $phpcsFile->findNext($this->ignoreTokens, $directivePtr + 1, $closeParenthesis, true);
            if ($valuePtr === false) {
                return;
            }

            $this->addWarningOnInvalidValue($phpcsFile, $valuePtr, $directiveContent);
        }
    }
1081444
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        $varName = $tokens[$stackPtr]['content'];
        if ($varName !== '$GLOBALS'
            && $varName !== '$HTTP_RAW_POST_DATA'
            && $varName !== '$_COOKIE'
            && $varName !== '$_ENV'
            && $varName !== '$_FILES'
            && $varName !== '$_GET'
            && $varName !== '$_POST'
            && $varName !== '$_REQUEST'
            && $varName !== '$_SERVER'
        ) {
            return;
        }

        $error = "The $varName super global must not be accessed directly.";
        $phpcsFile->addError($error, $stackPtr, 'NoSuperGlobals');
    }
1329551
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {

        $tokens = $phpcsFile->getTokens();
        $forbidden = $this->get_forbidden_tokens();
        $token = $tokens[$stackPtr];
        $phpcsFile->addError($forbidden[$token['code']], $stackPtr, 'Found');
    }