Exemplo n.º 1
0
 /**
  * Fixes all files for the given finder.
  *
  * @param \Symfony\CS\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(CSConfigInterface $config, $dryRun = false, $diff = false)
 {
     $changed = array();
     $fixers = $config->getFixers();
     $this->stopwatch->openSection();
     $fileCacheManager = new FileCacheManager($config->usingCache(), $config->getCacheFile(), $config->getRules());
     $checkers = [];
     $messageCacheManager = null;
     if ($config instanceof ConfigInterface) {
         $checkers = $config->getCheckers();
         $messageCacheManager = new FileMessageCacheManager($config->usingCache(), $config->getCheckerCacheFile(), array_map('get_class', $config->getCheckers()));
     }
     /** @var \SplFileInfo $file */
     foreach ($config->getFinder() as $file) {
         if ($file->isDir() || $file->isLink()) {
             continue;
         }
         $this->stopwatch->start($this->getFileRelativePathname($file));
         $relativeFile = $this->getFileRelativePathname($file);
         if ($fixInfo = $this->fixFile($file, $fixers, $dryRun, $diff, $fileCacheManager, $checkers, $messageCacheManager)) {
             $changed[$relativeFile] = $fixInfo;
         } elseif ($messageCacheManager->hasMessage($this->getFileRelativePathname($file))) {
             $changed[$relativeFile] = array('checkMessages' => $messageCacheManager->getMessage($relativeFile));
         }
         $this->stopwatch->stop($this->getFileRelativePathname($file));
     }
     $this->stopwatch->stopSection('fixFile');
     return $changed;
 }
 /**
  * Resolves risky allowed flag.
  */
 private function resolveRiskyAllowed()
 {
     if (null !== $this->options['allow-risky']) {
         $this->allowRisky = 'yes' === $this->options['allow-risky'];
         return;
     }
     $this->allowRisky = $this->config->getRiskyAllowed();
 }
 protected function parseFixers()
 {
     if (null !== $this->options['fixers']) {
         return array_map('trim', explode(',', $this->options['fixers']));
     }
     if (null === $this->options['level']) {
         return $this->config->getFixers();
     }
 }
Exemplo n.º 4
0
 private function prepareFixers(ConfigInterface $config)
 {
     $fixers = $config->getFixers();
     foreach ($fixers as $fixer) {
         if ($fixer instanceof ConfigAwareInterface) {
             $fixer->setConfig($config);
         }
     }
     return $fixers;
 }
Exemplo n.º 5
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());
     $processed = array();
     foreach ($config->getFinder() as $file) {
         $name = $this->getFileRelativePathname($file);
         if (in_array($name, $processed, true)) {
             continue;
         }
         $processed[] = $name;
         if ($file->isDir() || $file->isLink()) {
             continue;
         }
         $this->stopwatch->start($this->getFileRelativePathname($file));
         if ($fixInfo = $this->fixFile($file, $fixers, $dryRun, $diff, $fileCacheManager)) {
             $changed[$name] = $fixInfo;
         }
         $this->stopwatch->stop($this->getFileRelativePathname($file));
     }
     $this->stopwatch->stopSection('fixFile');
     return $changed;
 }