Issues (2)

src/Repositories/ScopeRepository.php (1 issue)

1
<?php
2
3
namespace AdvancedLearning\Oauth2Server\Repositories;
4
5
use AdvancedLearning\Oauth2Server\Entities\ScopeEntity;
6
use AdvancedLearning\Oauth2Server\Models\Scope;
7
use League\OAuth2\Server\Entities\ClientEntityInterface;
8
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
9
10
class ScopeRepository implements ScopeRepositoryInterface
11
{
12
    /**
13
     * {@inheritDoc}
14
     */
15
    public function getScopeEntityByIdentifier($identifier)
16
    {
17
        if ($scope = Scope::get()->filter(['Name' => $identifier])->first()) {
18
            return new ScopeEntity($identifier);
19
        }
20
    }
21
22
    /**
23
     * {@inheritDoc}
24
     */
25
    public function finalizeScopes(
26
        array $scopes,
27
        $grantType,
28
        ClientEntityInterface $clientEntity,
29
        $userIdentifier = null
30
    ) {
31
        // only check if we have a user, should a client have scopes?
32
        if (empty($userIdentifier)) return $scopes;
0 ignored issues
show
Coding Style Best Practice introduced by
It is generally a best practice to always use braces with control structures.

Adding braces to control structures avoids accidental mistakes as your code changes:

// Without braces (not recommended)
if (true)
    doSomething();

// Recommended
if (true) {
    doSomething();
}
Loading history...
33
34
        $userEntity = (new UserRepository())->getUserEntityByIdentifier($userIdentifier);
35
36
        $approvedScopes = [];
37
        foreach ($scopes as $scope) {
38
            if ($userEntity->hasScope($scope->getIdentifier())) {
39
                $approvedScopes[] = $scope;
40
            }
41
        }
42
        return $approvedScopes;
43
    }
44
}
45