Skip to content

Commit f2258ad

Browse files
committed
PHPStan Pro - allow pausing and resuming continuous analysis
1 parent 1b18601 commit f2258ad

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Diff for: src/Command/FixerApplication.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class FixerApplication
6767
/** @var (ExtendedPromiseInterface&CancellablePromiseInterface)|null */
6868
private $processInProgress;
6969

70+
private bool $fileMonitorActive = true;
71+
7072
/**
7173
* @param string[] $analysedPaths
7274
* @param list<string> $dnsServers
@@ -119,14 +121,22 @@ public function run(
119121
'filesCount' => $filesCount,
120122
'phpstanVersion' => ComposerHelper::getPhpStanVersion(),
121123
]]);
122-
$decoder->on('data', static function (array $data) use (
124+
$decoder->on('data', function (array $data) use (
123125
$output,
124126
): void {
125127
if ($data['action'] === 'webPort') {
126128
$output->writeln(sprintf('Open your web browser at: <fg=cyan>http://127.0.0.1:%d</>', $data['data']['port']));
127129
$output->writeln('Press [Ctrl-C] to quit.');
128130
return;
129131
}
132+
if ($data['action'] === 'resumeFileMonitor') {
133+
$this->fileMonitorActive = true;
134+
return;
135+
}
136+
if ($data['action'] === 'pauseFileMonitor') {
137+
$this->fileMonitorActive = false;
138+
return;
139+
}
130140
});
131141

132142
$this->fileMonitor->initialize(array_merge(
@@ -396,6 +406,10 @@ private function writeInfoFile(string $infoPath, string $version, string $branch
396406
private function monitorFileChanges(LoopInterface $loop, callable $hasChangesCallback): void
397407
{
398408
$callback = function () use (&$callback, $loop, $hasChangesCallback): void {
409+
if (!$this->fileMonitorActive) {
410+
$loop->addTimer(1.0, $callback);
411+
return;
412+
}
399413
$changes = $this->fileMonitor->getChanges();
400414

401415
if ($changes->hasAnyChanges()) {

0 commit comments

Comments
 (0)