PhpCsFixer\Console\ConfigurationResolver::resolveFinder PHP Méthode

resolveFinder() private méthode

Apply path on config instance.
private resolveFinder ( )
    private function resolveFinder()
    {
        if ($this->isStdIn()) {
            return new \ArrayIterator(array(new StdinFileInfo()));
        }
        $modes = array(self::PATH_MODE_OVERRIDE, self::PATH_MODE_INTERSECTION);
        if (!in_array($this->options['path-mode'], $modes, true)) {
            throw new InvalidConfigurationException(sprintf('The path-mode "%s" is not defined, supported are %s.', $this->options['path-mode'], implode(', ', $modes)));
        }
        $isIntersectionPathMode = self::PATH_MODE_INTERSECTION === $this->options['path-mode'];
        $paths = array_filter(array_map(function ($path) {
            return realpath($path);
        }, $this->getPath()));
        if (!count($paths)) {
            if ($isIntersectionPathMode) {
                return new \ArrayIterator(array());
            }
            return $this->iterableToTraversable($this->getConfig()->getFinder());
        }
        $pathsByType = array('file' => array(), 'dir' => array());
        foreach ($paths as $path) {
            if (is_file($path)) {
                $pathsByType['file'][] = $path;
            } else {
                $pathsByType['dir'][] = $path . DIRECTORY_SEPARATOR;
            }
        }
        $nestedFinder = null;
        $currentFinder = $this->iterableToTraversable($this->getConfig()->getFinder());
        try {
            $nestedFinder = $currentFinder instanceof \IteratorAggregate ? $currentFinder->getIterator() : $currentFinder;
        } catch (\Exception $e) {
        }
        if ($isIntersectionPathMode) {
            if (null === $nestedFinder) {
                throw new InvalidConfigurationException('Cannot create intersection with not-fully defined Finder in configuration file.');
            }
            return new \CallbackFilterIterator($nestedFinder, function (\SplFileInfo $current) use($pathsByType) {
                $currentRealPath = $current->getRealPath();
                if (in_array($currentRealPath, $pathsByType['file'], true)) {
                    return true;
                }
                foreach ($pathsByType['dir'] as $path) {
                    if (0 === strpos($currentRealPath, $path)) {
                        return true;
                    }
                }
                return false;
            });
        }
        if ($currentFinder instanceof SymfonyFinder && null === $nestedFinder) {
            // finder from configuration Symfony finder and it is not fully defined, we may fulfill it
            return $currentFinder->in($pathsByType['dir'])->append($pathsByType['file']);
        }
        return Finder::create()->in($pathsByType['dir'])->append($pathsByType['file']);
    }