Lines
100.00%
6 / 6
Methods
100.00%
5 / 5
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| isSuccessful | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| findFirstErrorLine | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| findLastErrorLine | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| listErrorLines | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 1 | ||
| 7 | final readonly class ExternalCommandResult | |
| 8 | { | |
| 9 | public function __construct( | |
| 10 | public int $exitCode, | |
| 11 | public string $output, | |
| 12 | public string $errorOutput, | |
| 13 | ) {} | |
| 14 | ||
| 15 | public function isSuccessful(): bool | |
| 16 | { | |
| 17 | return $this->exitCode === 0; | |
| 18 | } | |
| 19 | ||
| 20 | public function findFirstErrorLine(): string | |
| 21 | { | |
| 22 | return $this->listErrorLines()[0] ?? ''; | |
| 23 | } | |
| 24 | ||
| 25 | public function findLastErrorLine(): string | |
| 26 | { | |
| 27 | return array_last($this->listErrorLines()) ?? ''; | |
| 28 | } | |
| 29 | ||
| 30 | /** @return list<string> */ | |
| 31 | private function listErrorLines(): array | |
| 32 | { | |
| 33 | $lines = array_map(trim(...), explode("\n", $this->errorOutput)); | |
| 34 | ||
| 35 | return array_values(array_filter($lines, static fn(string $line): bool => $line !== '')); | |
| 36 | } | |
| 37 | } |