Skip to content

Commit c45181c

Browse files
committed
Fixed bug #1501 : Interactive mode is broken
1 parent 1a59851 commit c45181c

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
7070
- Fixed bug #1495 : Setting an invalid installed path breaks all commands
7171
- Fixed bug #1496 : Squiz.Strings.DoubleQuoteUsage not unescaping dollar sign when fixing
7272
-- Thanks to Michał Bundyra for the patch
73+
- Fixed bug #1501 : Interactive mode is broken
7374
</notes>
7475
<contents>
7576
<dir name="/">

src/Reporter.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ public function __construct(Config $config)
129129

130130
if ($output === null) {
131131
// Using a temp file.
132+
// This needs to be set in the constructor so that all
133+
// child procs use the same report file when running in parallel.
132134
$this->tmpFiles[$type] = tempnam(sys_get_temp_dir(), 'phpcs');
133135
file_put_contents($this->tmpFiles[$type], '');
134136
} else {
@@ -223,6 +225,7 @@ public function printReport($report)
223225
echo $generatedReport;
224226
if ($filename !== null && file_exists($filename) === true) {
225227
unlink($filename);
228+
unset($this->tmpFiles[$report]);
226229
}
227230
}
228231

@@ -265,6 +268,14 @@ public function cacheFileReport(File $phpcsFile)
265268

266269
if ($report['output'] === null) {
267270
// Using a temp file.
271+
if (isset($this->tmpFiles[$type]) === false) {
272+
// When running in interactive mode, the reporter prints the full
273+
// report many times, which will unlink the temp file. So we need
274+
// to create a new one if it doesn't exist.
275+
$this->tmpFiles[$type] = tempnam(sys_get_temp_dir(), 'phpcs');
276+
file_put_contents($this->tmpFiles[$type], '');
277+
}
278+
268279
file_put_contents($this->tmpFiles[$type], $generatedReport, FILE_APPEND);
269280
} else {
270281
$flags = FILE_APPEND;

src/Runner.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ public function runPHPCS()
9898
// so we hard-code the full report here and when outputting.
9999
// We also ensure parallel processing is off because we need to do one file at a time.
100100
if ($this->config->interactive === true) {
101-
$this->config->reports = array('full' => null);
102-
$this->config->parallel = 1;
103-
$this->config->showProcess = false;
101+
$this->config->reports = array('full' => null);
102+
$this->config->parallel = 1;
103+
$this->config->showProgress = false;
104104
}
105105

106106
// Disable caching if we are processing STDIN as we can't be 100%
@@ -591,9 +591,6 @@ public function processFile($file)
591591

592592
$this->reporter->cacheFileReport($file, $this->config);
593593

594-
// Clean up the file to save (a lot of) memory.
595-
$file->cleanUp();
596-
597594
if ($this->config->interactive === true) {
598595
/*
599596
Running interactively.
@@ -633,6 +630,9 @@ public function processFile($file)
633630
}//end while
634631
}//end if
635632

633+
// Clean up the file to save (a lot of) memory.
634+
$file->cleanUp();
635+
636636
}//end processFile()
637637

638638

0 commit comments

Comments
 (0)