/** * Checks and fixes PHP files using PHP Coding Standards Fixer. * * @param ReporterInterface $reporter * @param FileInterface $file * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function review(ReporterInterface $reporter, FileInterface $file) { $cmd = 'vendor/bin/php-cs-fixer -vvv '; foreach ($this->options as $key => $value) { $cmd .= ' --' . $key . '=' . escapeshellarg($value); } $cmd .= ' fix ' . escapeshellarg($file->getRelativePath()); $process = $this->getProcess($cmd); $process->run(); $process = $this->getProcess('git add ' . escapeshellarg($file->getRelativePath())); $process->run(); }
/** * Saves a copy of the cached version of the given file to a temp directory. * * @param FileInterface $file * * @return FileInterface */ private function saveFileToCache(FileInterface $file) { $cachedPath = sys_get_temp_dir() . self::CACHE_DIR . $file->getRelativePath(); if (!is_dir(dirname($cachedPath))) { mkdir(dirname($cachedPath), 0700, true); } $cmd = sprintf('git show :%s > %s', $file->getRelativePath(), $cachedPath); $process = new Process($cmd); $process->run(); $file->setCachedPath($cachedPath); return $file; }