Completed
Push — master ( 3a6bc2...bdf328 )
by Conrad
01:56
created

UserEntity   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 36
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getMember() 0 4 1
A hasScope() 0 7 2
1
<?php
2
3
namespace AdvancedLearning\Oauth2Server\Entities;
4
5
use AdvancedLearning\Oauth2Server\Extensions\GroupExtension;
6
use League\OAuth2\Server\Entities\Traits\EntityTrait;
7
use League\OAuth2\Server\Entities\UserEntityInterface;
8
use SilverStripe\Security\Group;
9
use SilverStripe\Security\Member;
10
11
class UserEntity implements UserEntityInterface
12
{
13
    use EntityTrait;
14
15
    protected $member;
16
17
    public function __construct(Member $member)
18
    {
19
        $this->member = $member;
20
        $this->setIdentifier($member->Email);
21
    }
22
23
    /**
24
     * Get the Member associated with this ClientEntity.
25
     *
26
     * @return Member
27
     */
28
    public function getMember()
29
    {
30
        return $this->member;
31
    }
32
33
    /**
34
     * Checks whether the member has a scope. Only works if the GroupExtension has been configured.
35
     *
36
     * @param string $scope
37
     * @return bool
38
     */
39
    public function hasScope(string $scope): bool
40
    {
41
        // always return true if extensions not configured
42
        return !Group::create()->hasExtension(GroupExtension::class) || $this->getMember()->Groups()->filter([
43
            'Scopes.Name' => $scope
44
        ])->count() > 0;
45
    }
46
}
47