Failed Conditions
Push — master ( dc4e55...720050 )
by Florent
19:46 queued 13:33
created

ScopeRepository   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 56
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSupportedScopes() 0 4 1
A getAvailableScopesForClient() 0 4 2
A areRequestedScopesAvailable() 0 4 1
A convertToArray() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2017 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\Component\Server\Model\Scope;
15
16
use OAuth2Framework\Component\Server\Model\Client\Client;
17
use OAuth2Framework\Component\Server\Util\Scope;
18
19
final class ScopeRepository implements ScopeRepositoryInterface
20
{
21
    /**
22
     * @var string[]
23
     */
24
    private $availableScopes = [];
25
26
    /**
27
     * ScopeManager constructor.
28
     *
29
     * @param array $availableScopes
30
     */
31
    public function __construct(array $availableScopes = [])
32
    {
33
        $this->availableScopes = $availableScopes;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function getSupportedScopes(): array
40
    {
41
        return $this->availableScopes;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function getAvailableScopesForClient(Client $client): array
48
    {
49
        return ($client->has('scope')) ? $this->convertToArray($client->get('scope')) : $this->getSupportedScopes();
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function areRequestedScopesAvailable(array $requestedScopes, array $availableScopes): bool
56
    {
57
        return 0 === count(array_diff($requestedScopes, $availableScopes));
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function convertToArray(string $scopes): array
64
    {
65
        Scope::checkScopeCharset($scopes);
66
        $scopes = explode(' ', $scopes);
67
68
        foreach ($scopes as $scope) {
69
            Scope::checkScopeUsedOnce($scope, $scopes);
70
        }
71
72
        return $scopes;
73
    }
74
}
75