Set   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 50
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A pushFeature() 0 3 1
A jsonSerialize() 0 3 1
A getFeatureByName() 0 7 2
A __construct() 0 4 2
A offsetExists() 0 3 1
A getFeatures() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RemotelyLiving\Doorkeeper\Features;
6
7
final class Set implements \JsonSerializable
8
{
9
    /**
10
     * @var \RemotelyLiving\Doorkeeper\Features\Feature[]
11
     */
12
    private $features = [];
13
14
    /**
15
     * @param \RemotelyLiving\Doorkeeper\Features\Feature[] $features
16
     */
17
    public function __construct(array $features = [])
18
    {
19
        foreach ($features as $feature) {
20
            $this->pushFeature($feature);
21
        }
22
    }
23
24
    public function pushFeature(Feature $feature): void
25
    {
26
        $this->features[$feature->getName()] = $feature;
27
    }
28
29
    public function offsetExists(string $featureName): bool
30
    {
31
        return isset($this->features[$featureName]);
32
    }
33
34
    /**
35
     * @return \RemotelyLiving\Doorkeeper\Features\Feature[]
36
     */
37
    public function getFeatures(): array
38
    {
39
        return $this->features;
40
    }
41
42
    public function getFeatureByName(string $featureName): Feature
43
    {
44
        if (!$this->offsetExists($featureName)) {
45
            throw new \OutOfBoundsException("Feature {$featureName} does not exist");
46
        }
47
48
        return $this->features[$featureName];
49
    }
50
51
    /**
52
     * @return array
53
     */
54
    public function jsonSerialize(): array
55
    {
56
        return ['features' => $this->features];
57
    }
58
}
59