GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

FeatureManager   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 84.21%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 9
c 2
b 0
f 1
lcom 1
cbo 5
dl 0
loc 58
ccs 16
cts 19
cp 0.8421
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A addFeature() 0 10 2
A removeFeature() 0 6 1
A has() 0 4 1
A get() 0 8 2
A isActive() 0 4 1
1
<?php
2
/**
3
 * Copyright (c) 2016, HelloFresh GmbH.
4
 * All rights reserved.
5
 *
6
 * This source code is licensed under the MIT license found in the
7
 * LICENSE file in the root directory of this source tree.
8
 */
9
10
namespace HelloFresh\FeatureToggle;
11
12
use Collections\Dictionary;
13
use Collections\MapInterface;
14
use HelloFresh\FeatureToggle\Exception\FeatureAlreadyExistsException;
15
use HelloFresh\FeatureToggle\Exception\FeatureNotFoundException;
16
17
class FeatureManager
18
{
19
    /**
20
     * @var MapInterface
21
     */
22
    protected $features;
23
24
    /**
25
     * FeatureManager constructor.
26
     * @param MapInterface $features
27
     */
28 6
    public function __construct(MapInterface $features = null)
29
    {
30 6
        $this->features = $features ? $features : new Dictionary();
31 6
    }
32
33 5
    public function addFeature(FeatureInterface $feature)
34
    {
35 5
        if ($this->has($feature->getName())) {
36 1
            throw new FeatureAlreadyExistsException(sprintf('The feature %s already exists', $feature->getName()));
37
        }
38
39 5
        $this->features->add($feature->getName(), $feature);
40
41 5
        return $this;
42
    }
43
44
    public function removeFeature(FeatureInterface $feature)
45
    {
46
        $this->features->removeKey($feature->getName());
47
48
        return $this;
49
    }
50
51 6
    public function has($name)
52
    {
53 6
        return $this->features->containsKey($name);
54
    }
55
56
    /**
57
     * Gets a feature toggle
58
     * @param $name - The name of the feature
59
     * @return FeatureInterface
60
     */
61 5
    public function get($name)
62
    {
63 5
        if (!$this->has($name)) {
64 1
            throw new FeatureNotFoundException(sprintf('The feature %s was not found', $name));
65
        }
66
67 4
        return $this->features->get($name);
68
    }
69
70 3
    public function isActive($name, Context $context)
71
    {
72 3
        return $this->get($name)->activeFor($context);
73
    }
74
}
75