Lines 0.00% 0 / 14
Functions and Methods 0.00% 0 / 1
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
StoreError 0.00% 0 / 14 0.00% 0 / 1 210 0.00% 0 / 1
 messageTemplate 0.00% 0 / 14 0.00% 0 / 1 210
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Contracts\Exception;
6
7enum StoreError: string implements ExceptionReason
8{
9    case KeyInvalid = 'key_invalid';
10    case ValueNotEncodable = 'value_not_encodable';
11    case ValueNotAMap = 'value_not_a_map';
12    case NotConfigured = 'not_configured';
13    case Unreachable = 'unreachable';
14    case Refused = 'refused';
15    case TimedOut = 'timed_out';
16    case RecentlyFailed = 'recently_failed';
17    case TypeMismatch = 'type_mismatch';
18    case NotIncrementable = 'not_incrementable';
19    case ValueNotIncrementable = 'value_not_incrementable';
20    case ValueMalformed = 'value_malformed';
21    case ValueRejected = 'value_rejected';
22
23    public function messageTemplate(): string
24    {
25        return match ($this) {
26            self::KeyInvalid => 'Store key "{key}" is invalid; expected a letter or digit, then up to 127 letters, digits, ".", "_", ":" or "-".',
27            self::ValueNotEncodable => 'The value for key "{key}" is not JSON-encodable: {cause}',
28            self::ValueNotAMap => '{class}::toStorage() returned a list for key "{key}"; expected a map of named fields.',
29            self::NotConfigured => 'Persistence is not configured; set persistence.url in stewart.yaml or STEWART_PERSISTENCE__URL in .env.',
30            self::Unreachable => 'The store at {target} is unreachable: {detail}',
31            self::Refused => 'The store at {target} refused the operation: {detail}',
32            self::TimedOut => 'The store at {target} did not answer within {timeout}.',
33            self::RecentlyFailed => 'The store at {target} failed moments ago and is not being retried yet: {detail}',
34            self::TypeMismatch => 'Key "{key}" holds {actual}, not {expected}.',
35            self::NotIncrementable => 'Key "{key}" cannot be incremented: {detail}',
36            self::ValueNotIncrementable => 'The stored value cannot be incremented: {detail}',
37            self::ValueMalformed => 'Key "{key}" does not hold valid JSON: {cause}',
38            self::ValueRejected => '{class}::fromStorage() rejected the value of key "{key}" (handle the old shape or delete the key): {cause}',
39        };
40    }
41}