Passed
Push — master ( b8bdbf...0c1875 )
by Rutger
15:13
created

Oauth2ServerException::scopeNotAllowedForClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 10
ccs 0
cts 7
cp 0
rs 10
cc 1
nc 1
nop 2
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
     * Unknown 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 unknownScope($scope, $redirectUri = null)
33
    {
34
        $errorMessage = 'The requested scope is unknown.';
35
36
        $hint = \sprintf(
37
            'Check the spelling of the `%s` scope 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
    /**
45
     * Unauthorized scope error.
46
     *
47
     * @param string      $scope       The bad scope
48
     * @param null|string $redirectUri A HTTP URI to redirect the user back to
49
     *
50
     * @return static
51
     */
52
    public static function scopeNotAllowedForClient($scope, $redirectUri = null)
53
    {
54
        $errorMessage = 'The requested scope is not allowed for the specified client.';
55
56
        $hint = \sprintf(
57
            'Request access to the `%s` scope for the client or remove it from the request.',
58
            \htmlspecialchars($scope, ENT_QUOTES, 'UTF-8', false)
59
        );
60
61
        return new static($errorMessage, 5, 'scope_not_allowed_for_client', 403, $hint, $redirectUri);
62
    }
63
}
64