DefaultScopePolicy   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A getScopes() 0 3 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: GCC-MED
5
 * Date: 15/01/2018
6
 * Time: 11:50
7
 */
8
9
namespace OAuth2\ScopePolicy\Policies;
10
11
12
use OAuth2\Roles\ClientInterface;
13
14
/**
15
 * Class DefaultScopePolicy
16
 * @package OAuth2\ScopePolicy\Policies
17
 *
18
 * @see https://tools.ietf.org/html/rfc6749#section-3.3 *
19
 * If the client omits the scope parameter when requesting
20
 * authorization, the authorization server MUST either process the
21
 * request using a pre-defined default value or fail the request
22
 * indicating an invalid scope.
23
 */
24
class DefaultScopePolicy implements ScopePolicyInterface
25
{
26
    /**
27
     * @var array
28
     */
29
    private $scopes = [];
30
31
    public function __construct(array $scopes)
32
    {
33
        if(empty($scopes)) {
34
            throw new \InvalidArgumentException('Scope must not be an empty array');
35
        }
36
        $this->scopes = $scopes;
37
    }
38
39
    public function getScopes(ClientInterface $client, ?array $scopes): array
40
    {
41
        return empty($scopes) ? $this->scopes : $scopes;
42
    }
43
}