Lines
60.00%
3 / 5
Functions and Methods
33.33%
1 / 3
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| CommitId | 60.00% | 3 / 5 | 33.33% | 1 / 3 | 5.02 | 0.00% | 0 / 1 | |||
| __construct | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 2 | |||||
| equals | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| __toString | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| 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 | use Stringable; | |
| 10 | ||
| 11 | final readonly class CommitId implements Stringable | |
| 12 | { | |
| 13 | private const string HASH_PATTERN = '/\A(?:[0-9a-f]{40}|[0-9a-f]{64})\z/'; | |
| 14 | ||
| 15 | public string $value; | |
| 16 | ||
| 17 | /** @throws DeployException */ | |
| 18 | public function __construct(string $value) | |
| 19 | { | |
| 20 | if (preg_match(self::HASH_PATTERN, $value) !== 1) { | |
| 21 | throw DeployException::createForReason(DeployError::CommitIdInvalid, value: $value); | |
| 22 | } | |
| 23 | ||
| 24 | $this->value = $value; | |
| 25 | } | |
| 26 | ||
| 27 | public function equals(self $other): bool | |
| 28 | { | |
| 29 | return $this->value === $other->value; | |
| 30 | } | |
| 31 | ||
| 32 | public function __toString(): string | |
| 33 | { | |
| 34 | return $this->value; | |
| 35 | } | |
| 36 | } |