Process multiple paths.

@param  string|string[] $paths One or many paths to scan.
@throws InvalidArgumentException If the paths are invalid.
@return string[]
550084
public function processMultiplePaths($paths)
    {
        $paths = $this->parseAsArray($paths);
        $paths = array_map([ $this, 'filterPath' ], $paths);
        $paths = array_filter($paths, [ $this, 'pathExists' ]);

        if ($paths === false) {
            throw new InvalidArgumentException('Received invalid paths.');
        }

        if (empty($paths)) {
            throw new InvalidArgumentException('Received empty paths.');
        }

        return $paths;
    }
1311988
public function setPaths(array $paths)
    {
        foreach ($paths as $value) {
            $this->ensureString(
                $value,
                'All the elements from array must be strings'
            );
        }

        $this->paths = $paths;

        return $this;
    }
299561
public function filterPrefix(array $arguments)
    {
        if (empty($arguments)) {
            throw new InvalidArgumentException('At least one argument needed');
        }

        $path = array_shift($arguments);

        if ( ! is_string($path)) {
            throw new InvalidArgumentException('First argument should be a string');
        }

        list($prefix, $path) = $this->getPrefixAndPath($path);
        array_unshift($arguments, $path);

        return [$prefix, $arguments];
    }
602458
public function _normalizePaths($paths = [])
    {
        $routePaths = [];

        if ($paths === null) {
            return ['controller' => 'index', 'action' => 'index'];
        } elseif (is_string($paths)) {
            if (($pos = strpos($paths, '::')) !== false) {
                $routePaths['controller'] = substr($paths, 0, $pos);
                $routePaths['action'] = substr($paths, $pos + 2);
            } else {
                $routePaths['controller'] = $paths;
                $routePaths['action'] = 'index';
            }
        } elseif (is_array($paths)) {
            if (isset($paths['area'])) {
                $routePaths['area'] = $paths['area'];
            }

            if (isset($paths['controller'])) {
                $routePaths['controller'] = $paths['controller'];
            } elseif (isset($paths[0])) {
                $routePaths['controller'] = $paths[0];
            } else {
                $routePaths['controller'] = 'index';
            }

            if (isset($paths['action'])) {
                $routePaths['action'] = $paths['action'];
            } elseif (isset($paths[1])) {
                $routePaths['action'] = $paths[1];
            } else {
                $routePaths['action'] = 'index';
            }

            $params = [];
            /** @noinspection ForeachSourceInspection */
            foreach ($paths as $k => $v) {
                if (is_string($k) && !in_array($k, ['area', 'controller', 'action'], true)) {
                    $params[$k] = $v;
                }
            }

            if ($params) {
                $routePaths['params'] = $params;
            }
        }

        if (isset($routePaths['controller']) && strpos($routePaths['controller'], '\\') !== false) {
            $controller = strtr($routePaths['controller'], '\\', '/');

            if (substr_count($controller, '/') === 2) {
                $routePaths['controller'] = basename($controller, 'Controller');
            } elseif (preg_match('#(?:/Controllers/([^/]+)/(\w+)Controller)|(?:/Areas/([^/]+)/Controllers/(\w+)Controller)$#', $controller, $match)) {
                if (isset($match[3])) {
                    $routePaths['area'] = $match[3];
                    $routePaths['controller'] = $match[4];
                } else {
                    $routePaths['area'] = $match[1];
                    $routePaths['controller'] = $match[2];
                }
            } else {
                $routePaths['controller'] = basename($controller, 'Controller');
            }
        }

        return $routePaths;
    }
698987
private function hydrateList($paths)
    {
        $files = array_filter(array_map(function ($path) {
            try {
                return $this->matcher->getFile($path);
            } catch (FileNotFoundException $e) {
                // Guess it doesn't exist anymore or we can't find it, remove from list.
                return null;
            }
        }, (array) $paths));

        $files = array_slice($files, 0, self::MAX_ITEMS);

        return $files;
    }
1115682
public function addPaths($paths)
    {
        $paths = is_array($paths) ? $paths : [$paths];

        foreach ($paths as $key => $path) {
            $key = is_int($key) ? null : $key;

            $this->addPath($path, $key);
        }

        return $this;
    }
828905
protected function streamlineFilePaths(array $paths): array
    {
        $paths = \array_map(function ($url) {
            if (!GeneralUtility::isValidUrl($url) && ':' !== $url[0]) {
                $url = GeneralUtility::locationHeaderUrl($url);
            }

            return $url;
        }, $paths);

        $paths = \array_filter($paths, function ($path) {
            return GeneralUtility::isOnCurrentHost($path) && ':' !== $path[0];
        });

        $paths = \array_map(function ($url) {
            return '/' . \ltrim(\str_replace(GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST'), '', $url), '/');
        }, $paths);

        return $paths;
    }
246514
protected function retrieveAllFiles(array $paths)
    {
        $files = [];

        foreach ($paths as $path) {
            $newFiles = [];

            try {
                $newFiles = $this->retrieveFiles($path);
            } catch (FileSystemException $e) {
                continue;
            } finally {
                $files = array_merge($files, $newFiles);
            }
        }

        return $files;
    }
1285713
public static function mergePreflightDir(array $paths): array
    {
        if (defined('PREFLIGHT_DIR')) {
            $dir = constant('PREFLIGHT_DIR');
            $path = trailingslashit($dir) . 'preflight.toml';

            $paths[] = normalize_path($path);
        }

        return $paths;
    }
437027
public function addPaths(array $paths)
    {
        $this->currentCollectorData = $this->filePathCollector->collect();

        foreach ($paths as $path) {
            $this->addPath($path);
        }
    }
957775
private function prefixPaths (array $paths, string $prefix) : array
    {
        $result = [];

        foreach ($paths as $namespace => $path)
        {
            $result[$namespace] = "{$prefix}/" . trim($path, "/");
        }

        return $result;
    }
1179098
public function path(string $path) : PathList
    {
        if (!file_exists($path)) {
            throw new \InvalidArgumentException(
                'Arg path doesn\'t exist, path[' . $path . '].'
            );
        }
        if (!is_dir($path)) {
            throw new \InvalidArgumentException(
                'Arg path is not a directory, path[' . $path . '].'
            );
        }
        $this->path = $path;
        return $this;
    }
462426
private static function processReindexPath($path)
    {
        if (is_string($path) || is_integer($path)) {
            // Single level path - one element only
            $path = array(array($path));
        } elseif (is_array($path) && !empty($path) && !is_array($path[0])) {
            // Single level path - multiple elements
            // Check each path element is either a string or an integer
            foreach ($path as $key) {
                if (!(is_string($key) || is_integer($key))) {
                    throw new InvalidArgumentException('Invalid reindex path.');
                }
            }

            $path = array($path);
        } elseif (is_array($path) && !empty($path) && is_array($path[0])) {
            // Multilevel path
            // Check each path element is an array (a sub-path)
            foreach ($path as $subpath) {
                if (!is_array($subpath) || empty($subpath)) {
                    throw new InvalidArgumentException('Invalid reindex path.');
                }

                // Check each sub-path element is a valid array key (either a string or an integer)
                foreach ($subpath as $key) {
                    if (!(is_string($key) || is_integer($key))) {
                        throw new InvalidArgumentException('Invalid reindex path.');
                    }
                }
            }
        } else {
            throw new InvalidArgumentException('Invalid reindex path.');
        }

        return $path;
    }
512739
private function realPath($path)
    {
        $result = realpath($path);
        if ($result === false) {
            throw new \InvalidArgumentException(sprintf('Failed to run realpath(\'%s\')', $path));
        }

        return $result;
    }
91131
public static function findDirs(string $path): array
    {
        $result = [];

        try {
            static::validatePath($path);
            $path = new DirectoryIterator($path);
        } catch (InvalidArgumentException $e) {
            return $result;
        } catch (UnexpectedValueException $e) {
            return $result;
        }

        foreach ($path as $dir) {
            if ($dir->isDot()) {
                continue;
            }
            if (!$dir->isDir()) {
                continue;
            }
            $result[] = $dir->getFilename();
        }
        asort($result);

        return $result;
    }
994657
protected function fixRelativePaths(array $paths)
    {
        $base = dirname($this->path);
        $base = ($base === '.') ? '' : "{$base}/";

        array_walk_recursive(
            $paths,
            function (&$path) use ($base) {
                $path = "{$base}{$path}";
            }
        );
        return $paths;
    }
1204076
protected function realPath(array $paths, $basePath = '')
    {
        return collect($paths)->map(function ($path) use ($basePath) {
            return realpath($basePath.$path);
        })->filter(function ($path) {
            return $path;
        });
    }