FeatureManager::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
ccs 3
cts 3
cp 1
crap 1
1
<?php
2
3
namespace LaravelFeature\Domain;
4
5
use LaravelFeature\Domain\Model\Feature;
6
use LaravelFeature\Domain\Repository\FeatureRepositoryInterface;
7
use LaravelFeature\Featurable\FeaturableInterface;
8
9
class FeatureManager
10
{
11
    /** @var FeatureRepositoryInterface */
12
    private $repository;
13
14
    /**
15
     * FeatureManager constructor.
16
     * @param FeatureRepositoryInterface $repository
17
     */
18 36
    public function __construct(FeatureRepositoryInterface $repository)
19
    {
20 36
        $this->repository = $repository;
21 36
    }
22
23 6
    public function add($featureName, $isEnabled)
24
    {
25 6
        $feature = Feature::fromNameAndStatus($featureName, $isEnabled);
26 6
        $this->repository->save($feature);
27 3
    }
28
29 6
    public function remove($featureName)
30
    {
31 6
        $feature = $this->repository->findByName($featureName);
32 6
        $this->repository->remove($feature);
33 3
    }
34
35 6
    public function rename($featureOldName, $featureNewName)
36
    {
37
        /** @var Feature $feature */
38 6
        $feature = $this->repository->findByName($featureOldName);
39 6
        $feature->setNewName($featureNewName);
40
41 6
        $this->repository->save($feature);
42 3
    }
43
44 3
    public function enable($featureName)
45
    {
46
        /** @var Feature $feature */
47 3
        $feature = $this->repository->findByName($featureName);
48
49 3
        $feature->enable();
50
51 3
        $this->repository->save($feature);
52 3
    }
53
54 3
    public function disable($featureName)
55
    {
56
        /** @var Feature $feature */
57 3
        $feature = $this->repository->findByName($featureName);
58
59 3
        $feature->disable();
60
61 3
        $this->repository->save($feature);
62 3
    }
63
64 3
    public function isEnabled($featureName)
65
    {
66
        /** @var Feature $feature */
67 3
        $feature = $this->repository->findByName($featureName);
68 3
        return $feature->isEnabled();
69
    }
70
71 3
    public function enableFor($featureName, FeaturableInterface $featurable)
72
    {
73 3
        $this->repository->enableFor($featureName, $featurable);
74 3
    }
75
76 3
    public function disableFor($featureName, FeaturableInterface $featurable)
77
    {
78 3
        $this->repository->disableFor($featureName, $featurable);
79 3
    }
80
81 3
    public function isEnabledFor($featureName, FeaturableInterface $featurable)
82
    {
83 3
        return $this->repository->isEnabledFor($featureName, $featurable);
84
    }
85
}
86