UserDoctrineRepository   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 49
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getRepositoryName() 0 3 1
A save() 0 6 1
A getById() 0 10 2
A getByEmail() 0 10 2
1
<?php declare(strict_types=1);
2
3
namespace VSV\GVQ_API\User\Repositories;
4
5
use Ramsey\Uuid\UuidInterface;
6
use VSV\GVQ_API\Common\Repositories\AbstractDoctrineRepository;
7
use VSV\GVQ_API\User\Models\User;
8
use VSV\GVQ_API\User\Repositories\Entities\UserEntity;
9
use VSV\GVQ_API\User\ValueObjects\Email;
10
11
class UserDoctrineRepository extends AbstractDoctrineRepository implements UserRepository
12
{
13
    /**
14
     * @inheritdoc
15
     */
16
    protected function getRepositoryName(): string
17
    {
18
        return UserEntity::class;
19
    }
20
21
    /**
22
     * @inheritdoc
23
     */
24
    public function save(User $user): void
25
    {
26
        $userEntity = UserEntity::fromUser($user);
27
28
        $this->entityManager->persist($userEntity);
29
        $this->entityManager->flush();
30
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35
    public function getById(UuidInterface $id): ?User
36
    {
37
        /** @var UserEntity|null $userEntity */
38
        $userEntity = $this->objectRepository->findOneBy(
39
            [
40
                'id' => $id->toString(),
41
            ]
42
        );
43
44
        return $userEntity ? $userEntity->toUser() : null;
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50
    public function getByEmail(Email $email): ?User
51
    {
52
        /** @var UserEntity|null $userEntity */
53
        $userEntity = $this->objectRepository->findOneBy(
54
            [
55
                'email' => $email->toNative(),
56
            ]
57
        );
58
59
        return $userEntity ? $userEntity->toUser() : null;
60
    }
61
}
62