/** * @param ConfigInterface $config * @param bool $isDryRun * * @return CacheManagerInterface */ private function createCacheManager(ConfigInterface $config, $isDryRun) { if ($config->usingCache() && (ToolInfo::isInstalledAsPhar() || ToolInfo::isInstalledByComposer())) { return new FileCacheManager(new FileHandler($config->getCacheFile()), new Signature(PHP_VERSION, ToolInfo::getVersion(), $config->usingLinter(), $config->getRules()), $isDryRun); } return new NullCacheManager(); }
/** * Resolve using cache. */ private function resolveUsingCache() { if (null !== $this->options['using-cache']) { $this->usingCache = 'yes' === $this->options['using-cache']; return; } $this->usingCache = $this->config->usingCache(); }
/** * 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; }
/** * 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; }