Processes the tokens that this sniff is interested in.

@param File $phpcsFile The file where the token was found.
@param int                  $stackPtr  The position in the stack where
the token was found.

@return void
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');
			}
		}

	}
602320
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);

        if (!in_array($arrayStart, [$stackPtr, $stackPtr + 1])) {
            $phpcsFile->addError('No whitespace allowed between the array keyword and the opening parenthesis', $stackPtr, 'SpaceAfterKeyword');
        }

        $firstMember = $phpcsFile->findNext(T_WHITESPACE, $arrayStart + 1, $arrayEnd, true);
        if ($firstMember === false && $arrayEnd - $arrayStart !== 1) {
            $phpcsFile->addError('Empty array declaration must have no space between the brackets', $stackPtr, 'SpaceInEmptyArray');
        }
    }
514866
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens     = $phpcsFile->getTokens();
        $modifyLeft = substr($tokens[($stackPtr - 1)]['content'], 0, 1) === '$'
            || $tokens[($stackPtr + 1)]['content'] === ';';

        if ($modifyLeft === true && $tokens[($stackPtr - 1)]['code'] === T_WHITESPACE) {
            $error = 'There must not be a single space before an unary operator statement';
            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'ExtraSpaceBefore');

            if ($fix === true) {
                $phpcsFile->fixer->beginChangeset();
                $phpcsFile->fixer->replaceToken(($stackPtr - 1), '');
                $phpcsFile->fixer->endChangeset();
            }
        }

        if ($modifyLeft === false && substr($tokens[($stackPtr + 1)]['content'], 0, 1) !== '$') {
            $error = 'A unary operator statement must not followed by a single space';
            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'ExtraSpaceAfter');

            if ($fix === true) {
                $phpcsFile->fixer->beginChangeset();
                $phpcsFile->fixer->replaceToken(($stackPtr + 1), '');
                $phpcsFile->fixer->endChangeset();
            }
        }
    }
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);
        }
    }
17486
public function process(File $phpcsFile, $stackPtr)
    {
        if ($this->supportsAbove('5.3') === false) {
            return;
        }

        $tokens  = $phpcsFile->getTokens();
        $varName = substr($tokens[$stackPtr]['content'], 1);

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

        if ($this->isClassProperty($phpcsFile, $stackPtr) === true) {
            // Ok, so this was a class property declaration, not our concern.
            return;
        }

        // Check for static usage of class properties shadowing the removed global variables.
        if ($this->inClassScope($phpcsFile, $stackPtr, false) === true) {
            $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true);
            if ($prevToken !== false && $tokens[$prevToken]['code'] === \T_DOUBLE_COLON) {
                return;
            }
        }

        // Do some additional checks for the $php_errormsg variable.
        if ($varName === 'php_errormsg'
            && $this->isTargetPHPErrormsgVar($phpcsFile, $stackPtr, $tokens) === false
        ) {
            return;
        }

        // Still here, so throw an error/warning.
        $itemInfo = array(
            'name' => $varName,
        );
        $this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
    }
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);
        }

    }
748636
public function process(File $phpcsFile, $stackPtr) {
		$tokens = $phpcsFile->getTokens();
		$utils = new \PHPCS_SecurityAudit\Sniffs\Utils();

		if ($tokens[$stackPtr]['content'] == 'error_reporting') {
			$p = $utils::get_param_tokens($phpcsFile, $stackPtr, 1);
			if (is_array($p) && count($p) == 1 && $p[0]['content'] === '0') {
				$error = 'Please do not disable error_reporting, it could be useful';
				$phpcsFile->addWarning($error, $stackPtr, 'ErrorReporting0');
			}
		}
	}
902342
public function process(File $phpcsFile, $stackPtr)
    {
        $this->checkContent($phpcsFile, $stackPtr, true);
        $this->checkContent($phpcsFile, $stackPtr, false);
    }
453423
public function process(File $phpcsFile, $stackPtr)
    {
        parent::process($phpcsFile, $stackPtr);

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

        $commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true);
        if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG) {
            return;
        }

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

        $empty = array(
                  T_DOC_COMMENT_WHITESPACE,
                  T_DOC_COMMENT_STAR,
                 );

        $short = $phpcsFile->findNext($empty, ($commentStart + 1), $commentEnd, true);
        if ($short === false || $tokens[$short]['code'] !== T_DOC_COMMENT_STRING) {
            return;
        }

        if ($this->isInheritDoc($phpcsFile, $commentStart) === true) {
            return;
        }

        $this->checkShort($phpcsFile, $stackPtr, $tokens[$short]['content'], $short);
    }
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');
        }
    }
626519
public function process(File $phpcsFile, $stackPtr)
    {
        if ($this->supportsBelow('5.6') === false) {
            return;
        }

        $tokens       = $phpcsFile->getTokens();
        $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
        if ($nextNonEmpty === false || isset($this->indicators[$tokens[$nextNonEmpty]['code']]) === false) {
            return;
        }

        // Still here ? In that case, it is an anonymous class.
        $phpcsFile->addError(
            'Anonymous classes are not supported in PHP 5.6 or earlier',
            $stackPtr,
            'Found'
        );
    }
728369
public function process(File $phpcsFile, $stackPtr)
    {
        $functionPtr = $phpcsFile->findPrevious(T_FUNCTION, ($stackPtr - 1));

        if ($functionPtr !== false) {
            $doubleColonPtr = $phpcsFile->findNext(T_DOUBLE_COLON, ($stackPtr + 1));

            if ($doubleColonPtr !== false) {
                $tokens        = $phpcsFile->getTokens();
                $functionName  = $phpcsFile->getDeclarationName($functionPtr);
                $methodNamePtr = $phpcsFile->findNext(T_STRING, ($stackPtr + 1));

                if ($methodNamePtr !== false && $tokens[$methodNamePtr]['content'] !== $functionName) {
                    $error = 'Method name mismatch in parent:: call';
                    $phpcsFile->addError($error, $stackPtr, 'WrongName');
                }
            }
        }//end if
    }
899997
public function process(File $phpcsFile, $stackPtr) {
		$utils = \PHPCS_SecurityAudit\Sniffs\UtilsFactory::getInstance();
		$tokens = $phpcsFile->getTokens();

		// http://www.php.net/manual/en/book.mysql.php
		if ($tokens[$stackPtr]['content'] == 'mysql_query') {
            $opener = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr, null, false, null, true);
			$closer = $tokens[$opener]['parenthesis_closer'];
            $s = $stackPtr + 1;
			$s = $phpcsFile->findNext(array_merge(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, \PHP_CodeSniffer\Util\Tokens::$bracketTokens, \PHPCS_SecurityAudit\Sniffs\Utils::$staticTokens, array(T_STRING_CONCAT)), $s, $closer, true);
             if ($s) {
				$msg = 'SQL function ' . $tokens[$stackPtr]['content'] . '() detected with dynamic parameter ';
				if ($utils::is_token_user_input($tokens[$s])) {
					$phpcsFile->addError($msg . ' directly from user input', $stackPtr, 'ErrFilesystem');
				} else {
					$phpcsFile->addWarning($msg, $stackPtr, 'WarnFilesystem');
				}
			}
		}

	}
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'
                );
            }
        }
    }
766593
public function process(File $phpcsFile, $stackPtr) {
		$utils = new Utils();
		if ($this->forceParanoia >= 0) {
			$parano =  $this->forceParanoia ? 1 : 0;
		} else {
			$parano = \PHP_CodeSniffer\Config::getConfigData('ParanoiaMode') ? 1 : 0;
		}

		$tokens = $phpcsFile->getTokens();
		if ($tokens[$stackPtr]['content'] == 'db_query' || $tokens[$stackPtr]['content'] == 'db_query_range') {
			$closer = $phpcsFile->findNext(T_SEMICOLON, $stackPtr);
			$s = $phpcsFile->findNext(\PHP_CodeSniffer\Util\Tokens::$stringTokens, $stackPtr + 1, $closer);
			if (preg_match('/{\s*(field_data|node|taxonony_term_data)\w*}/', $tokens[$s]['content'], $matches)) {
				$phpcsFile->addWarning($tokens[$stackPtr]['content'] . ' should not be used with ' . $matches[0] . ' because access control modules won\'t be able to modify or extend your SQL query.', $s, 'D7DbQueryACWar');
			}
		}

		if (in_array(str_replace("'", "", $tokens[$stackPtr]['content']), $utils::getACEntityTypes())) {
			$s = $phpcsFile->findPrevious(\PHP_CodeSniffer\Util\Tokens::$stringTokens, $stackPtr - 1);
			if ($tokens[$s]['content'] == "'entity_type'") {
				// TODO refactor to not have to backtrace for defines, use $utils::addACEntityType
			} elseif ($parano) {
				$isdef = $phpcsFile->findPrevious(T_STRING, $s - 1);
				if ($tokens[$isdef]['content'] == 'define') {
					array_push(self::$defines, str_replace("'", "", $tokens[$s]['content']));
				}
			}
		}

		// TODO the folling two ifs needs refactoring (putting the while in $utils might be a good idea)

		if ($tokens[$stackPtr]['content'] == 'entityCondition') {
			$closer = $phpcsFile->findNext(T_SEMICOLON, $stackPtr);
			$s = $phpcsFile->findNext(\PHP_CodeSniffer\Util\Tokens::$stringTokens, $stackPtr + 1, $closer);
			if ($tokens[$s]['content'] == "'entity_type'") {
				$closer = $phpcsFile->findNext(T_CLOSE_PARENTHESIS, $s);
				$s = $phpcsFile->findNext(array_merge(array(T_STRING), \PHP_CodeSniffer\Util\Tokens::$stringTokens), $s + 1, $closer);
				if ($s) {
					$found = str_replace("'", "", $tokens[$s]['content']);
					if (in_array($found, array_merge(self::$defines, $utils::getACEntityTypes()))) {
						$closer = $phpcsFile->findNext(T_SEMICOLON, $s);
						$warn = true;
						while ($s = $phpcsFile->findNext(T_STRING, $s + 1, $closer)) {
							if ($tokens[$s]['content'] == 'addTag') {
								$c = $phpcsFile->findNext(T_CLOSE_PARENTHESIS, $s);
								$n = $phpcsFile->findNext(array_merge(array(T_STRING), \PHP_CodeSniffer\Util\Tokens::$stringTokens), $s + 1, $c);
								$tag = str_replace("'", "", $tokens[$n]['content']);
								if ($n && in_array($tag, array('node_access','entity_field_access','term_access'))) {
									// This will not warn if wrong _access is used. Please warn anyways when paranoia is enforced.
									$warn = false;
								}
							}
						}
						if ($warn) {
							$phpcsFile->addWarning("EntityFieldQuery with entity type $found should be tagged for access restrictions", $stackPtr, 'D7DbQueryACErr');
						} elseif ($parano) {
							$phpcsFile->addWarning("Please validate that EntityFieldQuery with entity type $found is tagged with adequate access restrictions", $stackPtr, 'D7DbQueryACErr');
						}
					}
				}
			}
		}

		if ($tokens[$stackPtr]['content'] == 'db_select') {
			$closer = $phpcsFile->findNext(T_SEMICOLON, $stackPtr);
			$s = $phpcsFile->findNext(\PHP_CodeSniffer\Util\Tokens::$stringTokens, $stackPtr + 1, $closer);
			if (preg_match('/(field_data|node|taxonony_term_data)\w*/', $tokens[$s]['content'], $matches)) {
				$closer = $phpcsFile->findNext(T_SEMICOLON, $s);
				$warn = true;
				while ($s = $phpcsFile->findNext(T_STRING, $s + 1, $closer)) {
					if ($tokens[$s]['content'] == 'addTag') {
						$c = $phpcsFile->findNext(T_CLOSE_PARENTHESIS, $s);
						$n = $phpcsFile->findNext(array_merge(array(T_STRING), \PHP_CodeSniffer\Util\Tokens::$stringTokens), $s + 1, $c);
						$tag = str_replace("'", "", $tokens[$n]['content']);
						if ($n && in_array($tag, array('node_access','entity_field_access','term_access'))) {
							// This will not warn if wrong _access is used. Please warn anyways when paranoia is enforced.
							$warn = false;
						}
					}
				}
				if ($warn) {
					$phpcsFile->addWarning("Dynamic query with db_select on table $matches[0] should be tagged for access restrictions", $stackPtr, 'D7DbQueryACErr');
				} elseif ($parano) {
					$phpcsFile->addWarning("Please validate that dynamic query with db_select on table $matches[0] is tagged with adequate access restrictions", $stackPtr, 'D7DbQueryACErr');
				}
			}
		}

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

        $tokens = $phpcsFile->getTokens();
        $token  = $tokens[$stackPtr];
        // Skip function without body.
        if (isset($token['scope_opener']) === false) {
            return;
        }

        // Get all parameters from method signature.
        $parameters = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr);
        if (empty($parameters) || \is_array($parameters) === false) {
            return;
        }

        $paramNames = array();
        foreach ($parameters as $param) {
            $paramNames[] = strtolower($param['name']);
        }

        if (\count($paramNames) !== \count(array_unique($paramNames))) {
            $phpcsFile->addError(
                'Functions can not have multiple parameters with the same name since PHP 7.0',
                $stackPtr,
                'Found'
            );
        }
    }
488797
public function process(File $phpcsFile, $stackPtr)
    {
        if ($this->supportsBelow('5.5') !== true) {
            return;
        }

        $tokens = $phpcsFile->getTokens();
        $find   = array(
            \T_ARRAY            => \T_ARRAY,
            \T_OPEN_SHORT_ARRAY => \T_OPEN_SHORT_ARRAY,
        );

        while (($hasArray = $phpcsFile->findNext($find, ($stackPtr + 1), null, false, null, true)) !== false) {
            $phpcsFile->addError(
                'Constant arrays using the "const" keyword are not allowed in PHP 5.5 or earlier',
                $hasArray,
                'Found'
            );

            // Skip past the content of the array.
            $stackPtr = $hasArray;
            if ($tokens[$hasArray]['code'] === \T_OPEN_SHORT_ARRAY && isset($tokens[$hasArray]['bracket_closer'])) {
                $stackPtr = $tokens[$hasArray]['bracket_closer'];
            } elseif ($tokens[$hasArray]['code'] === \T_ARRAY && isset($tokens[$hasArray]['parenthesis_closer'])) {
                $stackPtr = $tokens[$hasArray]['parenthesis_closer'];
            }
        }
    }