CompanyRepository::flush()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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 Company\Infrastructure\Doctrine\Repository;
15
16
use Company\Infrastructure\Doctrine\Entity\Company;
17
use Core\Domain\Common\Model\VO\ResourceUuidInterface;
18
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...
19
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...
20
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...
21
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...
22
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...
23
24
/**
25
 * @method Company|null find($id, $lockMode = null, $lockVersion = null)
26
 * @method Company|null findOneBy(array $criteria, array $orderBy = null)
27
 * @method Company[]    findAll()
28
 * @method Company[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
29
 */
30
class CompanyRepository extends ServiceEntityRepository
31
{
32
    public function __construct(ManagerRegistry $registry)
33
    {
34
        parent::__construct($registry, Company::class);
35
    }
36
37
    /**
38
     * @throws ORMException
39
     * @throws OptimisticLockException
40
     */
41
    final public function save(Company $company): void
42
    {
43
        $this->getEntityManager()->persist($company);
44
        $this->flush();
45
    }
46
47
    /**
48
     * @throws ORMException
49
     * @throws OptimisticLockException
50
     */
51
    final public function flush(): void
52
    {
53
        $this->getEntityManager()->flush();
54
    }
55
56
    /**
57
     * @throws ORMException
58
     */
59
    final public function remove(Company $company): void
60
    {
61
        $this->getEntityManager()->remove($company);
62
    }
63
64
    /**
65
     * @throws NonUniqueResultException
66
     */
67
    final public function findOneByUuid(ResourceUuidInterface $uuid): ?Company
68
    {
69
        return $this->createQueryBuilder('c')
70
            ->where('c.uuid = :uuid')
71
            ->setParameter('uuid', $uuid)
72
            ->getQuery()
73
            ->getOneOrNullResult()
74
        ;
75
    }
76
77
    /**
78
     * @throws NonUniqueResultException
79
     */
80
    final public function companyExist(): bool
81
    {
82
        $statement = $this->createQueryBuilder('c')
83
            ->getQuery()
84
            ->getOneOrNullResult()
85
        ;
86
87
        return null !== $statement;
88
    }
89
}
90