Completed
Push — master ( 70433e...08bb6a )
by Alexander
19s queued 13s
created

UserRepository::findIdentity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\Repository;
4
5
use App\Entity\User;
6
use Cycle\ORM\ORMInterface;
7
use Cycle\ORM\Select;
8
use Yiisoft\Auth\IdentityInterface;
9
use Yiisoft\Auth\IdentityRepositoryInterface;
10
11
class UserRepository extends Select\Repository implements IdentityRepositoryInterface
12
{
13
    public function __construct(ORMInterface $orm, $role = User::class)
14
    {
15
        parent::__construct(new Select($orm, $role));
16
    }
17
18
    private function findIdentityBy(string $field, string $value): ?IdentityInterface
19
    {
20
        return $this->findOne([$field => $value]);
21
    }
22
23
    public function findIdentity(string $id): ?IdentityInterface
24
    {
25
        return $this->findByPK($id);
26
    }
27
28
    public function findIdentityByToken(string $token, string $type): ?IdentityInterface
29
    {
30
        return $this->findIdentityBy('token', $token);
31
    }
32
33
    public function findByLogin(string $login): ?IdentityInterface
34
    {
35
        return $this->findIdentityBy('login', $login);
36
    }
37
}
38