ConfigCatProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isEnabled() 0 9 2
A __construct() 0 14 3
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
}