Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| StoreException | |
100.00% |
5 / 5 |
|
100.00% |
5 / 5 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| alreadyExists | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| revisionConflict | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| statusConflict | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| notFound | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace LambdaTwelve\OneRecord\Server\Spi; |
| 6 | |
| 7 | use LambdaTwelve\OneRecord\Rdf\Iri; |
| 8 | use RuntimeException; |
| 9 | |
| 10 | /** |
| 11 | * The two conditions a store must detect itself, because only it can do so |
| 12 | * atomically: creating an object that exists (409) and saving a revision |
| 13 | * against a stale current revision. |
| 14 | */ |
| 15 | final class StoreException extends RuntimeException |
| 16 | { |
| 17 | public const string ALREADY_EXISTS = 'already_exists'; |
| 18 | public const string REVISION_CONFLICT = 'revision_conflict'; |
| 19 | public const string NOT_FOUND = 'not_found'; |
| 20 | public const string STATUS_CONFLICT = 'status_conflict'; |
| 21 | |
| 22 | public function __construct(public readonly string $kind, string $message) |
| 23 | { |
| 24 | parent::__construct($message); |
| 25 | } |
| 26 | |
| 27 | public static function alreadyExists(Iri $iri): self |
| 28 | { |
| 29 | return new self(self::ALREADY_EXISTS, \sprintf('"%s" already exists.', $iri->value)); |
| 30 | } |
| 31 | |
| 32 | public static function revisionConflict(Iri $iri, int $expected, int $actual): self |
| 33 | { |
| 34 | return new self(self::REVISION_CONFLICT, \sprintf('"%s" is at revision %d, not %d.', $iri->value, $actual, $expected)); |
| 35 | } |
| 36 | |
| 37 | public static function statusConflict(Iri $iri, string $expected, string $actual): self |
| 38 | { |
| 39 | return new self(self::STATUS_CONFLICT, \sprintf('"%s" is %s, not %s.', $iri->value, $actual, $expected)); |
| 40 | } |
| 41 | |
| 42 | public static function notFound(Iri $iri): self |
| 43 | { |
| 44 | return new self(self::NOT_FOUND, \sprintf('"%s" does not exist.', $iri->value)); |
| 45 | } |
| 46 | } |