Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
88.00% |
22 / 25 |
|
78.95% |
15 / 19 |
|
61.54% |
8 / 13 |
|
57.14% |
4 / 7 |
CRAP | |
0.00% |
0 / 1 |
| DoctrineIdentityRepository | |
88.00% |
22 / 25 |
|
78.95% |
15 / 19 |
|
61.54% |
8 / 13 |
|
57.14% |
4 / 7 |
17.88 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| findByEmail | |
75.00% |
3 / 4 |
|
66.67% |
2 / 3 |
|
50.00% |
1 / 2 |
|
0.00% |
0 / 1 |
2.50 | |||
| findByUsername | |
75.00% |
3 / 4 |
|
66.67% |
2 / 3 |
|
50.00% |
1 / 2 |
|
0.00% |
0 / 1 |
2.50 | |||
| findByEmailOrUsername | |
100.00% |
8 / 8 |
|
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| findByIdentifier | |
66.67% |
2 / 3 |
|
66.67% |
4 / 6 |
|
25.00% |
1 / 4 |
|
0.00% |
0 / 1 |
3.69 | |||
| findById | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| save | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Auth\Infrastructure\Persistence\Doctrine\Repository; |
| 4 | |
| 5 | use App\Auth\Domain\Model\Identity; |
| 6 | use App\Auth\Domain\Port\Driven\IdentityRepository; |
| 7 | use App\Auth\Infrastructure\Persistence\Doctrine\Entity\DoctrineIdentity; |
| 8 | use App\Shared\Domain\Model\EntityId; |
| 9 | use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
| 10 | use Doctrine\ORM\EntityManagerInterface; |
| 11 | use Doctrine\Persistence\ManagerRegistry; |
| 12 | |
| 13 | /** |
| 14 | * @author Wilhelm Zwertvaegher |
| 15 | * @extends ServiceEntityRepository<DoctrineIdentity> |
| 16 | */ |
| 17 | class DoctrineIdentityRepository extends ServiceEntityRepository implements IdentityRepository |
| 18 | { |
| 19 | public function __construct(ManagerRegistry $managerRegistry, private readonly EntityManagerInterface $entityManager) |
| 20 | { |
| 21 | parent::__construct($managerRegistry, DoctrineIdentity::class); |
| 22 | } |
| 23 | |
| 24 | public function findByEmail(string $email): ?Identity |
| 25 | { |
| 26 | $doctrineIdentity = parent::findOneBy(['email' => $email]); |
| 27 | if (!$doctrineIdentity) { |
| 28 | return null; |
| 29 | } |
| 30 | return $doctrineIdentity->toDomain(); |
| 31 | } |
| 32 | |
| 33 | public function findByUsername(string $username): ?Identity |
| 34 | { |
| 35 | $doctrineIdentity = parent::findOneBy(['username' => $username]); |
| 36 | if (!$doctrineIdentity) { |
| 37 | return null; |
| 38 | } |
| 39 | return $doctrineIdentity->toDomain(); |
| 40 | } |
| 41 | |
| 42 | public function findByEmailOrUsername(string $email, string $username): ?Identity |
| 43 | { |
| 44 | $doctrineIdentity = $this->createQueryBuilder('u') |
| 45 | ->where('u.email = :email') |
| 46 | ->orWhere('u.username = :username') |
| 47 | ->setParameter('email', $email) |
| 48 | ->setParameter('username', $username) |
| 49 | ->getQuery() |
| 50 | ->getOneOrNullResult(); |
| 51 | |
| 52 | return $doctrineIdentity ? $doctrineIdentity->toDomain() : null; |
| 53 | } |
| 54 | |
| 55 | public function findByIdentifier(string $identifier): ?Identity |
| 56 | { |
| 57 | if (!str_contains($identifier, '@')) { |
| 58 | return $this->findByUsername($identifier); |
| 59 | } |
| 60 | return $this->findByEmail($identifier); |
| 61 | } |
| 62 | |
| 63 | public function findById(EntityId $id): ?Identity |
| 64 | { |
| 65 | $identity = parent::find($id->__toString()); |
| 66 | return $identity?->toDomain(); |
| 67 | } |
| 68 | |
| 69 | public function save(Identity $identity): void |
| 70 | { |
| 71 | $doctrineEntity = $this->find($identity->getId()) ?? new DoctrineIdentity(); |
| 72 | $doctrineEntity->fromDomain($identity); |
| 73 | $this->entityManager->persist($doctrineEntity); |
| 74 | } |
| 75 | } |
Below are the source code lines that represent each code branch as identified by Xdebug. Please note a branch is not
necessarily coterminous with a line, a line may contain multiple branches and therefore show up more than once.
Please also be aware that some branches may be implicit rather than explicit, e.g. an if statement
always has an else as part of its logical flow even if you didn't write one.
| 19 | public function __construct(ManagerRegistry $managerRegistry, private readonly EntityManagerInterface $entityManager) |
| 20 | { |
| 21 | parent::__construct($managerRegistry, DoctrineIdentity::class); |
| 22 | } |
| 24 | public function findByEmail(string $email): ?Identity |
| 25 | { |
| 26 | $doctrineIdentity = parent::findOneBy(['email' => $email]); |
| 27 | if (!$doctrineIdentity) { |
| 28 | return null; |
| 30 | return $doctrineIdentity->toDomain(); |
| 31 | } |
| 42 | public function findByEmailOrUsername(string $email, string $username): ?Identity |
| 43 | { |
| 44 | $doctrineIdentity = $this->createQueryBuilder('u') |
| 45 | ->where('u.email = :email') |
| 46 | ->orWhere('u.username = :username') |
| 47 | ->setParameter('email', $email) |
| 48 | ->setParameter('username', $username) |
| 49 | ->getQuery() |
| 50 | ->getOneOrNullResult(); |
| 51 | |
| 52 | return $doctrineIdentity ? $doctrineIdentity->toDomain() : null; |
| 52 | return $doctrineIdentity ? $doctrineIdentity->toDomain() : null; |
| 52 | return $doctrineIdentity ? $doctrineIdentity->toDomain() : null; |
| 52 | return $doctrineIdentity ? $doctrineIdentity->toDomain() : null; |
| 53 | } |
| 63 | public function findById(EntityId $id): ?Identity |
| 64 | { |
| 65 | $identity = parent::find($id->__toString()); |
| 66 | return $identity?->toDomain(); |
| 67 | } |
| 55 | public function findByIdentifier(string $identifier): ?Identity |
| 56 | { |
| 57 | if (!str_contains($identifier, '@')) { |
| 57 | if (!str_contains($identifier, '@')) { |
| 57 | if (!str_contains($identifier, '@')) { |
| 57 | if (!str_contains($identifier, '@')) { |
| 58 | return $this->findByUsername($identifier); |
| 60 | return $this->findByEmail($identifier); |
| 61 | } |
| 33 | public function findByUsername(string $username): ?Identity |
| 34 | { |
| 35 | $doctrineIdentity = parent::findOneBy(['username' => $username]); |
| 36 | if (!$doctrineIdentity) { |
| 37 | return null; |
| 39 | return $doctrineIdentity->toDomain(); |
| 40 | } |
| 69 | public function save(Identity $identity): void |
| 70 | { |
| 71 | $doctrineEntity = $this->find($identity->getId()) ?? new DoctrineIdentity(); |
| 72 | $doctrineEntity->fromDomain($identity); |
| 73 | $this->entityManager->persist($doctrineEntity); |
| 74 | } |
| 3 | namespace App\Auth\Infrastructure\Persistence\Doctrine\Repository; |
| 4 | |
| 5 | use App\Auth\Domain\Model\Identity; |
| 6 | use App\Auth\Domain\Port\Driven\IdentityRepository; |
| 7 | use App\Auth\Infrastructure\Persistence\Doctrine\Entity\DoctrineIdentity; |
| 8 | use App\Shared\Domain\Model\EntityId; |
| 9 | use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
| 10 | use Doctrine\ORM\EntityManagerInterface; |
| 11 | use Doctrine\Persistence\ManagerRegistry; |
| 12 | |
| 13 | /** |
| 14 | * @author Wilhelm Zwertvaegher |
| 15 | * @extends ServiceEntityRepository<DoctrineIdentity> |
| 16 | */ |
| 17 | class DoctrineIdentityRepository extends ServiceEntityRepository implements IdentityRepository |
| 18 | { |
| 19 | public function __construct(ManagerRegistry $managerRegistry, private readonly EntityManagerInterface $entityManager) |
| 20 | { |
| 21 | parent::__construct($managerRegistry, DoctrineIdentity::class); |
| 22 | } |
| 23 | |
| 24 | public function findByEmail(string $email): ?Identity |
| 25 | { |
| 26 | $doctrineIdentity = parent::findOneBy(['email' => $email]); |
| 27 | if (!$doctrineIdentity) { |
| 28 | return null; |
| 29 | } |
| 30 | return $doctrineIdentity->toDomain(); |
| 31 | } |
| 32 | |
| 33 | public function findByUsername(string $username): ?Identity |
| 34 | { |
| 35 | $doctrineIdentity = parent::findOneBy(['username' => $username]); |
| 36 | if (!$doctrineIdentity) { |
| 37 | return null; |
| 38 | } |
| 39 | return $doctrineIdentity->toDomain(); |
| 40 | } |
| 41 | |
| 42 | public function findByEmailOrUsername(string $email, string $username): ?Identity |
| 43 | { |
| 44 | $doctrineIdentity = $this->createQueryBuilder('u') |
| 45 | ->where('u.email = :email') |
| 46 | ->orWhere('u.username = :username') |
| 47 | ->setParameter('email', $email) |
| 48 | ->setParameter('username', $username) |
| 49 | ->getQuery() |
| 50 | ->getOneOrNullResult(); |
| 51 | |
| 52 | return $doctrineIdentity ? $doctrineIdentity->toDomain() : null; |
| 53 | } |
| 54 | |
| 55 | public function findByIdentifier(string $identifier): ?Identity |
| 56 | { |
| 57 | if (!str_contains($identifier, '@')) { |
| 58 | return $this->findByUsername($identifier); |
| 59 | } |
| 60 | return $this->findByEmail($identifier); |
| 61 | } |
| 62 | |
| 63 | public function findById(EntityId $id): ?Identity |
| 64 | { |
| 65 | $identity = parent::find($id->__toString()); |
| 66 | return $identity?->toDomain(); |
| 67 | } |
| 68 | |
| 69 | public function save(Identity $identity): void |
| 70 | { |
| 71 | $doctrineEntity = $this->find($identity->getId()) ?? new DoctrineIdentity(); |
| 72 | $doctrineEntity->fromDomain($identity); |
| 73 | $this->entityManager->persist($doctrineEntity); |
| 74 | } |