Пример #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;
 }
 /**
  * Compute rules.
  *
  * @return array
  */
 private function parseRules()
 {
     if (null === $this->options['rules']) {
         return $this->config->getRules();
     }
     $rules = array();
     foreach (array_map('trim', explode(',', $this->options['rules'])) as $rule) {
         if ('-' === $rule[0]) {
             $rules[ltrim($rule, '-')] = false;
         } else {
             $rules[$rule] = true;
         }
     }
     return $rules;
 }
Пример #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());
     $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;
 }