{@inheritdoc}

@param File $phpcsFile
@param int  $stackPointer

@return void
320807
public function process(File $phpcsFile, $stackPointer)
    {
        ini_set('display_errors', 1);
        error_reporting(E_ALL);
        $tokens  = $phpcsFile->getTokens();
        $content = $tokens[$stackPointer]['content'];
        if ($tokens[$stackPointer]['type'] !== 'T_STRING' || stripos($content, 'in_array') === false)
        {
            return;
        }

        $end                 = $tokens[$stackPointer + 1]['parenthesis_closer'];
        $length              = $end - $stackPointer + 1;
        $inArrayContext      = $phpcsFile->getTokensAsString($stackPointer, $length);
        $inArrayContextMatch = [];
        preg_match('/in_array\\(\\s*.+,\\s*.+,\\s*true\\s*\\)/sim', $inArrayContext, $inArrayContextMatch);
        if (empty($inArrayContextMatch))
        {
            $type  = 'Production.StrictInArray.non-strictArray';
            $data  = [$inArrayContext];
            $error = 'in_array needs to have the third parameter set to true.';
            $phpcsFile->addWarning($error, $stackPointer, $type, $data);
        }
    }
887752
public function process(File $phpcsFile, $stackPtr)
    {
        if ($this->supportsAbove('7.3') === false) {
            return;
        }

        $funcName = $phpcsFile->getDeclarationName($stackPtr);

        if (strtolower($funcName) !== 'assert') {
            return;
        }

        if ($phpcsFile->hasCondition($stackPtr, $this->scopes) === true) {
            return;
        }

        if ($this->determineNamespace($phpcsFile, $stackPtr) === '') {
            // Not a namespaced function declaration. Parse error, but not our concern.
            return;
        }

        $phpcsFile->addWarning('Declaring a free-standing function called assert() is deprecated since PHP 7.3.', $stackPtr, 'Found');
    }
1041172
protected function isSprykerFacadeApiClass(File $phpCsFile, int $stackPointer): bool
    {
        if (!$this->hasNamespace($phpCsFile, $stackPointer)) {
            return false;
        }

        $namespace = $this->getNamespace($phpCsFile, $stackPointer);
        $name = $this->findClassOrInterfaceName($phpCsFile, $stackPointer);
        if (!$name || $name === 'AbstractFacade') {
            return false;
        }

        if (preg_match('/^Spryker\\\\Zed\\\\(.*?)\\\\Business$/', $namespace) && preg_match('/^(.+?)(Facade|FacadeInterface)$/', $name)) {
            return true;
        }

        return false;
    }
881658
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens    = $phpcsFile->getTokens();
        $prevToken = $phpcsFile->findPrevious(
            Tokens::$emptyTokens,
            ($stackPtr - 1),
            null,
            true
        );

        $expectedBlankLineCount = 1;
        $leadingLinePtr         = $this->getLeadingLinePointer($phpcsFile, $stackPtr, $prevToken);
        $blankLineCount         = ($tokens[$leadingLinePtr]['line'] - ($tokens[$prevToken]['line'] + 1));

        if (isset($tokens[$prevToken]['scope_opener']) === true && $tokens[$prevToken]['scope_opener'] === $prevToken) {
            $expectedBlankLineCount = 0;
        }

        if ($blankLineCount !== $expectedBlankLineCount) {
            $error = 'Expected %s blank line before return statement; %s found';
            $data  = array(
                      $expectedBlankLineCount,
                      $blankLineCount,
                     );
            $phpcsFile->addError($error, $stackPtr, 'BlankLineBeforeReturn', $data);
        }
    }
447372
protected function getSnifferIsApplicable(File $phpCsFile, int $stackPointer): bool
    {
        if ($this->isController($phpCsFile, $stackPointer)) {
            return true;
        }

        if ($this->isCollectionType($phpCsFile, $stackPointer)) {
            return true;
        }

        if ($this->isConsole($phpCsFile, $stackPointer)) {
            return true;
        }

        if ($this->isFacade($phpCsFile, $stackPointer)) {
            return true;
        }

        if ($this->isFactory($phpCsFile, $stackPointer)) {
            return true;
        }

        if ($this->isType($phpCsFile, $stackPointer)) {
            return true;
        }

        return false;
    }
1068627
public function process(File $phpcsFile, $stackPtr)
    {
        $functionName   = $phpcsFile->getDeclarationName($stackPtr);
        $functionNameLc = strtolower($functionName);

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

        if ($this->inClassScope($phpcsFile, $stackPtr, false) === false) {
            return;
        }

        $itemInfo = array(
            'name'   => $functionName,
            'nameLc' => $functionNameLc,
        );
        $this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
    }
43931
protected function addUseStatements(File $phpCsFile, int $stackPointer, array $missingUses): void
    {
        $useStatements = $this->parseUseStatements($phpCsFile, $stackPointer);
        foreach ($missingUses as $missingUse) {
            if (!in_array($missingUse, $useStatements)) {
                $this->addMissingUse($phpCsFile, $stackPointer, $missingUse);
            }
        }
    }
1114068
protected function checkInterface(File $phpCsFile, int $stackPointer): void
    {
        $facadeFile = str_replace('FacadeInterface.php', 'Facade.php', $phpCsFile->getFilename());

        $content = file_get_contents($facadeFile);
        preg_match_all('/public function (\w+)\b/', $content, $matches);
        $methods = $matches[1];
        asort($methods);

        $interfaceContent = file_get_contents($phpCsFile->getFilename());
        preg_match_all('/public function (\w+)\b/', $interfaceContent, $matches);
        $interfaceMethods = $matches[1];
        asort($interfaceMethods);

        if (array_values($interfaceMethods) === array_values($methods)) {
            return;
        }

        $missingInterfaceMethods = array_diff($methods, $interfaceMethods);
        $missingInterfaceImplementations = array_diff($interfaceMethods, $methods);

        if (count($missingInterfaceMethods) > 0) {
            $phpCsFile->addError(
                sprintf('Interface methods do not match facade methods: "%s" missing', implode(', ', $missingInterfaceMethods)),
                $stackPointer,
                'InterfaceMethodMissing'
            );
        }

        if (count($missingInterfaceImplementations) > 0) {
            $phpCsFile->addError(
                sprintf('Interface method has no implementation: "%s" missing', implode(', ', $missingInterfaceImplementations)),
                $stackPointer,
                'InterfaceImplementationMissing'
            );
        }
    }
787
protected function hasMethodAnnotation(File $phpCsFile, int $stackPointer): bool
    {
        $position = $phpCsFile->findPrevious(T_DOC_COMMENT_CLOSE_TAG, $stackPointer);
        $tokens = $phpCsFile->getTokens();

        while ($position !== false) {
            $position = $phpCsFile->findPrevious(T_DOC_COMMENT_TAG, $position);

            if ($position !== false) {
                if (strpos($tokens[$position + 2]['content'], $this->getMethodName() . '()') !== false) {
                    return true;
                }

                $position--;
            }
        }

        return false;
    }
314636
public function process(File $phpcsFile, $stackPtr)
    {
        // Should be removed, the requirement was previously also there, 5.3 just started throwing a warning about it.
        if ($this->supportsAbove('5.3') === false) {
            return;
        }

        $tokens = $phpcsFile->getTokens();

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

        $classScopeCloser = $tokens[$stackPtr]['scope_closer'];
        $functionPtr      = $stackPtr;

        // Find all the functions in this class or interface.
        while (($functionToken = $phpcsFile->findNext(\T_FUNCTION, $functionPtr, $classScopeCloser)) !== false) {
            /*
             * Get the scope closer for this function in order to know how
             * to advance to the next function.
             * If no body of function (e.g. for interfaces), there is
             * no closing curly brace; advance the pointer differently.
             */
            if (isset($tokens[$functionToken]['scope_closer'])) {
                $scopeCloser = $tokens[$functionToken]['scope_closer'];
            } else {
                $scopeCloser = ($functionToken + 1);
            }

            $methodName   = $phpcsFile->getDeclarationName($functionToken);
            $methodNameLc = strtolower($methodName);
            if (isset($this->magicMethods[$methodNameLc]) === false) {
                $functionPtr = $scopeCloser;
                continue;
            }

            $methodProperties = $phpcsFile->getMethodProperties($functionToken);
            $errorCodeBase    = $this->stringToErrorCode($methodNameLc);

            if (isset($this->magicMethods[$methodNameLc]['visibility']) && $this->magicMethods[$methodNameLc]['visibility'] !== $methodProperties['scope']) {
                $error     = 'Visibility for magic method %s must be %s. Found: %s';
                $errorCode = $errorCodeBase . 'MethodVisibility';
                $data      = array(
                    $methodName,
                    $this->magicMethods[$methodNameLc]['visibility'],
                    $methodProperties['scope'],
                );

                $phpcsFile->addError($error, $functionToken, $errorCode, $data);
            }

            if (isset($this->magicMethods[$methodNameLc]['static']) && $this->magicMethods[$methodNameLc]['static'] !== $methodProperties['is_static']) {
                $error     = 'Magic method %s cannot be defined as static.';
                $errorCode = $errorCodeBase . 'MethodStatic';
                $data      = array($methodName);

                if ($this->magicMethods[$methodNameLc]['static'] === true) {
                    $error     = 'Magic method %s must be defined as static.';
                    $errorCode = $errorCodeBase . 'MethodNonStatic';
                }

                $phpcsFile->addError($error, $functionToken, $errorCode, $data);
            }

            // Advance to next function.
            $functionPtr = $scopeCloser;
        }
    }
696007
protected function getClassMethod(File $phpCsFile, int $stackPointer): string
    {
        $className = $this->getClassName($phpCsFile);
        $methodName = $this->getMethodName($phpCsFile, $stackPointer);

        $classMethod = $className . '::' . $methodName;

        return $classMethod;
    }
110277
protected function isSprykerConstantsInterface(File $phpCsFile, int $stackPointer): bool
    {
        if (!$this->hasNamespace($phpCsFile, $stackPointer)) {
            return false;
        }

        $namespace = $this->getInterfaceNamespace($phpCsFile, $stackPointer);
        if (!preg_match('/^Spryker.*\\\\Shared\\\\/', $namespace)) {
            return false;
        }

        $name = $this->findClassOrInterfaceName($phpCsFile, $stackPointer);
        if (!$name || substr($name, -9) !== 'Constants') {
            return false;
        }

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

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

        $this->checkExistingDocBlock($phpCsFile, $docBlockEndIndex);
    }
1172221
protected function isOwnFileDocBlock(File $phpCsFile, int $stackPointer): bool
    {
        $fileDockBlockTokens = $this->getFileDocBlockTokens($phpCsFile, $stackPointer);

        $firstLineComment = $fileDockBlockTokens[static::FIRST_COMMENT_LINE_POSITION]['content'];

        if (strpos($firstLineComment, 'modified by Spryker Systems GmbH') !== false) {
            return false;
        }

        return true;
    }
1255356
protected function getSnifferIsApplicable(File $phpCsFile, int $stackPointer): bool
    {
        if ($this->isFacade($phpCsFile, $stackPointer)) {
            return true;
        }

        if ($this->isFactory($phpCsFile, $stackPointer)) {
            return true;
        }

        return false;
    }
903361
public function process(File $phpcsFile, $stackPointer)
    {
        $tokens       = $phpcsFile->getTokens();
        $currentToken = $tokens[$stackPointer];

        $closingParenthesisCandidate = $currentToken['parenthesis_closer'];
        $whitespaceCandidate         = $tokens[$closingParenthesisCandidate - 1];
        $linebreakCandidate          = $tokens[$closingParenthesisCandidate - 2];
        $commaCandidate              = $tokens[$closingParenthesisCandidate - 3];

        $hasClosingParenthesis = ($tokens[$closingParenthesisCandidate]['type'] === 'T_CLOSE_PARENTHESIS'
            && $whitespaceCandidate['type'] === 'T_WHITESPACE');

        $hasLinebreakBeforeClosingParenthesis = ($linebreakCandidate['type'] === 'T_WHITESPACE'
            && $linebreakCandidate['content'] === chr(10));

        $hasCommaAfterLastElement = $commaCandidate['type'] === 'T_COMMA';

        if ($hasClosingParenthesis && $hasLinebreakBeforeClosingParenthesis && !$hasCommaAfterLastElement)
        {
            $type  = 'Production.LastArrayElementComma.ArrayElementWithoutComma';
            $data  = $commaCandidate['content'];
            $error = 'Array element without comma: ' . $commaCandidate['line'];
            $phpcsFile->addWarning($error, $closingParenthesisCandidate - 3, $type, $data);
        }
    }
466634
protected function addFixableMissingDocBlock(File $phpCsFile, int $stackPointer): void
    {
        $fix = $phpCsFile->addFixableError('No file doc block', $stackPointer, 'FileDocBlockMissing');
        if ($fix) {
            $this->addFileDocBlock($phpCsFile, 0);
        }
    }