FeatureToggler::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 8
ccs 4
cts 5
cp 0.8
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2.032
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: davis.peixoto
5
 * Date: 17/08/15
6
 * Time: 15:02
7
 */
8
9
namespace Davispeixoto\FeatureToggler;
10
11
use Exception;
12
use Noodlehaus\Config;
13
14
class FeatureToggler
15
{
16
    /**
17
     * @var Config The config object
18
     */
19
    private $config;
20
21 1
    public function __construct($configFile)
22
    {
23
        try {
24 1
            $this->config = Config::load($configFile);
25 1
        } catch (Exception $e) {
26 1
            throw new FeatureTogglerException($e->getMessage());
27
        }
28
    }
29
30
    /**
31
     * @param string $key
32
     * @param bool|string $defaultValue
33
     * @return boolean
34
     */
35 69
    public function isEnabled($key, $defaultValue = false)
36
    {
37
        try {
38 69
            if ($this->config->has($key)) {
39 52
                return (bool) $this->config->get($key, $defaultValue);
40
            } else {
41 9
                return (bool) $defaultValue;
42
            }
43 8
        } catch (Exception $e) {
44 8
            return (bool) $defaultValue;
45
        }
46
    }
47
}
48