Passed
Pull Request — master (#408)
by Wilmer
04:16
created

IdentityRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 6
c 1
b 0
f 1
dl 0
loc 26
ccs 8
cts 8
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A save() 0 3 1
A findIdentity() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Auth;
6
7
use Cycle\ORM\Select;
8
use Throwable;
9
use Yiisoft\Auth\IdentityRepositoryInterface;
10
use Yiisoft\Yii\Cycle\Data\Writer\EntityWriter;
11
12
final class IdentityRepository extends Select\Repository implements IdentityRepositoryInterface
13
{
14
    private EntityWriter $entityWriter;
15
16 20
    public function __construct(Select $select, EntityWriter $entityWriter)
17
    {
18 20
        $this->entityWriter = $entityWriter;
19 20
        parent::__construct($select);
20 20
    }
21
22
    /**
23
     * @param string $id
24
     *
25
     * @return Identity|null
26
     */
27 1
    public function findIdentity(string $id): ?Identity
28
    {
29 1
        return $this->findOne(['user_id' => $id]);
30
    }
31
32
    /**
33
     * @throws Throwable
34
     */
35 1
    public function save(Identity $identity): void
36
    {
37 1
        $this->entityWriter->write([$identity]);
38 1
    }
39
}
40