Passed
Push — develop ( eb8792...6aee1f )
by Laurent
06:12
created

DoctrineUserRepository::remove()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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 Administration\Infrastructure\Persistence\DoctrineOrm\Repositories;
15
16
use Administration\Domain\Protocol\Repository\UserRepositoryProtocol;
17
use Administration\Domain\User\Model\User;
18
use Core\Domain\Model\User as UserSymfony;
19
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...
20
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...
21
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...
22
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...
23
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...
24
25
class DoctrineUserRepository extends ServiceEntityRepository implements UserRepositoryProtocol
26
{
27
    public function __construct(ManagerRegistry $registry)
28
    {
29
        parent::__construct($registry, UserSymfony::class);
30
    }
31
32
    /**
33
     * @throws ORMException
34
     * @throws OptimisticLockException
35
     */
36
    final public function add(User $user): void
37
    {
38
        $this->getEntityManager()->persist($user);
39
        $this->getEntityManager()->flush();
40
    }
41
42
    /**
43
     * @throws ORMException
44
     */
45
    final public function remove(User $user): void
46
    {
47
        $this->getEntityManager()->remove($user);
48
    }
49
50
    /**
51
     * @throws NonUniqueResultException
52
     */
53
    final public function findOneByUuid(string $uuid): ?UserSymfony
54
    {
55
        return $this->createQueryBuilder('u')
56
            ->where('u.uuid = :uuid')
57
            ->setParameter('uuid', $uuid)
58
            ->getQuery()
59
            ->getOneOrNullResult()
60
        ;
61
    }
62
63
    /**
64
     * @throws NonUniqueResultException
65
     */
66
    final public function existWithUsername(string $username): bool
67
    {
68
        $statement = $this->createQueryBuilder('u')
69
            ->select(['1'])
70
            ->where('u.username = :username')
71
            ->setParameter('username', $username)
72
            ->getQuery()
73
            ->getOneOrNullResult()
74
        ;
75
76
        return !(null === $statement);
77
    }
78
79
    /**
80
     * @throws NonUniqueResultException
81
     */
82
    final public function existWithEmail(string $email): bool
83
    {
84
        $statement = $this->createQueryBuilder('u')
85
            ->select(['1'])
86
            ->where('u.email = :email')
87
            ->setParameter('email', $email)
88
            ->getQuery()
89
            ->getOneOrNullResult()
90
        ;
91
92
        return !(null === $statement);
93
    }
94
}
95