Lines
100.00%
9 / 9
Functions and Methods
100.00%
3 / 3
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| PersistenceConfig | 100.00% | 9 / 9 | 100.00% | 3 / 3 | 3 | 100.00% | 1 / 1 | |||
| __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 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Config; | |
| 6 | ||
| 7 | use Stewart\Contracts\Time\Duration; | |
| 8 | use Stewart\Runtime\Exception\ConfigurationException; | |
| 9 | use Stewart\Store\StoreDsn; | |
| 10 | use Stewart\Store\StorePrefix; | |
| 11 | ||
| 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 | } |