Passed
Push — master ( 168924...afae3b )
by Alexander
06:14
created

UserRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 25%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 25
ccs 2
cts 8
cp 0.25
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A findAll() 0 3 1
A findIdentityBy() 0 3 1
A findIdentity() 0 3 1
A findByLogin() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\User;
6
7
use Cycle\ORM\Select;
8
use Yiisoft\Auth\IdentityInterface;
9
use Yiisoft\Auth\IdentityRepositoryInterface;
10
use Yiisoft\Data\Reader\DataReaderInterface;
11
use Yiisoft\Yii\Cycle\Data\Reader\EntityReader;
12
13
class UserRepository extends Select\Repository implements IdentityRepositoryInterface
14
{
15 1
    public function findAll(array $scope = [], array $orderBy = []): DataReaderInterface
16
    {
17 1
        return new EntityReader($this->select()->where($scope)->orderBy($orderBy));
18
    }
19
20
    private function findIdentityBy(string $field, string $value): ?IdentityInterface
21
    {
22
        return $this->findOne([$field => $value]);
23
    }
24
25
    /**
26
     * @param string $id
27
     *
28
     * @return IdentityInterface|User|null
29
     */
30
    public function findIdentity(string $id): ?IdentityInterface
31
    {
32
        return $this->findByPK($id);
33
    }
34
35
    public function findByLogin(string $login): ?IdentityInterface
36
    {
37
        return $this->findIdentityBy('login', $login);
38
    }
39
}
40