diff --git a/src/Config.php b/src/Config.php index 44f7149a0c..1a526a3cb9 100644 --- a/src/Config.php +++ b/src/Config.php @@ -115,6 +115,7 @@ class Config 'tabWidth' => null, 'encoding' => null, 'extensions' => null, + 'editorPath' => null, 'sniffs' => null, 'exclude' => null, 'ignored' => null, @@ -485,6 +486,7 @@ public function restoreDefaults() $this->reportFile = null; $this->generator = null; $this->filter = null; + $this->editorPath = null; $this->bootstrap = []; $this->basepath = null; $this->reports = ['full' => null]; @@ -503,6 +505,11 @@ public function restoreDefaults() $this->standards = explode(',', $standard); } + $editorPath = self::getConfigData('editorPath'); + if ($editorPath !== null) { + $this->editorPath = $editorPath; + } + $reportFormat = self::getConfigData('report_format'); if ($reportFormat !== null) { $this->reports = [$reportFormat => null]; @@ -834,6 +841,9 @@ public function processLongArgument($arg, $pos) $this->sniffs = $sniffs; $this->overriddenDefaults['sniffs'] = true; + } else if (substr($arg, 0, 12) === 'editor-path=') { + $this->editorPath = substr($arg, 12); + $this->overriddenDefaults['editorPath'] = true; } else if (substr($arg, 0, 8) === 'exclude=') { if (isset($this->overriddenDefaults['exclude']) === true) { break; @@ -1351,7 +1361,7 @@ public function printPHPCSUsage() echo ' [--report-width=] [--basepath=] [--bootstrap=]'.PHP_EOL; echo ' [--severity=] [--error-severity=] [--warning-severity=]'.PHP_EOL; echo ' [--runtime-set key value] [--config-set key value] [--config-delete key] [--config-show]'.PHP_EOL; - echo ' [--standard=] [--sniffs=] [--exclude=]'.PHP_EOL; + echo ' [--standard=] [--sniffs=] [--exclude=] [--editor-path=]'.PHP_EOL; echo ' [--encoding=] [--parallel=] [--generator=]'.PHP_EOL; echo ' [--extensions=] [--ignore=] [--ignore-annotations]'.PHP_EOL; echo ' [--stdin-path=] [--file-list=] - ...'.PHP_EOL; diff --git a/src/Runner.php b/src/Runner.php index 46e504875d..45c58d40dc 100644 --- a/src/Runner.php +++ b/src/Runner.php @@ -627,7 +627,7 @@ public function processFile($file) $this->reporter->printReport('full'); - echo ' to recheck, [s] to skip or [q] to quit : '; + echo ' to recheck, [s] to skip'.($this->config->editorPath ? ', [o] to open in editor' : null).' or [q] to quit : '; $input = fgets(STDIN); $input = trim($input); @@ -636,6 +636,10 @@ public function processFile($file) break(2); case 'q': throw new DeepExitException('', 0); + case 'o': + if ($this->config->editorPath) { + exec($this->config->editorPath.' '.$file->path); + } default: // Repopulate the sniffs because some of them save their state // and only clear it when the file changes, but we are rechecking