Completed
Push — develop ( 5503b1...6a0d81 )
by Abdelrahman
19:31 queued 18:12
created

ScopeRepository::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 Rinvex\Oauth\Repositories;
6
7
use Rinvex\Oauth\Bridge\Scope;
8
use League\OAuth2\Server\Entities\ClientEntityInterface;
9
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
10
11
class ScopeRepository implements ScopeRepositoryInterface
12
{
13
    /**
14
     * Return information about a scope.
15
     *
16
     * @param string $identifier The scope identifier
17
     *
18
     * @return \League\OAuth2\Server\Entities\ScopeEntityInterface|null
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use Scope|null.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
19
     */
20
    public function getScopeEntityByIdentifier($identifier)
21
    {
22
        if (app('cortex.auth.ability')->resolveRouteBinding($identifier)) {
23
            return new Scope($identifier);
24
        }
25
    }
26
27
    /**
28
     * Given a client, grant type and optional user identifier validate the set of scopes requested are valid and optionally
29
     * append additional scopes or remove requested scopes.
30
     *
31
     * @param \League\OAuth2\Server\Entities\ScopeEntityInterface[] $scopes
32
     * @param string                                                $grantType
33
     * @param ClientEntityInterface                                 $clientEntity
34
     * @param null|string                                           $userIdentifier
35
     *
36
     * @return \League\OAuth2\Server\Entities\ScopeEntityInterface[]
37
     */
38
    public function finalizeScopes(array $scopes, $grantType, ClientEntityInterface $clientEntity, $userIdentifier = null)
39
    {
40
        $abilityIds = app('cortex.auth.ability')->all()->pluck('id');
41
42
        return collect($scopes)->filter(function ($scope) use ($abilityIds) {
43
            return $abilityIds->contains(app('cortex.auth.ability')->unhashId($scope->getIdentifier()));
44
        })->all();
45
    }
46
}
47