Passed
Push — develop ( dfc3dd...7c6d84 )
by nguereza
01:37
created

Scope::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Platine OAuth2
5
 *
6
 * Platine OAuth2 is a library that implements the OAuth2 specification
7
 *
8
 * This content is released under the MIT License (MIT)
9
 *
10
 * Copyright (c) 2020 Platine OAuth2
11
 *
12
 * Permission is hereby granted, free of charge, to any person obtaining a copy
13
 * of this software and associated documentation files (the "Software"), to deal
14
 * in the Software without restriction, including without limitation the rights
15
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
 * copies of the Software, and to permit persons to whom the Software is
17
 * furnished to do so, subject to the following conditions:
18
 *
19
 * The above copyright notice and this permission notice shall be included in all
20
 * copies or substantial portions of the Software.
21
 *
22
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
 * SOFTWARE.
29
 */
30
31
declare(strict_types=1);
32
33
namespace Platine\OAuth2\Entity;
34
35
/**
36
 * @class Scope
37
 * @package Platine\OAuth2\Entity
38
 */
39
class Scope
40
{
41
    /**
42
     * The scope id
43
     * @var int
44
     */
45
    protected int $id;
46
47
    /**
48
     * The scope name
49
     * @var string
50
     */
51
    protected string $name;
52
53
    /**
54
     * The scope description
55
     * @var string|null
56
     */
57
    protected ?string $description = null;
58
59
    /**
60
     * Whether is the default scope
61
     * @var bool
62
     */
63
    protected bool $isDefault = false;
64
65
    /**
66
     * Can not rewrite the constructor in child classes
67
     */
68
    final public function __construct()
69
    {
70
    }
71
72
    /**
73
     * Create new scope
74
     * @param int $id
75
     * @param string $name
76
     * @param string|null $description
77
     * @param bool $isDefault
78
     * @return self
79
     */
80
    public static function createNewScope(
81
        int $id,
82
        string $name,
83
        ?string $description = null,
84
        bool $isDefault = false
85
    ): self {
86
        $scope = new static();
87
        $scope->id = $id;
88
        $scope->name = $name;
89
        $scope->description = $description;
90
        $scope->isDefault = $isDefault;
91
92
        return $scope;
93
    }
94
95
    /**
96
     * Create scope using given data
97
     * @param array<string, mixed> $data
98
     * @return self
99
     */
100
    public static function hydrate(array $data): self
101
    {
102
        $scope = new static();
103
        $scope->id = $data['id'];
104
        $scope->name = $data['name'];
105
        $scope->description = $data['description'];
106
        $scope->isDefault = $data['is_default'];
107
108
        return $scope;
109
    }
110
111
    /**
112
     * Return the id
113
     * @return int
114
     */
115
    public function getId(): int
116
    {
117
        return $this->id;
118
    }
119
120
    /**
121
     * Return the name
122
     * @return string
123
     */
124
    public function getName(): string
125
    {
126
        return $this->name;
127
    }
128
129
    /**
130
     * Return the description
131
     * @return string|null
132
     */
133
    public function getDescription(): ?string
134
    {
135
        return $this->description;
136
    }
137
138
    /**
139
     * Whether is the default scope
140
     * @return bool
141
     */
142
    public function isDefault(): bool
143
    {
144
        return $this->isDefault;
145
    }
146
147
148
    /**
149
     *
150
     * @return string
151
     */
152
    public function __toString(): string
153
    {
154
        return $this->name;
155
    }
156
}
157