UserRepository::getUserDetails()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
namespace OAuth\Repository;
4
5
use Del\Repository\UserRepository as UserRepo;
6
use League\OAuth2\Server\Entities\ClientEntityInterface;
7
use League\OAuth2\Server\Entities\UserEntityInterface;
8
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
9
use OAuth\Client;
10
11
class UserRepository extends UserRepo implements UserRepositoryInterface
12
{
13
    public function getUserEntityByUserCredentials(
14
        $email,
15
        $password,
16
        $grantType,
17
        ClientEntityInterface $client
18
    )
19
    {
20
        $user = $this->findOneBy(['email' => $email]);
21
        if ($user) {
22
            /** @var Client $client */
23
//            $client->ge
24
            return $user;
25
            /** @todo check password client and granttype */
26
        }
27
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the return type mandated by League\OAuth2\Server\Rep...tityByUserCredentials() of League\OAuth2\Server\Entities\UserEntityInterface.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
28
    }
29
30
31
    /**
32
     * @param $email
33
     * @param $password
34
     * @return mixed
35
     */
36
    public function checkUserCredentials($email, $password)
37
    {
38
        $user = $this->findOneBy(['email' => $email]);
39
        if ($user) {
40
            return $user->verifyPassword($password);
41
        }
42
        return false;
43
    }
44
45
    /**
46
     * @param $email
47
     * @return mixed
48
     */
49
    public function getUserDetails($email)
50
    {
51
        $user = $this->findOneBy(['email' => $email]);
52
        if ($user) {
53
            $user = $user->toArray();
54
        }
55
        return $user;
56
    }
57
58
}