UserRepository   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 25
c 0
b 0
f 0
dl 0
loc 76
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A flush() 0 3 1
A remove() 0 3 1
A __construct() 0 3 1
A existWithEmail() 0 11 1
A save() 0 4 1
A findOneByUuid() 0 7 1
A existWithUsername() 0 11 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\Doctrine\Repository;
15
16
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
0 ignored issues
show
Bug introduced by
The type Doctrine\Bundle\Doctrine...ServiceEntityRepository was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Doctrine\ORM\NonUniqueResultException;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\NonUniqueResultException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use Doctrine\ORM\OptimisticLockException;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\OptimisticLockException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use Doctrine\ORM\ORMException;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\ORMException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Doctrine\Persistence\ManagerRegistry;
0 ignored issues
show
Bug introduced by
The type Doctrine\Persistence\ManagerRegistry was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use User\Infrastructure\Doctrine\Entity\User;
22
23
/**
24
 * @method User|null find($id, $lockMode = null, $lockVersion = null)
25
 * @method User|null findOneBy(array $criteria, array $orderBy = null)
26
 * @method User[]    findAll()
27
 * @method User[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
28
 */
29
class UserRepository extends ServiceEntityRepository
30
{
31
    public function __construct(ManagerRegistry $registry)
32
    {
33
        parent::__construct($registry, User::class);
34
    }
35
36
    /**
37
     * @throws NonUniqueResultException
38
     */
39
    final public function existWithUsername(string $username): bool
40
    {
41
        $statement = $this->createQueryBuilder('u')
42
            ->select(['1'])
43
            ->where('u.username = :username')
44
            ->setParameter('username', $username)
45
            ->getQuery()
46
            ->getOneOrNullResult()
47
        ;
48
49
        return null !== $statement;
50
    }
51
52
    /**
53
     * @throws NonUniqueResultException
54
     */
55
    final public function existWithEmail(string $email): bool
56
    {
57
        $statement = $this->createQueryBuilder('u')
58
            ->select(['1'])
59
            ->where('u.email = :email')
60
            ->setParameter('email', $email)
61
            ->getQuery()
62
            ->getOneOrNullResult()
63
        ;
64
65
        return null !== $statement;
66
    }
67
68
    /**
69
     * @throws ORMException
70
     * @throws OptimisticLockException
71
     */
72
    final public function save(User $user): void
73
    {
74
        $this->getEntityManager()->persist($user);
75
        $this->getEntityManager()->flush();
76
    }
77
78
    /**
79
     * @throws OptimisticLockException
80
     * @throws ORMException
81
     */
82
    public function flush(): void
83
    {
84
        $this->getEntityManager()->flush();
85
    }
86
87
    /**
88
     * @throws ORMException
89
     */
90
    final public function remove(User $user): void
91
    {
92
        $this->getEntityManager()->remove($user);
93
    }
94
95
    /**
96
     * @throws NonUniqueResultException
97
     */
98
    final public function findOneByUuid(string $uuid): ?User
99
    {
100
        return $this->createQueryBuilder('u')
101
            ->where('u.uuid = :uuid')
102
            ->setParameter('uuid', $uuid)
103
            ->getQuery()
104
            ->getOneOrNullResult()
105
        ;
106
    }
107
}
108