Passed
Pull Request — master (#408)
by Wilmer
09:16 queued 03:33
created

IdentityRepository::save()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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