getFinder() public method

Returns files to scan.
public getFinder ( ) : iterable | Traversable | string[]
return iterable | Traversable | string[]
Exemplo n.º 1
0
 /**
  * Apply path on config instance.
  */
 private function resolveConfigPath()
 {
     if ($this->isStdIn) {
         $this->config->finder(new \ArrayIterator(array(new StdinFileInfo())));
         return;
     }
     $isIntersectionPathMode = self::PATH_MODE_INTERSECTION === $this->options['path-mode'];
     $paths = array_filter(array_map(function ($path) {
         return realpath($path);
     }, $this->path));
     if (empty($paths)) {
         if ($isIntersectionPathMode) {
             $this->config->finder(new \ArrayIterator(array()));
         }
         return;
     }
     $pathsByType = array('file' => array(), 'dir' => array());
     foreach ($paths as $path) {
         $isFile = is_file($path);
         if (is_file($path)) {
             $pathsByType['file'][] = $path;
         } else {
             $pathsByType['dir'][] = $path . DIRECTORY_SEPARATOR;
         }
     }
     $currentFinder = $this->config->getFinder();
     $nestedFinder = null;
     $iterator = null;
     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.');
         }
         $iterator = 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;
         });
     } elseif ($currentFinder instanceof SymfonyFinder && null === $nestedFinder) {
         // finder from configuration Symfony finder and it is not fully defined, we may fulfill it
         $iterator = $currentFinder->in($pathsByType['dir'])->append($pathsByType['file']);
     } else {
         $iterator = Finder::create()->in($pathsByType['dir'])->append($pathsByType['file']);
     }
     $this->config->finder($iterator);
 }
Exemplo n.º 2
0
 /**
  * Fixes all files for the given finder.
  *
  * @param ConfigInterface $config A ConfigInterface instance
  * @param bool            $dryRun Whether to simulate the changes or not
  * @param bool            $diff   Whether to provide diff
  *
  * @return array
  */
 public function fix(ConfigInterface $config, $dryRun = false, $diff = false)
 {
     $changed = array();
     $fixers = $config->getFixers();
     $this->stopwatch->openSection();
     $fileCacheManager = new FileCacheManager($config->usingCache(), $config->getCacheFile(), $config->getRules());
     foreach ($config->getFinder() as $file) {
         if ($file->isDir() || $file->isLink()) {
             continue;
         }
         $name = $this->getFileRelativePathname($file);
         $this->stopwatch->start($name);
         if ($fixInfo = $this->fixFile($file, $fixers, $dryRun, $diff, $fileCacheManager)) {
             $changed[$name] = $fixInfo;
         }
         $this->stopwatch->stop($name);
     }
     $this->stopwatch->stopSection('fixFile');
     return $changed;
 }
Exemplo n.º 3
0
 /**
  * Fixes all files for the given finder.
  *
  * @param ConfigInterface $config A ConfigInterface instance
  * @param bool            $dryRun Whether to simulate the changes or not
  * @param bool            $diff   Whether to provide diff
  *
  * @return array
  */
 public function fix(ConfigInterface $config, $dryRun = false, $diff = false)
 {
     $changed = array();
     $fixers = $config->getFixers();
     $this->stopwatch->openSection();
     $fileCacheManager = new FileCacheManager($config->usingCache(), $config->getCacheFile(), $config->getRules());
     $finder = $config->getFinder();
     $finderIterator = $finder instanceof \IteratorAggregate ? $finder->getIterator() : $finder;
     foreach (new UniqueFileIterator($finderIterator) as $file) {
         $name = $this->getFileRelativePathname($file);
         $this->stopwatch->start($name);
         if ($fixInfo = $this->fixFile($file, $fixers, $dryRun, $diff, $fileCacheManager)) {
             $changed[$name] = $fixInfo;
         }
         $this->stopwatch->stop($name);
     }
     $this->stopwatch->stopSection('fixFile');
     return $changed;
 }