Feature::jsonSerialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RemotelyLiving\Doorkeeper\Features;
6
7
use RemotelyLiving\Doorkeeper\Rules;
8
9
final class Feature implements \JsonSerializable
10
{
11
    private string $name;
12
13
    private bool $enabled;
14
15
    /**
16
     * @var \RemotelyLiving\Doorkeeper\Rules\RuleInterface[]
17
     */
18
    private $ruleSet = [];
19
20
    /**
21
     * @param string                                           $name
22
     * @param bool                                             $enabled
23
     * @param \RemotelyLiving\Doorkeeper\Rules\RuleInterface[] $rules
24
     */
25
    public function __construct(string $name, bool $enabled, array $rules = [])
26
    {
27
        $this->name      = $name;
28
        $this->enabled = $enabled;
29
30
        foreach ($rules as $rule) {
31
            $this->addRule($rule);
32
        }
33
    }
34
35
    public function getName(): string
36
    {
37
        return $this->name;
38
    }
39
40
    public function isEnabled(): bool
41
    {
42
        return $this->enabled;
43
    }
44
45
    /**
46
     * @throws \DomainException
47
     */
48
    public function addRule(Rules\RuleInterface $rule): void
49
    {
50
        $this->ruleSet[] = $rule;
51
    }
52
53
    /**
54
     * @return \RemotelyLiving\Doorkeeper\Rules\RuleInterface[]
55
     */
56
    public function getRules(): array
57
    {
58
        return $this->ruleSet;
59
    }
60
61
    public function jsonSerialize(): array
62
    {
63
        return [
64
            'name' => $this->name,
65
            'enabled' => $this->enabled,
66
            'rules' => $this->ruleSet,
67
        ];
68
    }
69
}
70