ConfigCatProvider::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
c 1
b 0
f 0
nc 4
nop 4
dl 0
loc 14
rs 10
1
<?php
2
3
namespace MetroMarkets\FFBundle\Providers;
4
5
use ConfigCat\Cache\ConfigCache;
6
use ConfigCat\ConfigCatClient;
7
use ConfigCat\User;
8
use MetroMarkets\FFBundle\Contract\ProviderInterface;
9
use Psr\Log\LoggerInterface;
10
11
class ConfigCatProvider implements ProviderInterface
12
{
13
    /** @var ConfigCatClient */
14
    private $client;
15
16
    public function __construct(string $sdkKey, ConfigCache $cache = null, int $cacheTTL = 60, LoggerInterface $logger = null)
17
    {
18
        $options = [];
19
20
        if ($cache) {
21
            $options['cache'] = $cache;
22
            $options['cache-refresh-interval'] = $cacheTTL;
23
        }
24
25
        if ($logger) {
26
            $options['logger'] = $logger;
27
        }
28
29
        $this->client = new ConfigCatClient($sdkKey, $options);
30
    }
31
32
33
    public function isEnabled(string $key, string $identifier = null): bool
34
    {
35
        $user = null;
36
37
        if ($identifier) {
38
            $user = new User($identifier);
39
        }
40
41
        return $this->client->getValue($key, false, $user);
42
    }
43
}