Passed
Pull Request — develop (#169)
by
unknown
03:14 queued 01:21
created

CompanyRepository::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
c 0
b 0
f 0
nc 1
nop 1
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 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...
18
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...
19
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...
20
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...
21
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...
22
23
/**
24
 * @method Company|null find($id, $lockMode = null, $lockVersion = null)
25
 * @method Company|null findOneBy(array $criteria, array $orderBy = null)
26
 * @method Company[]    findAll()
27
 * @method Company[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
28
 */
29
class CompanyRepository extends ServiceEntityRepository
30
{
31
    public function __construct(ManagerRegistry $registry)
32
    {
33
        parent::__construct($registry, Company::class);
34
    }
35
36
    /**
37
     * @throws NonUniqueResultException
38
     */
39
    final public function existsWithName(string $name): bool
40
    {
41
        $statement = $this->createQueryBuilder('c')
42
            ->select(['1'])
43
            ->where('c.companyName = :name')
44
            ->setParameter('name', $name)
45
            ->getQuery()
46
            ->getOneOrNullResult()
47
        ;
48
49
        return !(null === $statement);
50
    }
51
52
    /**
53
     * @throws ORMException
54
     * @throws OptimisticLockException
55
     */
56
    final public function save(Company $company): void
57
    {
58
        $this->getEntityManager()->persist($company);
59
        $this->getEntityManager()->flush();
60
    }
61
62
    /**
63
     * @throws ORMException
64
     * @throws OptimisticLockException
65
     */
66
    final public function flush(): void
67
    {
68
        $this->getEntityManager()->flush();
69
    }
70
71
    /**
72
     * @throws ORMException
73
     */
74
    final public function remove(Company $company): void
75
    {
76
        $this->getEntityManager()->remove($company);
77
    }
78
79
    /**
80
     * @throws NonUniqueResultException
81
     */
82
    final public function findOneByUuid(string $uuid): ?Company
83
    {
84
        return $this->createQueryBuilder('c')
85
            ->where('c.uuid = :uuid')
86
            ->setParameter('uuid', $uuid)
87
            ->getQuery()
88
            ->getOneOrNullResult()
89
        ;
90
    }
91
92
    /**
93
     * @throws NonUniqueResultException
94
     */
95
    final public function companyExist(): bool
96
    {
97
        $statement = $this->createQueryBuilder('c')
98
            ->getQuery()
99
            ->getOneOrNullResult()
100
        ;
101
102
        return null !== $statement;
103
    }
104
}
105