Skip to content

Commit 0d7ebad

Browse files
Piotr MakowskiAstinus-Eberhard
authored andcommitted
[PMakowski] squizlabs#2.5.1.x-dev: Adding option to define editor path and open files in that during interactive session
1 parent 87ba877 commit 0d7ebad

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/Config.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class Config
115115
'tabWidth' => null,
116116
'encoding' => null,
117117
'extensions' => null,
118+
'editorPath' => null,
118119
'sniffs' => null,
119120
'exclude' => null,
120121
'ignored' => null,
@@ -485,6 +486,7 @@ public function restoreDefaults()
485486
$this->reportFile = null;
486487
$this->generator = null;
487488
$this->filter = null;
489+
$this->editorPath = null;
488490
$this->bootstrap = [];
489491
$this->basepath = null;
490492
$this->reports = ['full' => null];
@@ -503,6 +505,11 @@ public function restoreDefaults()
503505
$this->standards = explode(',', $standard);
504506
}
505507

508+
$editorPath = self::getConfigData('editorPath');
509+
if ($editorPath !== null) {
510+
$this->editorPath = $editorPath;
511+
}
512+
506513
$reportFormat = self::getConfigData('report_format');
507514
if ($reportFormat !== null) {
508515
$this->reports = [$reportFormat => null];
@@ -839,6 +846,9 @@ public function processLongArgument($arg, $pos)
839846

840847
$this->sniffs = $sniffs;
841848
self::$overriddenDefaults['sniffs'] = true;
849+
} else if (substr($arg, 0, 12) === 'editor-path=') {
850+
$this->editorPath = substr($arg, 12);
851+
self::$overriddenDefaults['editorPath'] = true;
842852
} else if (substr($arg, 0, 8) === 'exclude=') {
843853
if (isset(self::$overriddenDefaults['exclude']) === true) {
844854
break;
@@ -1361,7 +1371,7 @@ public function printPHPCSUsage()
13611371
echo ' [--report-width=<reportWidth>] [--basepath=<basepath>] [--bootstrap=<bootstrap>]'.PHP_EOL;
13621372
echo ' [--severity=<severity>] [--error-severity=<severity>] [--warning-severity=<severity>]'.PHP_EOL;
13631373
echo ' [--runtime-set key value] [--config-set key value] [--config-delete key] [--config-show]'.PHP_EOL;
1364-
echo ' [--standard=<standard>] [--sniffs=<sniffs>] [--exclude=<sniffs>]'.PHP_EOL;
1374+
echo ' [--standard=<standard>] [--sniffs=<sniffs>] [--exclude=<sniffs>] [--editor-path=<path>]'.PHP_EOL;
13651375
echo ' [--encoding=<encoding>] [--parallel=<processes>] [--generator=<generator>]'.PHP_EOL;
13661376
echo ' [--extensions=<extensions>] [--ignore=<patterns>] [--ignore-annotations]'.PHP_EOL;
13671377
echo ' [--stdin-path=<stdinPath>] [--file-list=<fileList>] <file> - ...'.PHP_EOL;

src/Runner.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ public function processFile($file)
627627

628628
$this->reporter->printReport('full');
629629

630-
echo '<ENTER> to recheck, [s] to skip or [q] to quit : ';
630+
echo '<ENTER> to recheck, [s] to skip'.($this->config->editorPath ? ', [o] to open in editor' : null).' or [q] to quit : ';
631631
$input = fgets(STDIN);
632632
$input = trim($input);
633633

@@ -636,6 +636,10 @@ public function processFile($file)
636636
break(2);
637637
case 'q':
638638
throw new DeepExitException('', 0);
639+
case 'o':
640+
if ($this->config->editorPath) {
641+
exec($this->config->editorPath.' '.$file->path);
642+
}
639643
default:
640644
// Repopulate the sniffs because some of them save their state
641645
// and only clear it when the file changes, but we are rechecking

0 commit comments

Comments
 (0)