Lines 100.00% 2 / 2
Functions and Methods 100.00% 2 / 2
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
StderrFallback 100.00% 2 / 2 100.00% 2 / 2 2 100.00% 1 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 writeLine 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Worker;
6
7use Stewart\Runtime\Model\ResourceScope;
8use Stewart\Runtime\Model\WorkerId;
9
10final readonly class StderrFallback
11{
12    public function __construct(
13        private WorkerId $workerId,
14        private string $fallbackStream = 'php://stderr',
15    ) {}
16
17    public function writeLine(ResourceScope $scope, string $text): void
18    {
19        file_put_contents($this->fallbackStream, \sprintf("[worker %d][%s] %s\n", $this->workerId->value, $scope, $text), \FILE_APPEND);
20    }
21}