@param \PHP_CodeSniffer\Files\File $file
@param int $index First functional code after docblock

@return int|false
979737
protected function _findDocBlockCloseTagIndex(File $file, $index) {
		$prevCode = $file->findPrevious(Tokens::$emptyTokens, $index - 1, null, true);
		if (!$prevCode) {
			return false;
		}

		return $file->findPrevious(T_DOC_COMMENT_CLOSE_TAG, $index - 1, $prevCode);
	}
232039
protected function file(array &$files, $type, $index)
    {
        if (is_array($files[$type]))
        {
            return $files[$type][$index];
        }

        return $files[$type];
    }
1270748
public function storeToIndex($file, $content)
    {
        $tags = '';
        SearchHelper::makeTags($tags, array('file'));

        // get data from FAL
        if ($file instanceof \TYPO3\CMS\Core\Resource\File) {
            $metadata = $file->_getMetaData();
            $orig_uid = $file->getUid();
        } else {
            $metadata = false;
            $orig_uid = 0;
        }

        $indexRecordValues = array(
            'storagepid' => $this->indexerConfig['storagepid'],
            'title' => $this->fileInfo->getName(),
            'type' => 'file:' . $this->fileInfo->getExtension(),
            'targetpid' => 1,
            'tags' => $tags,
            'params' => '',
            'abstract' => '',
            'language_uid' => -1,
            'starttime' => 0,
            'endtime' => 0,
            'fe_group' => 0,
            'debug' => false
        );

        $additionalFields = array(
            'sortdate' => $this->fileInfo->getModificationTime(),
            'orig_uid' => $orig_uid,
            'orig_pid' => 0,
            'directory' => $this->fileInfo->getRelativePath(),
            'hash' => $this->getUniqueHashForFile()
        );

        // add additional content if FAL is used
        if ($this->pObj->indexerConfig['fal_storage'] > 0) {
            // index meta data from FAL: title, description, alternative
            $additionalContent = '';

            if ($metadata['fe_groups']) {
                $indexRecordValues['fe_group'] = $metadata['fe_groups'];
            }

            if ($metadata['title']) {
                $additionalContent = $metadata['title'] . "\n";
            }

            if ($metadata['description']) {
                $indexRecordValues['abstract'] = $metadata['description'];
                $additionalContent .= $metadata['description'] . "\n";
            }

            if ($metadata['alternative']) {
                $additionalContent .= $metadata['alternative'] . "\n";
            }

            // remove previously indexed additional content elements (they can be identified by having trailing
            // linebreaks, the linebreaks in the file content have been removed)
            if (strpos($content, "\n")) {
                $content = substr($content, strrpos($content, "\n"));
            }

            // add additional content
            $content = $additionalContent . $content;

            // make tags from assigned categories
            $categories = SearchHelper::getCategories($metadata['uid'], 'sys_file_metadata');
            SearchHelper::makeTags($indexRecordValues['tags'], $categories['title_list']);

            // assign categories as generic tags (eg. "syscat123")
            SearchHelper::makeSystemCategoryTags(
                $indexRecordValues['tags'],
                $metadata['uid'],
                'sys_file_metadata'
            );
        }

        // hook for custom modifications of the indexed data, e. g. the tags
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyFileIndexEntry'])) {
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyFileIndexEntry'] as $_classRef) {
                $_procObj = &GeneralUtility::makeInstance($_classRef);
                $_procObj->modifyFileIndexEntry($file, $content, $additionalFields, $indexRecordValues, $this);
            }
        }

        // store record in index table
        $this->pObj->storeInIndex(
            $indexRecordValues['storagepid'],   // storage PID
            $indexRecordValues['title'],        // page title
            $indexRecordValues['type'],         // content type
            $indexRecordValues['targetpid'],    // target PID: where is the single view?
            $content,                           // indexed content, includes the title (linebreak after title)
            $indexRecordValues['tags'],         // tags
            $indexRecordValues['params'],       // typolink params for singleview
            $indexRecordValues['abstract'],     // abstract
            $indexRecordValues['language_uid'], // language uid
            $indexRecordValues['starttime'],    // starttime
            $indexRecordValues['endtime'],      // endtime
            $indexRecordValues['fe_group'],     // fe_group
            $indexRecordValues['debug'],        // debug only?
            $additionalFields                    // additional fields added by hooks
        );
    }
683533
protected function executeAction($index, $action)
    {
        list($key, $name, $args) = $action;

        $executedCount = $this->preExecuteAction($key, $index, $args);
        call_user_func_array([$this->rawLayoutBuilder, $name], $args);
        $executedCount++;
        $executedCount += $this->postExecuteAction($key, $index, $args);

        return $executedCount;
    }
288950
private function methodNeedsDocBlock(File $sniffedFile, $index)
    {
        $methodName = $sniffedFile->getDeclarationName($index);

        return !in_array($methodName, $this->methodNamesWithoutNecessaryDocBlock, true);
    }
718443
public function processFileMethods(array $methods, string $file)
    {
        foreach ($methods as $name => $method) {
            if (is_null($method['docblock'])) {
                $this->errors[] = [
                    'type' => 'method',
                    'file' => $file,
                    'class' => $name,
                    'method' => $name,
                    'line' => $method['line'],
                ];
            }
        }
    }
154636
protected function getTypeFromTag(File $file, $tagIndex)
    {
        $content = $file->getTokens()[($tagIndex + 2)]['content'];
        $parts   = explode(' ', $content, 2);
        $type    = $parts[0];
        return $type;
    }
472858
private function hasIndex($index)
    {
        return is_string($index) ? $this->hasName($index) : $this->hasPosition($index);
    }
441174
public static function validIndex( $index, $value )
    {
        if ( is_array( $value ) )
        {
            return ( count( $value ) > $index && $index >= 0 );
        }
        elseif ( is_string( $value ) )
        {
            return ( strlen( $value ) > $index && $index >= 0 );
        }

        return FALSE;
    }
795491
public final function resourceCheck(File $file) {
        if ($this->resourcePathMatch($file)) {
            if (is_null($this->getParentProject()->getResourceByFile($file)) && !is_null($resource = $this->resourceFactory($file))) {
                $this->getParentProject()->registerResource($resource);
            }
            return TRUE;
        } else {
            return FALSE;
        }
    }
491546
protected function assertValidDocBlock(File $phpCsFile, int $methodIndex): void
    {
        $docBlockEndIndex = $this->findRelatedDocBlock($phpCsFile, $methodIndex);
        if (!$docBlockEndIndex) {
            // Let another sniff take care of this
            return;
        }

        $tokens = $phpCsFile->getTokens();

        $docBlockStartIndex = $tokens[$docBlockEndIndex]['comment_opener'];

        for ($i = $docBlockStartIndex + 1; $i < $docBlockEndIndex; $i++) {
            if ($tokens[$i]['type'] !== 'T_DOC_COMMENT_TAG') {
                continue;
            }
            if (!in_array($tokens[$i]['content'], ['@param', '@return'], true)) {
                continue;
            }

            $classNameIndex = $i + 2;

            if ($tokens[$classNameIndex]['type'] !== 'T_DOC_COMMENT_STRING') {
                continue;
            }

            $content = $tokens[$classNameIndex]['content'];

            $spacePos = strpos($content, ' ');
            if ($spacePos) {
                $content = substr($content, 0, $spacePos);
            }
            if (substr($content, 0, 8) !== '\Spryker') {
                continue;
            }
            if (substr($content, -9) === 'Interface') {
                continue;
            }
            $pieces = explode('\\', $content);
            $lastPiece = array_pop($pieces);

            if (!$this->isRelevant($lastPiece)) {
                continue;
            }

            $error = 'Bridges should be annotated with interfaces only.';
            $phpCsFile->addError($error, $classNameIndex, 'WrongAnnotation');
        }
    }
381600
protected function checkFirstAnnotationTag(File $phpCsFile, int $docBlockStartIndex, int $docBlockEndIndex): void
    {
        $tokens = $phpCsFile->getTokens();

        $nextIndex = $phpCsFile->findNext(T_DOC_COMMENT_TAG, $docBlockStartIndex + 1, $docBlockEndIndex);
        if (!$nextIndex) {
            return;
        }

        $prevIndex = $phpCsFile->findPrevious(T_DOC_COMMENT_STRING, $nextIndex - 1, $docBlockStartIndex + 1);
        if (!$prevIndex) {
            $this->checkBeginningOfDocBlock($phpCsFile, $docBlockStartIndex, $nextIndex);
            return;
        }

        $diff = $tokens[$nextIndex]['line'] - $tokens[$prevIndex]['line'];
        if ($diff === 2) {
            return;
        }

        $fix = $phpCsFile->addFixableError('Expected 1 extra new line before tags, got ' . ($diff - 1), $nextIndex, 'ExtraLineMissing');
        if (!$fix) {
            return;
        }

        if ($diff > 2) {
            $phpCsFile->fixer->beginChangeset();

            for ($i = $prevIndex; $i < $nextIndex; $i++) {
                if ($tokens[$i]['line'] <= $tokens[$prevIndex]['line'] + 1 || $tokens[$i]['line'] >= $tokens[$nextIndex]['line']) {
                    continue;
                }
                $phpCsFile->fixer->replaceToken($i, '');
            }

            $phpCsFile->fixer->endChangeset();

            return;
        }

        $i = $nextIndex;
        while ($tokens[$i]['line'] === $tokens[$nextIndex]['line']) {
            $i--;
        }

        $phpCsFile->fixer->beginChangeset();

        $indentation = $this->getIndentationWhitespace($phpCsFile, $docBlockEndIndex);
        $phpCsFile->fixer->addContentBefore($i, $indentation . '*');
        $phpCsFile->fixer->addNewlineBefore($i);

        $phpCsFile->fixer->endChangeset();
    }
1158869
public static function getFilePath($cwd, array $index)
    {
        $path = self::getRequestPath();

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

        $file = $cwd.$path;

        if (is_file($file)) {
            return $file;
        }

        if (empty($index)) {
            return false;
        }

        foreach ($index as $ext) {
            $f = rtrim($file, '/').'/index.'.$ext;

            if (is_file($f)) {
                return $f;
            }
        }

        return false;
    }
352271
public function process(File $sniffedFile, $index)
    {
        if ($this->methodNeedsDocBlock($sniffedFile, $index) && !$this->hasMethodDocBlock($sniffedFile, $index))
        {
            $this->addWarning($sniffedFile, $index, 'Methods must have a docblock.');
        }
    }
1174424
public function hasMethodMetadata($method, $index)
    {
        return isset($this->methodMetadata[$method], $this->methodMetadata[$method][$index]);
    }
35224
protected function numberOfLineFeedsBetweenDocBlockAndDeclaration(File $sniffedFile, $indexOfFunctionToken)
    {
        $indexOfClosingDocBlock = $sniffedFile->findPrevious([T_DOC_COMMENT_CLOSE_TAG], $indexOfFunctionToken);
        if ($indexOfClosingDocBlock === false)
        {
            return false;
        }

        $numberOfLineFeeds = 0;
        for ($i = $indexOfClosingDocBlock; $i < $indexOfFunctionToken; $i++)
        {
            if ($this->isLinefeedToken($sniffedFile, $i))
            {
                $numberOfLineFeeds++;
            }
        }

        return $numberOfLineFeeds;
    }
484976
protected function wordShouldBeUppercase($index, $word)
    {
        return
            (
                $this->isFirstWordOfSentence($index) ||
                $this->isLastWord($word) ||
                !$this->isIgnoredWord($word)
            ) &&
            (
                !$this->hasUppercaseLetter($word)
            );
    }