Lines 100.00% 15 / 15
Methods 100.00% 2 / 2
Classes 100.00% 1 / 1
Covered by tests of size
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 resolve 100.00% 14 / 14 100.00% 1 / 1 4
22readonly class ConfigurationStorageSettingsResolver
23{
24    private const string DEFAULT_REDIS_DSN = 'tcp://redis:6379?database=1';
25    private const string DEFAULT_REDIS_PREFIX = 'pmf:config:';
26    private const float DEFAULT_CONNECT_TIMEOUT = 1.0;
27
28    public function __construct(
29        private DatabaseConfigurationStore $databaseConfigurationStore,
30    ) {
31    }
32
33    public function resolve(): ConfigurationStorageSettings
34    {
35        $enabledValue = strtolower(
36            $this->databaseConfigurationStore->fetchValue('storage.useRedisForConfiguration') ?? 'false',
37        );
38        $enabled = in_array($enabledValue, ['1', 'true', 'yes', 'on'], strict: true);
39
40        $redisDsn = trim($this->databaseConfigurationStore->fetchValue('storage.redisDsn') ?? '');
41        if ($redisDsn === '') {
42            $redisDsn = self::DEFAULT_REDIS_DSN;
43        }
44
45        $redisPrefix = $this->databaseConfigurationStore->fetchValue('storage.redisPrefix') ?? '';
46        if ($redisPrefix === '') {
47            $redisPrefix = self::DEFAULT_REDIS_PREFIX;
48        }
49
50        $connectTimeout = (float) ($this->databaseConfigurationStore->fetchValue('storage.redisConnectTimeout') ?? '');
51        if ($connectTimeout <= 0) {
52            $connectTimeout = self::DEFAULT_CONNECT_TIMEOUT;
53        }
54
55        return new ConfigurationStorageSettings($enabled, $redisDsn, $redisPrefix, $connectTimeout);
56    }
57}