Similar to findFirstFileMatching but assumes /next/ in segment and
matches after skipping the everything up to and including the namespace
before the /next/ key segment.

@return array [ $targetfile, $targetns, $target ]
763571
function findFirstFileMatchingAfterNext($ns, $name, $filename) {
		$nextPtr = \strrpos($ns, '\\next\\');

		// due to the way the syntax works, the namespace before the keyword
		// next is implied from the file namespace so it's always a complete
		// namespace rather then a partial one
		$skipNamespace = substr($ns, 0, $nextPtr + 1);

		$targetNs = substr($ns, $nextPtr + 6); // strlen('\\next\\') = 6

		$skipped = false;
		foreach ($this->state['modules'] as $module) {

			if ( ! $skipped) {
				if ($module['namespace'] == $skipNamespace) {
					$skipped = true;
				}

				continue;
			}

			if ( ! $module['enabled']) {
				continue;
			}

			if (\strripos($module['namespace'], $targetNs) !== false) {
				$targetfile = $module['path'].'/src/'.$filename.'.php';
				if ($this->file_exists($targetfile)) {
					$target = $module['namespace'].$name;
					return [ $targetfile, $module['namespace'], $target ];
				}
			}
		}

		return null; // failed to match anything
	}
295370
public function getMatchingEntries()
    {
        $limits = $this->getRange();
        $current = $limits['begin'];
        $entries[] = $this->long2ip($current);
        $entries = array();

        while ($current != $limits['end']) {
            $current = $this->IpLongAdd($current, 1);
            $entries[] = $this->long2ip($current);
        }

        return $entries;
    }
734562
public function findAll()
    {
        return new CallbackMapIterator(
            new FilesystemIterator(
                $this->getSavePath(),
                FilesystemIterator::SKIP_DOTS |
                FilesystemIterator::KEY_AS_FILENAME |
                FilesystemIterator::CURRENT_AS_FILEINFO
            ),
            function ( SplFileInfo $info ) {
                return $info->getFilename();
            }
        );
    }
145620
protected function getIncomingFiles()
    {
        $fh = $this->app->make('helper/validation/file');
        $nh = $this->app->make('helper/number');
        $incoming = $this->app->make(Incoming::class);
        $files = $incoming->getIncomingFilesystem()->listContents($incoming->getIncomingPath());
        foreach (array_keys($files) as $index) {
            $files[$index]['allowed'] = $fh->extension($files[$index]['basename']);
            $files[$index]['thumbnail'] = FileTypeList::getType($files[$index]['extension'])->getThumbnail();
            $files[$index]['displaySize'] = $nh->formatSize($files[$index]['size'], 'KB');
        }

        return $files;
    }
1358580
public function getNext()
    {
        if ($this->currentToken !== null || strlen($this->currentInput) > 0) {
            $this->parseNextToken();

            return $this->currentToken;
        }

        return null;
    }
134877
private function findFilesInDiffToTarget(string $targetBranch) : GitChangeSet
    {
        $mergeBase = $this->processRunner->runAsProcess('git', 'merge-base', 'HEAD', $targetBranch);

        $rawDiffUnfilteredString = $this->processRunner->runAsProcess(
            'git',
            'diff',
            '--name-only',
            '--diff-filter=d',
            $mergeBase
        );

        $rawDiffUnfiltered = explode("\n", trim($rawDiffUnfilteredString));

        $result = $this->gitChangeSetFactory->build($rawDiffUnfiltered, $mergeBase);

        return $result;
    }
229974
protected function NextItem()
	{
		while (true)
		{
			if ( ! $this->accept )
			{
				if ( ! $this->MoveNextIter() )
				{
					return null;
				}
				$this->first = true;
				if ( $this->matchSelf && $this->TestItem() )
				{
					$this->sequentialPosition++;
					return $this->curr;
				}
			}
			if ( $this->first)
			{
				$this->accept = $this->MoveToFirst( $this->curr );
				$this->first = false;
			}
			else
			{
				$this->accept = $this->MoveToNext( $this->curr );
			}
			if ( $this->accept )
			{
				if ( $this->TestItem() )
				{
					$this->sequentialPosition++;
					return $this->curr;
				}
			}
		}
	}
482567
public function next()
	{
		if( is_resource( $this->filePointer ) )
		{
			if( !feof( $this->filePointer ) )
			{
				$data = fgetcsv(
					$this->filePointer,
					self::$maxRowSize,
					$this->delimiter,
					$this->enclosure
				);
				//A blank line in a CSV file will be returned as an array comprising a single null field, and will not be treated as an error. 
				if( count( $data ) == 1 && ( !isset( $data[0] ) || trim( $data[0] ) == '') ) 
					return $this->next();				
				if( $data )
				{
					$this->currentElement	= $data;	
					$this->rowCounter++;
					return TRUE;
				}
			}
		}
		return FALSE;
	}
614202
private function get_target_section() {

        if (!$this->fixeddataset) {
            $key = rand(1, self::$paramsections[$this->size]);
        } else {
            // Using section 1.
            $key = 1;
        }

        return $key;
    }
1204749
protected function getMap()
    {
        $fileSets = $this->getFilesets();

        // No filesets set
        // We're assuming single file / directory
        if (empty($fileSets)) {
            return $this->getTarget();
        }

        $targets = [];

        foreach ($fileSets as $fs) {
            if (!($fs instanceof FileSet)) {
                continue;
            }

            // We need a directory to store the links
            if (!is_dir($this->getLink())) {
                throw new BuildException('Link must be an existing directory when using fileset');
            }

            $fromDir = $fs->getDir($this->getProject())->getAbsolutePath();

            if (!is_dir($fromDir)) {
                $this->log('Directory doesn\'t exist: ' . $fromDir, Project::MSG_WARN);
                continue;
            }

            $fsTargets = [];

            $ds = $fs->getDirectoryScanner($this->getProject());

            $fsTargets = array_merge(
                $fsTargets,
                $ds->getIncludedDirectories(),
                $ds->getIncludedFiles()
            );

            // Add each target to the map
            foreach ($fsTargets as $target) {
                if (!empty($target)) {
                    $targets[$target] = $fromDir . DIRECTORY_SEPARATOR . $target;
                }
            }
        }

        return $targets;
    }
602964
public function getNFirst($n)
    {
        $it = new \ArrayIterator();
        $j = 0;
        foreach ($this as $file) {
            if ($j == $n) {
                break;
            }
            $j++;
            $it->append($file);
        }

        $finder = new static();
        $finder->append($it);

        return $finder;
    }
741328
public function find(): self
    {
        $preparedPaths = \array_unique(
            \array_merge(
                $this->getPreparedPaths((array) $this->paths['psr0']),
                $this->getPreparedPaths((array) $this->paths['psr4']),
                $this->getPreparedPaths((array) $this->paths['classmap'])
            ),
            \SORT_STRING
        );

        $finder = Finder::create()
            ->files()
            ->in($preparedPaths)
            ->exclude($this->excludes)
            ->name('*.php')
            ->sortByName();

        if ($this->filter !== null) {
            $finder->filter($this->filter);
        }

        /** @var \SplFileInfo $file */
        foreach ($finder as $file) {
            $realPath  = (string) $file->getRealPath();

            $namespace = null;
            $tokens    = \token_get_all((string) \file_get_contents($realPath));

            foreach ($tokens as $key => $token) {
                if (\is_array($token)) {
                    if ($token[0] === \T_NAMESPACE) {
                        $namespace = self::getNamespace($key + 2, $tokens);
                    } elseif ($token[0] === \T_INTERFACE) {
                        $name = self::getName($key + 2, $tokens);

                        if ($name === null) {
                            continue 2;
                        }

                        $this->interfaces[\ltrim($namespace . '\\' . $name, '\\')] = $realPath;
                    } elseif ($token[0] === \T_TRAIT) {
                        $name = self::getName($key + 2, $tokens);

                        if ($name === null) {
                            continue 2;
                        }

                        $this->traits[\ltrim($namespace . '\\' . $name, '\\')] = $realPath;
                    } elseif ($token[0] === \T_ABSTRACT) {
                        $name = self::getName($key + 4, $tokens);

                        if ($name === null) {
                            continue 2;
                        }

                        $this->abstractClasses[\ltrim($namespace . '\\' . $name, '\\')] = $realPath;

                        continue 2;
                    } elseif ($token[0] === \T_CLASS) {
                        $name = self::getName($key + 2, $tokens);

                        if ($name === null) {
                            continue 2;
                        }

                        $this->classes[\ltrim($namespace . '\\' . $name, '\\')] = $realPath;
                    }
                }
            }

            unset($tokens);
            // PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
            \gc_mem_caches();
        }

        return $this;
    }
464186
protected function doFileSearch()
    {
        if (empty($this->searchLocations)) {
            throw new \RuntimeException(
                'No search locations have been defined.'
            );
        }

        return (new Finder())
            ->name($this->searchPattern)
            ->in($this->searchLocations)
            ->depth($this->searchDepth)
            ->files();
    }
194399
public function find_all() {
        $this->ensure_path_exists();
        $files = glob($this->glob_keys_pattern(), GLOB_MARK | GLOB_NOSORT);
        $return = array();
        if ($files === false) {
            return $return;
        }
        foreach ($files as $file) {
            $return[] = substr(basename($file), 0, -6);
        }
        return $return;
    }
397544
private function getMappings(): Iterator
    {
        if ($this->mappings === null) {
            $filePaths = [];

            foreach ($this->mappingFilePaths as $mappingFilePath) {
                $newFilePaths = iterator_to_array(new SplFileObject($mappingFilePath, 'r'));
                $filePaths    = array_merge($filePaths, $newFilePaths);
            }

            $this->mappings = new ArrayIterator(
                array_map(
                    function (string $mapping) : FileMappingInterface {
                        return new UnixFileMapping(
                            $this->sourceDirectory,
                            $this->targetDirectory,
                            trim($mapping)
                        );
                    },
                    // Filter out empty lines.
                    array_filter(
                        $filePaths
                    )
                )
            );
        }

        return $this->mappings;
    }
172642
public function getTargetList() {
		$targetFieldsList = $this->_modelSearch->getTargetFieldsList();
		$targetData = $this->_controller->request->query('target');
		if (empty($targetData)) {
			$target = $targetFieldsList;
		} else {
			$target = array_intersect((array)$targetData, $targetFieldsList);
			if (empty($target)) {
				throw new InternalErrorException(__d('cake_search_info', 'Invalid fields for filter of search scope.'));
			}
			$target = array_values($target);
		}
		if ($this->_modelSearch->getAnyPartFlag($targetData)) {
			$target[] = CAKE_SEARCH_INFO_TARGET_FIELD_ANY_PART;
		}

		return $target;
	}
40747
public function getNextStrpos($patterns)
    {
        $next = -1;
        $match = null;
        foreach ($patterns as $p) {
            $index = strpos($this->src, $p, $this->index);
            if ($index === false) {
                continue;
            }
            if ($next === -1 || $index < $next) {
                $next = $index;
                $match = $p;
            }
        }
        return array($next, $match);
    }