diff --git a/src/Console/Command/Make.php b/src/Console/Command/Make.php index 999259d..e74a211 100644 --- a/src/Console/Command/Make.php +++ b/src/Console/Command/Make.php @@ -261,7 +261,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $payload = [ 'pid' => $pid, 'configuration' => $config, - 'config' => $config->getConfigurationFile(), 'ansiSupport' => $output->isDecorated(), 'immutableCopy' => $io->getTypedOption(ManifestOptions::IMMUTABLE_OPTION)->asBoolean(), 'versions' => [ @@ -289,7 +288,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $logger->error('Workflow has failed', $context); $isSuccessful = false; } finally { - if ($isSuccessful) { + if ($isSuccessful) { // @phpstan-ignore variable.undefined $logger->notice( sprintf( 'Workflow has finished. Elapsed time %s', @@ -322,6 +321,9 @@ private function changeWorkingDir(?string $newWorkingDir): ?string return $newWorkingDir; } + /** + * @param array{pid: string} $context + */ private function getCustomStage(string $stageClass, IO $io, Command $command, LoggerInterface $logger, array $context): StageInterface { if (!class_exists($stageClass)) { diff --git a/src/Console/Logger.php b/src/Console/Logger.php index 9565905..33f7b26 100644 --- a/src/Console/Logger.php +++ b/src/Console/Logger.php @@ -37,6 +37,8 @@ public function __construct( } /** + * @param string $level + * @param string $message * @param array{ * status?: string, * id?: int, @@ -48,7 +50,7 @@ public function __construct( public function log($level, $message, array $context = []): void { if (isset($context['status']) && isset($context['id'])) { - $id = $context['id']; + $id = sprintf('%d', $context['id']); $error = $context['error'] ?? false; $message = match ($context['status']) { self::STATUS_STARTED => $this->helper->start($id, $message, $context['prefix'] ?? 'RUN'), diff --git a/src/Pipeline/AbstractStage.php b/src/Pipeline/AbstractStage.php index b3a4aa8..594badd 100644 --- a/src/Pipeline/AbstractStage.php +++ b/src/Pipeline/AbstractStage.php @@ -12,13 +12,13 @@ use Psr\Log\LoggerInterface; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Helper\HelperInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\StreamOutput; use function file_exists; use function file_get_contents; use function fopen; +use function get_resource_id; use function realpath; use function sprintf; use function unserialize; @@ -32,23 +32,20 @@ public const BOX_MANIFESTS_DIR = '.box.manifests/'; public const META_DATA_FILE = '.box.manifests.bin'; - private ?HelperInterface $debugFormatterHelper; - /** * @param array{pid: string} $context */ - public function __construct( + final public function __construct( protected IO $io, protected Command $command, protected LoggerInterface $logger, protected array $context ) { - $this->debugFormatterHelper = $this->command->getHelperSet()?->has('debug_formatter') - ? $this->command->getHelper('debug_formatter') - : null - ; } + /** + * @param array{pid: string} $context + */ public static function create(IO $io, Command $command, LoggerInterface $logger, array $context): static { return new static($io, $command, $logger, $context); @@ -56,9 +53,17 @@ public static function create(IO $io, Command $command, LoggerInterface $logger, /** * @param string|string[] $contents + * @param array{ + * status?: string, + * id?: string + * } $context */ - protected function writeToStream(string $filename, string|iterable $contents, string $reason = 'Unable to write', array $context = []): int - { + protected function writeToStream( + string $filename, + string|iterable $contents, + string $reason = 'Unable to write', + array $context = [] + ): int { $resource = fopen($filename, 'w'); if (!$resource) { $message = sprintf('%s to file "%s"', $reason, realpath($filename)); @@ -70,7 +75,11 @@ protected function writeToStream(string $filename, string|iterable $contents, st $stream->write($contents, true, OutputInterface::OUTPUT_RAW); fclose($stream->getStream()); $this->logger->debug( - sprintf('%s written to "%s"', $resource, str_starts_with($filename, 'php://') ? $filename : realpath($filename)), + sprintf( + 'Resource id #%d written to "%s"', + get_resource_id($resource), + str_starts_with($filename, 'php://') ? $filename : realpath($filename) + ), $context ); return 1; diff --git a/src/Pipeline/CompileStage.php b/src/Pipeline/CompileStage.php index 4132b38..e04eb0d 100644 --- a/src/Pipeline/CompileStage.php +++ b/src/Pipeline/CompileStage.php @@ -29,7 +29,7 @@ public function __invoke(array $payload): array { $context = ['status' => Logger::STATUS_RUNNING, 'id' => $payload['pid']]; - $configurationFile = $payload['outputConf'] ?? $payload['config']; + $configurationFile = $payload['outputConf'] ?? $payload['configurationFile']; $process = $this->createBoxProcess($configurationFile); $process->run(); diff --git a/src/Pipeline/InterruptibleTimedProcessor.php b/src/Pipeline/InterruptibleTimedProcessor.php index 77b02ec..eacfd3b 100644 --- a/src/Pipeline/InterruptibleTimedProcessor.php +++ b/src/Pipeline/InterruptibleTimedProcessor.php @@ -41,7 +41,7 @@ public function process($payload, callable ...$stages) $stopwatch = new Stopwatch(); foreach ($stages as $stage) { - $name = $stage::class; + $name = $stage::class; // @phpstan-ignore classConstant.nonObject $stopwatch->start($name); $pid = $payload['pid'] = uniqid(); @@ -66,13 +66,15 @@ public function process($payload, callable ...$stages) $isSuccessful = false; } finally { if (!$isSuccessful) { + // @phpstan-ignore-next-line variable.undefined $message = sprintf('The stage "%s" has failed : %s', $name, $exception->getMessage()); } + // @phpstan-ignore-next-line variable.undefined $this->logger->log($level, $message, ['status' => Logger::STATUS_STOPPED, 'id' => $pid, 'error' => !$isSuccessful]); if (!$isSuccessful) { // circuit breaker or critical conditions lead to abort the workflow - throw $exception; + throw $exception; // @phpstan-ignore variable.undefined } } } diff --git a/src/Pipeline/StageInterface.php b/src/Pipeline/StageInterface.php index 65373a6..3feb06c 100644 --- a/src/Pipeline/StageInterface.php +++ b/src/Pipeline/StageInterface.php @@ -27,10 +27,14 @@ interface StageInterface public const COMPILE_STAGE = 'compile'; public const STDOUT = 'php://stdout'; + /** + * @param array{pid: string} $context + */ public static function create(IO $io, Command $command, LoggerInterface $logger, array $context): static; /** * @param array{ + * pid: string, * configuration: Configuration, * ansiSupport: bool, * immutableCopy: bool, @@ -47,6 +51,7 @@ public static function create(IO $io, Command $command, LoggerInterface $logger, * configurationFile: string|null * } $payload * @return array{ + * pid: string, * configuration: Configuration, * ansiSupport: bool, * immutableCopy: bool,