Passed
Push — master ( fb60c6...a721e7 )
by Rutger
03:14
created

Oauth2BaseClientAuthorizationRequest::getClient()   A

Complexity

Conditions 6
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 6.0493

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 14
ccs 8
cts 9
cp 0.8889
rs 9.2222
c 1
b 0
f 0
cc 6
nc 4
nop 0
crap 6.0493
1
<?php
2
3
namespace rhertogh\Yii2Oauth2Server\components\authorization\client\base;
4
5
use rhertogh\Yii2Oauth2Server\components\authorization\base\Oauth2BaseAuthorizationRequest;
6
use rhertogh\Yii2Oauth2Server\interfaces\components\authorization\client\Oauth2ClientAuthorizationRequestInterface;
7
use yii\base\InvalidArgumentException;
8
use yii\base\InvalidCallException;
9
use yii\web\ForbiddenHttpException;
10
11
abstract class Oauth2BaseClientAuthorizationRequest extends Oauth2BaseAuthorizationRequest implements Oauth2ClientAuthorizationRequestInterface
12
{
13
    /**
14
     * @var string|null
15
     */
16
    public $_authorizeUrl = null;
17
18
    /**
19
     * @var string|null
20
     */
21
    public $_grantType = null;
22
23
    /**
24
     * @var string[]
25
     */
26
    public $_prompts = [];
27
28
    /**
29
     * @var int|null
30
     */
31
    public $_maxAge = null;
32
33
    /**
34
     * @var string[]
35
     */
36
    public $_requestedScopeIdentifiers = [];
37
38
    /**
39
     * @var string[]
40
     */
41
    public $_selectedScopeIdentifiers = [];
42
43
    /**
44
     * @var bool
45
     */
46
    protected $_userAuthenticatedBeforeRequest = false;
47
48
    /**
49
     * @var bool
50
     */
51
    protected $_authenticatedDuringRequest = false;
52
53 1
    public function __serialize()
54
    {
55 1
        return array_merge(parent::__serialize(), [
56 1
            '_authorizeUrl' => $this->_authorizeUrl,
57 1
            '_grantType' => $this->_grantType,
58 1
            '_prompts' => $this->_prompts,
59 1
            '_maxAge' => $this->_maxAge,
60 1
            '_requestedScopeIdentifiers' => $this->_requestedScopeIdentifiers,
61 1
            '_selectedScopeIdentifiers' => $this->_selectedScopeIdentifiers,
62 1
            '_userAuthenticatedBeforeRequest' => $this->_userAuthenticatedBeforeRequest,
63 1
            '_authenticatedDuringRequest' => $this->_authenticatedDuringRequest,
64 1
        ]);
65
    }
66
67
    /**
68
     * @inheritDoc
69
     */
70 4
    public function getClient()
71
    {
72 4
        $clientIdentifier = $this->getClientIdentifier();
73 4
        if (empty($clientIdentifier)) {
74 1
            throw new InvalidCallException('Client identifier must be set.');
75
        }
76 3
        if (empty($this->_client) || $this->_client->getIdentifier() != $clientIdentifier) {
77 3
            $this->_client = $this->getModule()->getClientRepository()->getClientEntity($clientIdentifier);
78 3
            if (!$this->_client  || !$this->_client->isEnabled()) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space before logical operator; 2 found
Loading history...
79
                throw new ForbiddenHttpException('Client "' . $clientIdentifier . '" not found or disabled.');
80
            }
81
        }
82
83 3
        return $this->_client;
84
    }
85
86
    /**
87
     * @inheritDoc
88
     */
89
    public function setClient($client)
90
    {
91
        if (empty($client)) {
92
            throw new InvalidArgumentException('Client is required for Client Authorization Request.');
93
        }
94
        return parent::setClient($client);
95
    }
96
97
    /**
98
     * @inheritDoc
99
     */
100 1
    public function getAuthorizeUrl()
101
    {
102 1
        return $this->_authorizeUrl;
103
    }
104
105
    /**
106
     * @inheritDoc
107
     */
108 4
    public function setAuthorizeUrl($authorizeUrl)
109
    {
110 4
        $this->_authorizeUrl = $authorizeUrl;
111 4
        $this->setCompleted(false);
112 4
        return $this;
113
    }
114
115
    /**
116
     * @inheritDoc
117
     */
118 4
    public function getGrantType()
119
    {
120 4
        return $this->_grantType;
121
    }
122
123
    /**
124
     * @inheritDoc
125
     */
126 4
    public function setGrantType($grantType)
127
    {
128 4
        $this->_grantType = $grantType;
129 4
        $this->setCompleted(false);
130 4
        return $this;
131
    }
132
133
    /**
134
     * @inheritDoc
135
     */
136 4
    public function getPrompts()
137
    {
138 4
        return $this->_prompts;
139
    }
140
141
    /**
142
     * @inheritDoc
143
     */
144 4
    public function setPrompts($prompts)
145
    {
146 4
        $this->_prompts = $prompts;
147 4
        return $this;
148
    }
149
150
    /**
151
     * @inheritDoc
152
     */
153 4
    public function getMaxAge()
154
    {
155 4
        return $this->_maxAge;
156
    }
157
158
    /**
159
     * @inheritDoc
160
     */
161 4
    public function setMaxAge($maxAge)
162
    {
163 4
        $this->_maxAge = $maxAge;
164 4
        return $this;
165
    }
166
167
    /**
168
     * @inheritDoc
169
     */
170 4
    public function getRequestedScopeIdentifiers()
171
    {
172 4
        return $this->_requestedScopeIdentifiers;
173
    }
174
175
    /**
176
     * @inheritDoc
177
     */
178 4
    public function setRequestedScopeIdentifiers($requestedScopeIdentifiers)
179
    {
180 4
        $this->_requestedScopeIdentifiers = $requestedScopeIdentifiers;
181 4
        $this->setCompleted(false);
182 4
        return $this;
183
    }
184
185
    /**
186
     * @inheritDoc
187
     */
188 3
    public function getSelectedScopeIdentifiers()
189
    {
190 3
        return $this->_selectedScopeIdentifiers;
191
    }
192
193
    /**
194
     * @inheritDoc
195
     */
196 1
    public function setSelectedScopeIdentifiers($selectedScopeIdentifiers)
197
    {
198 1
        $this->_selectedScopeIdentifiers = $selectedScopeIdentifiers;
199 1
        $this->setCompleted(false);
200 1
        return $this;
201
    }
202
203
    /**
204
     * @inheritDoc
205
     */
206 3
    public function setUserAuthenticatedBeforeRequest($authenticatedBeforeRequest)
207
    {
208 3
        $this->_userAuthenticatedBeforeRequest = $authenticatedBeforeRequest;
209 3
        return $this;
210
    }
211
212
    /**
213
     * @inheritDoc
214
     */
215
    public function wasUserAuthenticatedBeforeRequest()
216
    {
217
        return $this->_userAuthenticatedBeforeRequest;
218
    }
219
220
    /**
221
     * @inheritDoc
222
     */
223
    public function setUserAuthenticatedDuringRequest($authenticatedDuringRequest)
224
    {
225
        $this->_authenticatedDuringRequest = $authenticatedDuringRequest;
226
        return $this;
227
    }
228
229
    /**
230
     * @inheritDoc
231
     */
232 3
    public function wasUserAthenticatedDuringRequest()
233
    {
234 3
        return $this->_authenticatedDuringRequest;
235
    }
236
}
237