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

UserRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 0
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getUserEntityByUserCredentials() 0 14 2
A getUserEntityByIdentifier() 0 4 1
1
<?php
2
3
namespace AdvancedLearning\Oauth2Server\Repositories;
4
5
6
use AdvancedLearning\Oauth2Server\Entities\UserEntity;
7
use League\OAuth2\Server\Entities\ClientEntityInterface;
8
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
9
use SilverStripe\Core\Injector\Injector;
10
use SilverStripe\ORM\ValidationResult;
11
use SilverStripe\Security\Member;
12
use SilverStripe\Security\MemberAuthenticator\MemberAuthenticator;
13
14
class UserRepository implements UserRepositoryInterface
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function getUserEntityByUserCredentials(
20
        $username,
21
        $password,
22
        $grantType,
23
        ClientEntityInterface $clientEntity
24
    ) {
25
        $member = Member::get()->filter(['Email' => $username])->first();
26
        /**
27
         * @var ValidationResult $result
28
         */
29
        $result = Injector::inst()->get(MemberAuthenticator::class)->checkPassword($member, $password);
30
31
        return $result->isValid() ? new UserEntity($member) : null;
0 ignored issues
show
Documentation introduced by Conrad Dobbs
$member is of type object<SilverStripe\ORM\DataObject>|null, but the function expects a object<SilverStripe\Security\Member>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
32
    }
33
34
    /**
35
     * Gets a UserEntity by their identifier (Member->Email).
36
     *
37
     * @param string $userIdentifier
38
     * @return UserEntity
39
     */
40
    public function getUserEntityByIdentifier(string $userIdentifier): UserEntity
41
    {
42
        return new UserEntity(Member::get()->filter(['Email' => $userIdentifier])->first());
0 ignored issues
show
Documentation introduced by Conrad Dobbs
\SilverStripe\Security\M...erIdentifier))->first() is of type object<SilverStripe\ORM\DataObject>|null, but the function expects a object<SilverStripe\Security\Member>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
43
    }
44
45
}
46