Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
| DoctrineUserRepository | |
100.00% |
11 / 11 |
|
100.00% |
8 / 8 |
8 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| save | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| remove | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| ofId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| ofEmail | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| existsByEmail | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| paginate | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| count | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Identity\Infrastructure\Persistence\Doctrine; |
| 6 | |
| 7 | use App\Identity\Domain\User; |
| 8 | use App\Identity\Domain\UserRepository; |
| 9 | use App\Identity\Domain\ValueObject\Email; |
| 10 | use App\Identity\Domain\ValueObject\UserId; |
| 11 | use Doctrine\ORM\EntityManagerInterface; |
| 12 | |
| 13 | final class DoctrineUserRepository implements UserRepository |
| 14 | { |
| 15 | public function __construct(private readonly EntityManagerInterface $entityManager) |
| 16 | { |
| 17 | } |
| 18 | |
| 19 | public function save(User $user): void |
| 20 | { |
| 21 | $this->entityManager->persist($user); |
| 22 | $this->entityManager->flush(); |
| 23 | } |
| 24 | |
| 25 | public function remove(User $user): void |
| 26 | { |
| 27 | $this->entityManager->remove($user); |
| 28 | $this->entityManager->flush(); |
| 29 | } |
| 30 | |
| 31 | public function ofId(UserId $id): ?User |
| 32 | { |
| 33 | return $this->entityManager->find(User::class, $id); |
| 34 | } |
| 35 | |
| 36 | public function ofEmail(Email $email): ?User |
| 37 | { |
| 38 | return $this->entityManager->getRepository(User::class)->findOneBy(['email' => $email]); |
| 39 | } |
| 40 | |
| 41 | public function existsByEmail(Email $email): bool |
| 42 | { |
| 43 | return $this->ofEmail($email) !== null; |
| 44 | } |
| 45 | |
| 46 | public function paginate(int $offset, int $limit): array |
| 47 | { |
| 48 | return $this->entityManager->getRepository(User::class) |
| 49 | ->findBy([], ['createdAt' => 'ASC'], $limit, $offset); |
| 50 | } |
| 51 | |
| 52 | public function count(): int |
| 53 | { |
| 54 | return $this->entityManager->getRepository(User::class)->count([]); |
| 55 | } |
| 56 | } |