Passed
Push — develop ( e1f02f...e3219b )
by Laurent
01:59
created

ReadUser   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 10
c 1
b 0
f 0
dl 0
loc 33
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A findAll() 0 3 1
A __construct() 0 3 1
A existsWithUsername() 0 3 1
A findOneByUuid() 0 9 2
A existsWithEmail() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the G.L.S.R. Apps package.
7
 *
8
 * (c) Dev-Int Création <[email protected]>.
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace User\Infrastructure\Storage;
15
16
use Core\Domain\Common\Model\VO\ResourceUuid;
17
use User\Domain\Exception\UserNotFoundException;
18
use User\Domain\Storage\ReadUser as ReadUserDomain;
19
use User\Infrastructure\Doctrine\Entity\User;
20
use User\Infrastructure\Doctrine\Repository\UserRepository;
21
22
class ReadUser implements ReadUserDomain
23
{
24
    private UserRepository $userRepository;
25
26
    public function __construct(UserRepository $userRepository)
27
    {
28
        $this->userRepository = $userRepository;
29
    }
30
31
    public function existsWithUsername(string $username): bool
32
    {
33
        return $this->userRepository->existWithUsername($username);
34
    }
35
36
    public function existsWithEmail(string $email): bool
37
    {
38
        return $this->userRepository->existWithEmail($email);
39
    }
40
41
    public function findOneByUuid(string $uuid): User
42
    {
43
        $user = $this->userRepository->findOneByUuid(ResourceUuid::fromString($uuid)->__toString());
44
45
        if (!$user instanceof User) {
46
            throw new UserNotFoundException();
47
        }
48
49
        return $user;
50
    }
51
52
    public function findAll(): array
53
    {
54
        return $this->userRepository->findAll();
55
    }
56
}
57