diff --git a/src/EventListener/PreAssetsCompileListener.php b/src/EventListener/PreAssetsCompileListener.php index 9eb2cea..3095223 100644 --- a/src/EventListener/PreAssetsCompileListener.php +++ b/src/EventListener/PreAssetsCompileListener.php @@ -19,7 +19,7 @@ public function __invoke(PreAssetsCompileEvent $event): void $this->typeScriptBuilder ->setOutput($output); foreach ($this->typeScriptBuilder->createAllBuildProcess() as $process) { - $process->wait(function ($type, $buffer) use ($output) { + $process->wait(static function ($type, $buffer) use ($output) { $output->write($buffer); }); diff --git a/src/Tools/WatcherBinary.php b/src/Tools/WatcherBinary.php index b88b3af..c82ffdd 100644 --- a/src/Tools/WatcherBinary.php +++ b/src/Tools/WatcherBinary.php @@ -21,26 +21,25 @@ public function startWatch(string $watchPath, callable $callback, array $extensi } $process = new Process([$this->executablePath, $watchPath]); - $process->start(function ($type, $buffer) use ($callback, $extensions) { + $process->start(static function ($type, $buffer) use ($callback, $extensions) { if (Process::ERR === $type) { throw new \Exception($buffer); - } else { - $lines = explode("\n", $buffer); - $changedFiles = []; - foreach ($lines as $line) { - try { - $entry = json_decode($line, true, 512, \JSON_THROW_ON_ERROR); - if ($extensions && !\in_array(pathinfo($entry['name'], \PATHINFO_EXTENSION), $extensions)) { - continue; - } - $changedFiles[$entry['name']] = $entry['operation']; - } catch (\JsonException) { + } + $lines = explode("\n", $buffer); + $changedFiles = []; + foreach ($lines as $line) { + try { + $entry = json_decode($line, true, 512, \JSON_THROW_ON_ERROR); + if ($extensions && !\in_array(pathinfo($entry['name'], \PATHINFO_EXTENSION), $extensions)) { continue; } + $changedFiles[$entry['name']] = $entry['operation']; + } catch (\JsonException) { + continue; } - foreach ($changedFiles as $file => $operation) { - $callback($file, $operation); - } + } + foreach ($changedFiles as $file => $operation) { + $callback($file, $operation); } }); diff --git a/tests/Tools/WatcherBinaryFactoryTest.php b/tests/Tools/WatcherBinaryFactoryTest.php index 4fedd18..be7b909 100644 --- a/tests/Tools/WatcherBinaryFactoryTest.php +++ b/tests/Tools/WatcherBinaryFactoryTest.php @@ -14,7 +14,7 @@ public function testGetBinaryFromServerSpecs(): void { // Test that the binary exists and the process is created with the correct arguments $binary = (new WatcherBinaryFactory())->getBinaryFromServerSpecs('Linux'); - $process = $binary->startWatch($this->watchPath, fn ($path, $operation) => ''); + $process = $binary->startWatch($this->watchPath, static fn ($path, $operation) => ''); $this->assertEquals('\''.realpath($this->binaryDir).'/watcher-linux\' \''.$this->watchPath.'/...\'', $process->getCommandLine()); // Test that an exception is thrown when the platform is not supported