ScopeRepository::finalizeScopes()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 4
nc 4
nop 4
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()) {
0 ignored issues
show
Unused Code introduced by Conrad Dobbs
$scope is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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 Conrad Dobbs
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