Completed
Push — master ( b4ede8...73596f )
by Guilherme
05:13
created

RemoteClaim::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\RemoteClaimsBundle\Entity;
12
13
use Doctrine\ORM\Mapping as ORM;
14
use LoginCidadao\RemoteClaimsBundle\Model\ClaimProviderInterface;
15
use LoginCidadao\RemoteClaimsBundle\Model\RemoteClaimInterface;
16
use LoginCidadao\RemoteClaimsBundle\Model\TagUri;
17
use LoginCidadao\RemoteClaimsBundle\Validator\Constraints\HostBelongsToClaimProvider;
18
19
/**
20
 * RemoteClaim
21
 * @package LoginCidadao\RemoteClaimsBundle\Entity
22
 * @HostBelongsToClaimProvider
23
 * @ORM\Entity(repositoryClass="LoginCidadao\RemoteClaimsBundle\Entity\RemoteClaimRepository")
24
 * @ORM\Table(name="remote_claim")
25
 */
26
class RemoteClaim implements RemoteClaimInterface
27
{
28
    /**
29
     * @ORM\Id
30
     * @ORM\Column(type="integer")
31
     * @ORM\GeneratedValue(strategy="AUTO")
32
     */
33
    protected $id;
34
35
    /**
36
     * @var TagUri|string
37
     * @ORM\Column(name="name", type="string", length=255, nullable=false)
38
     */
39
    private $name;
40
41
    /**
42
     * Uri used to access the Claim Metadata.
43
     *
44
     * This value is to be considered a "cached value" and will be used only when the Discovery process fails.
45
     *
46
     * @var string
47
     *
48
     * @ORM\Column(name="claim_uri", type="string", length=2083, nullable=true)
49
     */
50
    private $uri;
51
52
    /**
53
     * @var string
54
     * @ORM\Column(name="display_name", type="string", length=255, nullable=false)
55
     */
56
    private $displayName;
57
58
    /**
59
     * @var string
60
     * @ORM\Column(name="description", type="text", nullable=true)
61
     */
62
    private $description;
63
64
    /**
65
     * @var string[]
66
     * @ORM\Column(name="provider_recommended_scope", type="json_array", nullable=true)
67
     */
68
    private $providerRecommendedScope;
69
70
    /**
71
     * @var string[]
72
     * @ORM\Column(name="provider_essential_scope", type="json_array", nullable=true)
73
     */
74
    private $providerEssentialScope;
75
76
    /**
77
     * @var ClaimProviderInterface
78
     *
79
     * @ORM\ManyToOne(targetEntity="LoginCidadao\OAuthBundle\Entity\Client")
80
     * @ORM\JoinColumn(name="provider_id", referencedColumnName="id")
81
     */
82
    private $provider;
83
84
    /**
85
     * RemoteClaim constructor.
86
     */
87 26
    public function __construct()
88
    {
89 26
        $this->providerEssentialScope = [];
90 26
        $this->providerRecommendedScope = [];
91 26
    }
92
93
    /**
94
     * @return mixed
95
     */
96 1
    public function getId()
97
    {
98 1
        return $this->id;
99
    }
100
101
    /**
102
     * @param mixed $id
103
     * @return RemoteClaim
104
     */
105 1
    public function setId($id)
106
    {
107 1
        $this->id = $id;
108
109 1
        return $this;
110
    }
111
112
    /**
113
     * @return TagUri
114
     */
115 16
    public function getName()
116
    {
117 16
        if (is_string($this->name)) {
118 1
            return TagUri::createFromString($this->name);
119
        }
120
121 15
        return $this->name;
122
    }
123
124
    /**
125
     * @param TagUri $name
126
     * @return RemoteClaim
127
     */
128 17
    public function setName(TagUri $name)
129
    {
130 17
        $this->name = $name;
131
132 17
        return $this;
133
    }
134
135
    /**
136
     * @inheritDoc
137
     */
138 3
    public function getUri()
139
    {
140 3
        return $this->uri;
141
    }
142
143
    /**
144
     * @inheritDoc
145
     */
146 3
    public function setUri($uri)
147
    {
148 3
        $this->uri = $uri;
149
150 3
        return $this;
151
    }
152
153
    /**
154
     * @return string
155
     */
156 9
    public function getDisplayName()
157
    {
158 9
        return $this->displayName;
159
    }
160
161
    /**
162
     * @param string $displayName
163
     * @return RemoteClaim
164
     */
165 12
    public function setDisplayName($displayName)
166
    {
167 12
        $this->displayName = $displayName;
168
169 12
        return $this;
170
    }
171
172
    /**
173
     * @return string
174
     */
175 7
    public function getDescription()
176
    {
177 7
        return $this->description;
178
    }
179
180
    /**
181
     * @param string $description
182
     * @return RemoteClaim
183
     */
184 12
    public function setDescription($description)
185
    {
186 12
        $this->description = $description;
187
188 12
        return $this;
189
    }
190
191
    /**
192
     * @return ClaimProviderInterface
193
     */
194 12
    public function getProvider()
195
    {
196 12
        return $this->provider;
197
    }
198
199
    /**
200
     * @param ClaimProviderInterface $provider
201
     * @return RemoteClaim
202
     */
203 16
    public function setProvider(ClaimProviderInterface $provider)
204
    {
205 16
        $this->provider = $provider;
206
207 16
        return $this;
208
    }
209
210
    /**
211
     * @return string[]
212
     */
213 10
    public function getRecommendedScope()
214
    {
215 10
        return $this->providerRecommendedScope;
216
    }
217
218
    /**
219
     * @param string|string[] $recommendedScope
220
     * @return RemoteClaimInterface
221
     */
222 13
    public function setRecommendedScope($recommendedScope)
223
    {
224 13
        $this->providerRecommendedScope = $this->enforceScopeArray($recommendedScope);
225
226 13
        return $this;
227
    }
228
229
    /**
230
     * @return string[]
231
     */
232 10
    public function getEssentialScope()
233
    {
234 10
        return $this->providerEssentialScope;
235
    }
236
237
    /**
238
     * @param string|string[] $essentialScope
239
     * @return RemoteClaimInterface
240
     */
241 13
    public function setEssentialScope($essentialScope)
242
    {
243 13
        $this->providerEssentialScope = $this->enforceScopeArray($essentialScope);
244
245 13
        return $this;
246
    }
247
248
    /**
249
     * @param $scope
250
     * @return string[]
251
     */
252 13
    private function enforceScopeArray($scope)
253
    {
254 13
        if (is_array($scope)) {
255 12
            return $scope;
256
        }
257
258 1
        if (trim($scope) === '') {
259
            return [];
260
        }
261
262 1
        return explode(' ', $scope);
263
    }
264
}
265