Lines
100.00%
9 / 9
Methods
100.00%
3 / 3
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| fromSection | 100.00% | 7 / 7 | 100.00% | 1 / 1 | 1 | ||
| isStoreConfigured | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| 12 | final readonly class PersistenceConfig | |
| 13 | { | |
| 14 | private const int SHORTEST_STORE_TIMING_MILLISECONDS = 100; | |
| 15 | ||
| 16 | public function __construct( | |
| 17 | public ?StoreDsn $url, | |
| 18 | public StorePrefix $prefix, | |
| 19 | public Duration $timeout, | |
| 20 | public Duration $recoveryInterval, | |
| 21 | ) {} | |
| 22 | ||
| 23 | /** @throws ConfigurationException */ | |
| 24 | public static function fromSection(ConfigSection $persistence): self | |
| 25 | { | |
| 26 | $shortest = Duration::milliseconds(self::SHORTEST_STORE_TIMING_MILLISECONDS); | |
| 27 | ||
| 28 | return new self( | |
| 29 | url: $persistence->findSwitchableValue('url', StoreDsn::parse(...)), | |
| 30 | prefix: $persistence->readParsedValue('prefix', static fn(string $prefix): StorePrefix => new StorePrefix($prefix)), | |
| 31 | timeout: $persistence->readDuration('timeout', $shortest), | |
| 32 | recoveryInterval: $persistence->readDuration('recovery_interval', $shortest), | |
| 33 | ); | |
| 34 | } | |
| 35 | ||
| 36 | public function isStoreConfigured(): bool | |
| 37 | { | |
| 38 | return $this->url !== null; | |
| 39 | } | |
| 40 | } |