Passed
Push — develop ( 6aee1f...577144 )
by Laurent
01:44
created

DoctrineCompanyRepository   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 73
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A existsWithName() 0 11 1
A __construct() 0 3 1
A remove() 0 4 1
A save() 0 5 1
A findOneByUuid() 0 14 2
A companyExist() 0 8 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 Administration\Infrastructure\Persistence\DoctrineOrm\Repositories;
15
16
use Administration\Domain\Company\Model\Company as CompanyModel;
17
use Administration\Domain\Protocol\Repository\CompanyRepositoryProtocol;
18
use Administration\Infrastructure\Persistence\DoctrineOrm\Entities\Company;
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 DoctrineCompanyRepository extends ServiceEntityRepository implements CompanyRepositoryProtocol
26
{
27
    public function __construct(ManagerRegistry $registry)
28
    {
29
        parent::__construct($registry, Company::class);
30
    }
31
32
    /**
33
     * @throws NonUniqueResultException
34
     */
35
    final public function existsWithName(string $companyName): bool
36
    {
37
        $statement = $this->createQueryBuilder('c')
38
            ->select(['1'])
39
            ->where('c.companyName = :companyName')
40
            ->setParameter('companyName', $companyName)
41
            ->getQuery()
42
            ->getOneOrNullResult()
43
        ;
44
45
        return null !== $statement;
46
    }
47
48
    /**
49
     * @throws ORMException
50
     * @throws OptimisticLockException
51
     */
52
    final public function save(CompanyModel $company): void
53
    {
54
        $companyEntity = Company::fromModel($company);
55
        $this->getEntityManager()->persist($companyEntity);
56
        $this->getEntityManager()->flush();
57
    }
58
59
    /**
60
     * @throws ORMException
61
     */
62
    final public function remove(CompanyModel $company): void
63
    {
64
        $companyEntity = Company::fromModel($company);
65
        $this->getEntityManager()->remove($companyEntity);
66
    }
67
68
    /**
69
     * @throws NonUniqueResultException
70
     */
71
    final public function findOneByUuid(string $uuid): ?CompanyModel
72
    {
73
        $company = $this->createQueryBuilder('c')
74
            ->where('c.uuid = :uuid')
75
            ->setParameter('uuid', $uuid)
76
            ->getQuery()
77
            ->getOneOrNullResult()
78
        ;
79
80
        if (null === $company) {
81
            return null;
82
        }
83
84
        return Company::toModel($company);
85
    }
86
87
    /**
88
     * @throws NonUniqueResultException
89
     */
90
    final public function companyExist(): bool
91
    {
92
        $statement = $this->createQueryBuilder('c')
93
            ->getQuery()
94
            ->getOneOrNullResult()
95
        ;
96
97
        return null !== $statement;
98
    }
99
}
100