@param \PHP_CodeSniffer\Files\File $phpCsFile

@return array
329719
protected function parseUseStatements(File $phpCsFile): array
    {
        $useStatements = [];
        $tokens = $phpCsFile->getTokens();

        foreach ($tokens as $id => $token) {
            if ($token['type'] !== 'T_USE') {
                continue;
            }

            $endIndex = $phpCsFile->findEndOfStatement($id);
            $useStatement = '';
            for ($i = $id + 2; $i < $endIndex; $i++) {
                $useStatement .= $tokens[$i]['content'];
            }

            $useStatement = trim($useStatement);

            if (strpos($useStatement, ' as ') !== false) {
                [$useStatement, $className] = explode(' as ', $useStatement);
            } else {
                $className = $useStatement;
                if (strpos($useStatement, '\\') !== false) {
                    $lastSeparator = strrpos($useStatement, '\\');
                    $className = substr($useStatement, $lastSeparator + 1);
                }
            }

            $useStatement = '\\' . ltrim($useStatement, '\\');

            $useStatements[$className] = $useStatement;
        }

        return $useStatements;
    }
537415
public function process(File $phpcsFile, $stackPtr)
    {
        if ($this->supportsBelow('7.2') === false) {
            return;
        }

        $tokens = $phpcsFile->getTokens();

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

        if ($tokens[$stackPtr]['code'] === \T_STRING) {
            $ignore = array(
                \T_FUNCTION        => true,
                \T_CONST           => true,
                \T_USE             => true,
            );

            $prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
            if (isset($ignore[$tokens[$prevNonEmpty]['code']]) === true) {
                // Not a function call.
                return;
            }
        }

        $closer            = $tokens[$nextNonEmpty]['parenthesis_closer'];
        $lastInParenthesis = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($closer - 1), $nextNonEmpty, true);

        if ($tokens[$lastInParenthesis]['code'] !== \T_COMMA) {
            return;
        }

        $data = array();
        switch ($tokens[$stackPtr]['code']) {
            case \T_ISSET:
                $data[]    = 'calls to isset()';
                $errorCode = 'FoundInIsset';
                break;

            case \T_UNSET:
                $data[]    = 'calls to unset()';
                $errorCode = 'FoundInUnset';
                break;

            default:
                $data[]    = 'function calls';
                $errorCode = 'FoundInFunctionCall';
                break;
        }

        $phpcsFile->addError(
            'Trailing comma\'s are not allowed in %s in PHP 7.2 or earlier',
            $lastInParenthesis,
            $errorCode,
            $data
        );
    }
313640
protected function isProvider(File $phpCsFile): bool
    {
        return $this->hasCorrectName($phpCsFile, 'DependencyProvider') && $this->isCoreProvider($phpCsFile);
    }
199130
protected function parseUseStatements(File $phpCsFile, int $stackPointer): array
    {
        $useStatements = [];
        $tokens = $phpCsFile->getTokens();
        if ($phpCsFile->findPrevious(T_USE, $stackPointer)) {
            $position = $phpCsFile->findPrevious(T_USE, $stackPointer);
            while ($position !== false) {
                $position = $phpCsFile->findPrevious(T_USE, $position);
                if ($position !== false) {
                    $end = $phpCsFile->findEndOfStatement($position);
                    if ($tokens[$position]['type'] === 'T_USE') {
                        $useTokens = array_slice($tokens, $position + 2, $end - $position - 2);
                        $useStatements[] = $this->parseUseParts($useTokens);
                    }
                }
                $position--;
            }
        }

        return $useStatements;
    }
332659
protected function extractExceptionAnnotations(File $phpCsFile, int $docBlockStartIndex): array
    {
        $tokens = $phpCsFile->getTokens();

        $throwTags = [];
        foreach ($tokens[$docBlockStartIndex]['comment_tags'] as $index) {
            if ($tokens[$index]['content'] !== '@throws') {
                continue;
            }

            if ($tokens[($index + 2)]['code'] !== T_DOC_COMMENT_STRING) {
                continue;
            }

            $fullClass = $tokens[($index + 2)]['content'];
            $space = strpos($fullClass, ' ');
            if ($space !== false) {
                $fullClass = substr($fullClass, 0, $space);
            }

            $class = $fullClass;
            $lastSeparator = strrpos($class, '\\');
            if ($lastSeparator !== false) {
                $class = substr($class, $lastSeparator + 1);
            }

            $throwTags[] = [
                'index' => $index,
                'fullClass' => $fullClass,
                'class' => $class,
            ];
        }

        return $throwTags;
    }
367099
protected function fileExists(File $phpCsFile, string $className): bool
    {
        $fileName = $phpCsFile->getFilename();
        $fileNameParts = explode(DIRECTORY_SEPARATOR, $fileName);
        $sourceDirectoryPosition = array_search('src', $fileNameParts);
        $basePathParts = array_slice($fileNameParts, 0, $sourceDirectoryPosition + 1);

        $basePath = implode(DIRECTORY_SEPARATOR, $basePathParts) . DIRECTORY_SEPARATOR;
        $classFileName = str_replace('\\', DIRECTORY_SEPARATOR, $className);

        $fileName = $basePath . $classFileName . '.php';

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

        $tokens = $phpcsFile->getTokens();

        if ($tokens[$stackPtr]['code'] === \T_OPEN_SHORT_ARRAY) {
            if ($this->isShortList($phpcsFile, $stackPtr) === false) {
                return;
            }

            $open  = $stackPtr;
            $close = $tokens[$stackPtr]['bracket_closer'];
        } else {
            // T_LIST.
            $open = $phpcsFile->findNext(\T_OPEN_PARENTHESIS, $stackPtr, null, false, null, true);
            if ($open === false || isset($tokens[$open]['parenthesis_closer']) === false) {
                return;
            }

            $close = $tokens[$open]['parenthesis_closer'];
        }

        $error = true;
        if (($close - $open) > 1) {
            for ($cnt = $open + 1; $cnt < $close; $cnt++) {
                if (isset($this->ignoreTokens[$tokens[$cnt]['code']]) === false) {
                    $error = false;
                    break;
                }
            }
        }

        if ($error === true) {
            $phpcsFile->addError(
                'Empty list() assignments are not allowed since PHP 7.0',
                $stackPtr,
                'Found'
            );
        }
    }
1228654
protected function getNamespace(File $phpCsFile): string
    {
        $className = $this->getClassName($phpCsFile);
        $classNameParts = explode('\\', $className);

        return $classNameParts[0];
    }
736874
protected function findErrors(File $phpCsFile, int $contentIndex): array
    {
        $tokens = $phpCsFile->getTokens();

        $comment = $tokens[$contentIndex]['content'];

        preg_match('|^(.+?)(\s+)(.+?)\s*$|', $comment, $contentMatches);
        if (!$contentMatches || !$contentMatches[1] || !$contentMatches[3]) {
            $phpCsFile->addError('Invalid Inline Doc Block content', $contentIndex, 'ContentInvalid');
            return [];
        }

        $errors = [];

        if (!preg_match('|([a-z0-9]) $|i', $comment)) {
            $errors['space-before-end'] = 'Expected single space before ´*/´';
        }

        if (!preg_match('|^\$[a-z0-9]+$|i', $contentMatches[3])) {
            $errors['order'] = 'Expected ´{Type} ${var}´, got `' . $contentMatches[1] . $contentMatches[2] . $contentMatches[3] . '`';
        }

        return $errors;
    }
66278
protected function getMethodFileAddedName(File $phpCsFile): string
    {
        return $this->getModule($phpCsFile) . $this->getLayer($phpCsFile) . 'Factory';
    }
822100
protected function parseImplements(File $phpcsFile, int $implementsStartIndex): array
    {
        $implementsEndIndex = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, $implementsStartIndex + 1);

        return $this->parse($phpcsFile, $implementsStartIndex, $implementsEndIndex);
    }
824242
protected function isCore(File $phpCsFile): bool
    {
        $namespace = $this->getNamespace($phpCsFile);

        $coreNamespaces = [
            static::NAMESPACE_SPRYKER,
            static::NAMESPACE_SPRYKER_SDK,
            static::NAMESPACE_SPRYKER_SHOP,
            static::NAMESPACE_SPRYKER_ECO,
        ];

        return in_array($namespace, $coreNamespaces, true);
    }
137915
public function process(File $phpcsFile, $stackPtr)
    {
        if ($this->supportsAbove('7.3') === false) {
            return;
        }

        $tokens = $phpcsFile->getTokens();

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

        $switchOpener = $tokens[$stackPtr]['scope_opener'];
        $switchCloser = $tokens[$stackPtr]['scope_closer'];

        // Quick check whether we need to bother with the more complex logic.
        $hasContinue = $phpcsFile->findNext(\T_CONTINUE, ($switchOpener + 1), $switchCloser);
        if ($hasContinue === false) {
            return;
        }

        $caseDefault = $switchOpener;

        do {
            $caseDefault = $phpcsFile->findNext($this->caseTokens, ($caseDefault + 1), $switchCloser);
            if ($caseDefault === false) {
                break;
            }

            if (isset($tokens[$caseDefault]['scope_opener']) === false) {
                // Unknown start of the case, skip.
                continue;
            }

            $caseOpener      = $tokens[$caseDefault]['scope_opener'];
            $nextCaseDefault = $phpcsFile->findNext($this->caseTokens, ($caseDefault + 1), $switchCloser);
            if ($nextCaseDefault === false) {
                $caseCloser = $switchCloser;
            } else {
                $caseCloser = $nextCaseDefault;
            }

            // Check for unscoped control structures within the case.
            $controlStructure = $caseOpener;
            $doCount          = 0;
            while (($controlStructure = $phpcsFile->findNext($this->loopStructures, ($controlStructure + 1), $caseCloser)) !== false) {
                if ($tokens[$controlStructure]['code'] === \T_DO) {
                    $doCount++;
                }

                if (isset($tokens[$controlStructure]['scope_opener'], $tokens[$controlStructure]['scope_closer']) === false) {
                    if ($tokens[$controlStructure]['code'] === \T_WHILE && $doCount > 0) {
                        // While in a do-while construct.
                        $doCount--;
                        continue;
                    }

                    // Control structure without braces found within the case, ignore this case.
                    continue 2;
                }
            }

            // Examine the contents of the case.
            $continue = $caseOpener;

            do {
                $continue = $phpcsFile->findNext(\T_CONTINUE, ($continue + 1), $caseCloser);
                if ($continue === false) {
                    break;
                }

                $nextSemicolon = $phpcsFile->findNext(array(\T_SEMICOLON, \T_CLOSE_TAG), ($continue + 1), $caseCloser);
                $codeString    = '';
                for ($i = ($continue + 1); $i < $nextSemicolon; $i++) {
                    if (isset($this->acceptedLevelTokens[$tokens[$i]['code']]) === false) {
                        // Function call/variable or other token which make numeric level impossible to determine.
                        continue 2;
                    }

                    if (isset(Tokens::$emptyTokens[$tokens[$i]['code']]) === true) {
                        continue;
                    }

                    $codeString .= $tokens[$i]['content'];
                }

                $level = null;
                if ($codeString !== '') {
                    if (is_numeric($codeString)) {
                        $level = (int) $codeString;
                    } else {
                        // With the above logic, the string can only contain digits and operators, eval!
                        $level = eval("return ( $codeString );");
                    }
                }

                if (isset($level) === false || $level === 0) {
                    $level = 1;
                }

                // Examine which control structure is being targeted by the continue statement.
                if (isset($tokens[$continue]['conditions']) === false) {
                    continue;
                }

                $conditions = array_reverse($tokens[$continue]['conditions'], true);
                // PHPCS adds more structures to the conditions array than we want to take into
                // consideration, so clean up the array.
                foreach ($conditions as $tokenPtr => $tokenCode) {
                    if (isset($this->loopStructures[$tokenCode]) === false) {
                        unset($conditions[$tokenPtr]);
                    }
                }

                $targetCondition = \array_slice($conditions, ($level - 1), 1, true);
                if (empty($targetCondition)) {
                    continue;
                }

                $conditionToken = key($targetCondition);
                if ($conditionToken === $stackPtr) {
                    $phpcsFile->addWarning(
                        "Targeting a 'switch' control structure with a 'continue' statement is strongly discouraged and will throw a warning as of PHP 7.3.",
                        $continue,
                        'Found'
                    );
                }

            } while ($continue < $caseCloser);

        } while ($caseDefault < $switchCloser);
    }
1183802
public function process(File $phpcsFile, $stackPtr)
    {
        if ($this->supportsAbove('5.4') === false) {
            return;
        }

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

        foreach ($parameters as $param) {
            if (isset($this->superglobals[$param['name']]) === true) {
                $error     = 'Parameter shadowing super global (%s) causes fatal error since PHP 5.4';
                $errorCode = $this->stringToErrorCode(substr($param['name'], 1)) . 'Found';
                $data      = array($param['name']);

                $phpcsFile->addError($error, $param['token'], $errorCode, $data);
            }
        }
    }
1097223
public function process(File $phpcsFile, $stackPtr) {
		$utils = new Utils();

		$tokens = $phpcsFile->getTokens();

		// Array of dynamic queries methods	and vulnerable params
		// TODO https://drupal.org/node/310085 db_merge()
		$dynq = array(
			'condition' => 3,
			'where' => 1,
			'having' => 1,
			'havingCondition' => 3,
			'orderBy' => array(1,2),
			'groupBy' => 1,
			'addExpression' => 1,
			'join' => 3,
			'innerJoin' => 3,
			'leftJoin' => 3,
			'rightJoin' => 3,
			'expression' => array(1,2),
			'fields' => 1, //special case with sub array() in param #1
		);

		if (!array_key_exists($tokens[$stackPtr]['content'], $dynq)) {
			return;
		}
		$paramnumlist = $dynq[$tokens[$stackPtr]['content']];

		if (!is_array($paramnumlist)) {
			$paramnumlist = array($paramnumlist);
		}

		foreach ($paramnumlist as $paramnum) {
			$t = $utils::get_param_tokens($phpcsFile, $stackPtr, $paramnum);
			if (!$t) {
				// Param not found or empty
				return;
			}

			$closer = end($t)['stackPtr']+1;
			$s = $t[0]['stackPtr'] - 1;
			$warn = FALSE;
			$already = FALSE;
			$next = false;
			while ($s < $closer) {
				$s = $phpcsFile->findNext(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, $s + 1, $closer, true);
				if (!$s) {
					break;
				}
				if ($tokens[$stackPtr]['content'] == 'fields' && ($tokens[$s]['content'] == 'array' || $next)) {
					$next = $phpcsFile->findNext(T_DOUBLE_ARROW, $s + 1, $closer);
					if ($next) {
						$s = $phpcsFile->findPrevious(\PHP_CodeSniffer\Util\Tokens::$emptyTokens, $next - 1, null, true);
						if (is_numeric($paramnum)) {
							$paramnum .= ' with array key value';
						}
					} else {
						// End of Array or empty Array
						break;
					}
				}
				if ($utils::is_token_user_input($tokens[$s])) {
					$phpcsFile->addError('SQL injection found in ' . $tokens[$stackPtr]['content'] . " with param #$paramnum", $s, 'D7DynQueriesSQLi');
				} elseif ($tokens[$s]['code'] == T_DOUBLE_QUOTED_STRING || $tokens[$s]['code'] == T_VARIABLE) {
					$phpcsFile->addWarning('Potential SQL injection with direct variable usage in ' . $tokens[$stackPtr]['content'] . " with param #$paramnum", $s, 'D7DynQueriesDirectVar');
				} elseif ($tokens[$s]['code'] != T_CONSTANT_ENCAPSED_STRING && $tokens[$s]['code'] != T_LNUMBER) {
					$warn = TRUE;
				}
			}

			if ($warn && \PHP_CodeSniffer\Config::getConfigData('ParanoiaMode')) {
				$phpcsFile->addWarning('Potential SQL injection in ' . $tokens[$stackPtr]['content'] . " with param #$paramnum", $stackPtr, 'D7DynQueriesWarn');
			}
		}
	}
811575
protected function findCustomLicense(File $phpCsFile): ?string
    {
        $path = str_replace(getcwd(), '', $phpCsFile->getFilename());

        if (strpos($path, DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'spryker' . DIRECTORY_SEPARATOR . 'spryker' . DIRECTORY_SEPARATOR) === 0) {
            $pathArray = explode(DIRECTORY_SEPARATOR, substr($path, 8));
            array_shift($pathArray);
            array_shift($pathArray);
            array_shift($pathArray);

            $path = getcwd() . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR
                . 'spryker' . DIRECTORY_SEPARATOR . 'spryker' . DIRECTORY_SEPARATOR
                . 'Bundles' . DIRECTORY_SEPARATOR . array_shift($pathArray) . DIRECTORY_SEPARATOR;

            return $this->getLicense($path) ?: null;
        }
        if (strpos($path, DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR) === 0) {
            $pathArray = explode(DIRECTORY_SEPARATOR, substr($path, 8));
            array_shift($pathArray);

            $path = getcwd() . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . array_shift($pathArray) . DIRECTORY_SEPARATOR;

            return $this->getLicense($path) ?: null;
        }

        if (strpos($path, DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR) === 0) {
            $pathArray = explode(DIRECTORY_SEPARATOR, substr($path, 8));

            $path = getcwd() . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR
                . array_shift($pathArray) . DIRECTORY_SEPARATOR . array_shift($pathArray) . DIRECTORY_SEPARATOR;
        } else {
            $path = getcwd() . DIRECTORY_SEPARATOR;
        }

        return $this->getLicense($path) ?: null;
    }
1233398
protected function isBlacklistedFile(File $phpcsFile) {
		$file = $phpcsFile->getFilename();
		return strpos($file, DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR) !== false;
	}