Lines
100.00%
7 / 7
Functions and Methods
100.00%
2 / 2
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| PreparedRelease | 100.00% | 7 / 7 | 100.00% | 2 / 2 | 4 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| fromScriptOutput | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 3 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Broker\Deploy; | |
| 6 | ||
| 7 | use Stewart\Runtime\Exception\DeployError; | |
| 8 | use Stewart\Runtime\Exception\DeployException; | |
| 9 | ||
| 10 | final readonly class PreparedRelease | |
| 11 | { | |
| 12 | public function __construct( | |
| 13 | public CommitId $commit, | |
| 14 | public ReleaseState $state, | |
| 15 | ) {} | |
| 16 | ||
| 17 | /** @throws DeployException */ | |
| 18 | public static function fromScriptOutput(string $output): self | |
| 19 | { | |
| 20 | $line = trim($output); | |
| 21 | $parts = explode(' ', $line); | |
| 22 | $state = ReleaseState::tryFrom($parts[1] ?? ''); | |
| 23 | ||
| 24 | if (\count($parts) !== 2 || $state === null) { | |
| 25 | throw DeployException::createForReason(DeployError::PrepareOutputUnexpected, output: $line); | |
| 26 | } | |
| 27 | ||
| 28 | return new self(new CommitId($parts[0]), $state); | |
| 29 | } | |
| 30 | } |