Passed
Push — master ( f0f387...b4ede8 )
by Guilherme
02:19 queued 10s
created

RemoteClaim::setProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
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 1
dl 0
loc 5
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
     * @return mixed
86
     */
87 1
    public function getId()
88
    {
89 1
        return $this->id;
90
    }
91
92
    /**
93
     * @param mixed $id
94
     * @return RemoteClaim
95
     */
96 1
    public function setId($id)
97
    {
98 1
        $this->id = $id;
99
100 1
        return $this;
101
    }
102
103
    /**
104
     * @return TagUri
105
     */
106 16
    public function getName()
107
    {
108 16
        if (is_string($this->name)) {
109 1
            return TagUri::createFromString($this->name);
110
        }
111
112 15
        return $this->name;
113
    }
114
115
    /**
116
     * @param TagUri $name
117
     * @return RemoteClaim
118
     */
119 17
    public function setName(TagUri $name)
120
    {
121 17
        $this->name = $name;
122
123 17
        return $this;
124
    }
125
126
    /**
127
     * @inheritDoc
128
     */
129 3
    public function getUri()
130
    {
131 3
        return $this->uri;
132
    }
133
134
    /**
135
     * @inheritDoc
136
     */
137 3
    public function setUri($uri)
138
    {
139 3
        $this->uri = $uri;
140
141 3
        return $this;
142
    }
143
144
    /**
145
     * @return string
146
     */
147 9
    public function getDisplayName()
148
    {
149 9
        return $this->displayName;
150
    }
151
152
    /**
153
     * @param string $displayName
154
     * @return RemoteClaim
155
     */
156 12
    public function setDisplayName($displayName)
157
    {
158 12
        $this->displayName = $displayName;
159
160 12
        return $this;
161
    }
162
163
    /**
164
     * @return string
165
     */
166 7
    public function getDescription()
167
    {
168 7
        return $this->description;
169
    }
170
171
    /**
172
     * @param string $description
173
     * @return RemoteClaim
174
     */
175 12
    public function setDescription($description)
176
    {
177 12
        $this->description = $description;
178
179 12
        return $this;
180
    }
181
182
    /**
183
     * @return ClaimProviderInterface
184
     */
185 12
    public function getProvider()
186
    {
187 12
        return $this->provider;
188
    }
189
190
    /**
191
     * @param ClaimProviderInterface $provider
192
     * @return RemoteClaim
193
     */
194 16
    public function setProvider(ClaimProviderInterface $provider)
195
    {
196 16
        $this->provider = $provider;
197
198 16
        return $this;
199
    }
200
201
    /**
202
     * @return string[]
203
     */
204 8
    public function getRecommendedScope()
205
    {
206 8
        return $this->providerRecommendedScope;
207
    }
208
209
    /**
210
     * @param string|string[] $recommendedScope
211
     * @return RemoteClaimInterface
212
     */
213 13
    public function setRecommendedScope($recommendedScope)
214
    {
215 13
        $this->providerRecommendedScope = $this->enforceScopeArray($recommendedScope);
216
217 13
        return $this;
218
    }
219
220
    /**
221
     * @return string[]
222
     */
223 8
    public function getEssentialScope()
224
    {
225 8
        return $this->providerEssentialScope;
226
    }
227
228
    /**
229
     * @param string|string[] $essentialScope
230
     * @return RemoteClaimInterface
231
     */
232 13
    public function setEssentialScope($essentialScope)
233
    {
234 13
        $this->providerEssentialScope = $this->enforceScopeArray($essentialScope);
235
236 13
        return $this;
237
    }
238
239
    /**
240
     * @param $scope
241
     * @return string[]
242
     */
243 13
    private function enforceScopeArray($scope)
244
    {
245 13
        if (is_array($scope)) {
246 12
            return $scope;
247
        }
248
249 1
        if (trim($scope) === '') {
250
            return [];
251
        }
252
253 1
        return explode(' ', $scope);
254
    }
255
}
256