FeatureToggler   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 90.91%

Importance

Changes 7
Bugs 2 Features 0
Metric Value
wmc 5
c 7
b 2
f 0
lcom 1
cbo 2
dl 0
loc 34
ccs 10
cts 11
cp 0.9091
rs 10

2 Methods

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