Passed
Push — master ( 6f2986...60854d )
by Rutger
13:35
created

Oauth2ServerException::authorizationNotAllowed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace rhertogh\Yii2Oauth2Server\exceptions;
4
5
use League\OAuth2\Server\Exception\OAuthServerException;
6
use rhertogh\Yii2Oauth2Server\interfaces\exceptions\Oauth2ServerExceptionInterface;
7
8
class Oauth2ServerException extends OAuthServerException implements Oauth2ServerExceptionInterface
9
{
10
    /**
11
     * Authorization not allowed.
12
     * @param null|string $redirectUri A HTTP URI to redirect the user back to
13
     * @return static
14
     * @since 1.0.0
15
     */
16
    public static function authorizationNotAllowed($redirectUri = null)
17
    {
18
        $errorMessage = 'Authorization not allowed.';
19
        $hint = 'The user is not is not allowed to authorize the specified client.';
20
21
        return new static($errorMessage, 0, 'authorization_not_allowed', 403, $hint, $redirectUri);
22
    }
23
24
    /**
25
     * Invalid scope error.
26
     *
27
     * @param string      $scope       The bad scope
28
     * @param null|string $redirectUri A HTTP URI to redirect the user back to
29
     *
30
     * @return static
31
     */
32
    public static function scopeNotAllowedForClient($scope, $redirectUri = null)
33
    {
34
        $errorMessage = 'The requested scope is not allowed for the specified client.';
35
36
        $hint = \sprintf(
37
            'Configure the `%s` scope for the client or remove it from the request.',
38
            \htmlspecialchars($scope, ENT_QUOTES, 'UTF-8', false)
39
        );
40
41
        return new static($errorMessage, 5, 'scope_not_allowed_for_client', 403, $hint, $redirectUri);
42
    }
43
}
44