, errors?: int, error_details?: list, skipped?: int, profile?: list, raw?: list} */ final class Execution { private static ?self $instance = null; /** * @param resource|null $stdout * @param resource|null $filter */ private function __construct( public readonly AgentResult $agent, public readonly Driver $driver, public mixed $stdout = null, public mixed $filter = null, ) { // } /** * @param array $argv */ public static function start(AgentResult $agent, array $argv): void { if (self::running()) { throw new ShouldNotHappenException; } $binary = basename($argv[0] ?? ''); $starter = match ($binary) { 'paratest' => new Drivers\Paratest\Starter, 'pest' => new Drivers\Pest\Starter, 'phpstan', 'phpstan.phar' => new Drivers\Phpstan\Starter, 'phpunit' => new Drivers\Phpunit\Starter, default => null, }; if ($starter instanceof Driver) { self::$instance = new self( $agent, $starter, ); $starter->start(); } } public static function running(): bool { return self::$instance instanceof Execution; } public static function current(): self { return self::$instance ?? throw new ShouldNotHappenException; } public function restoreStdout(): void { if (is_resource($this->filter)) { stream_filter_remove($this->filter); $this->filter = null; } } public function flushStdout(): void { if (! is_resource($this->filter)) { return; } $captured = CaptureFilter::output(); $this->restoreStdout(); if ($captured !== '') { fwrite(STDOUT, $captured); } } }