Test Failed
Push — dev ( ccede5...b27119 )
by Herberto
13:46
created

OauthScopeRepository::getScopeEntityByIdentifier()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Acme\App\Infrastructure\Auth\Authentication\Oauth;
6
7
use League\OAuth2\Server\Entities\ClientEntityInterface;
8
use League\OAuth2\Server\Entities\ScopeEntityInterface;
9
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
10
11
final class OauthScopeRepository implements ScopeRepositoryInterface
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    public function getScopeEntityByIdentifier($identifier): ScopeEntityInterface
17
    {
18
        if (OauthScope::hasScope($identifier)) {
19
            return new OauthScope($identifier);
20
        }
21
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function finalizeScopes(
27
        array $scopes,
28
        $grantType,
29
        ClientEntityInterface $clientEntity,
30
        $userIdentifier = null
31
    ): array {
32
        $filteredScopes = [];
33
        /** @var OauthScope $scope */
34
        foreach ($scopes as $scope) {
35
            $hasScope = OauthScope::hasScope($scope->getIdentifier());
36
            if ($hasScope) {
37
                $filteredScopes[] = $scope;
38
            }
39
        }
40
41
        return $filteredScopes;
42
    }
43
}
44