DoctrineSupplierRepository::remove()   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
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
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\Infrastructure\Finders\Exceptions\SupplierNotFound;
17
use Administration\Infrastructure\Persistence\DoctrineOrm\Entities\Supplier;
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\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 Supplier|null find($id, $lockMode = null, $lockVersion = null)
25
 * @method Supplier|null findOneBy(array $criteria, array $orderBy = null)
26
 * @method Supplier[]    findAll()
27
 * @method Supplier[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
28
 */
29
class DoctrineSupplierRepository extends ServiceEntityRepository
30
{
31
    public function __construct(ManagerRegistry $registry)
32
    {
33
        parent::__construct($registry, Supplier::class);
34
    }
35
36
    /**
37
     * @throws NonUniqueResultException
38
     */
39
    public function existsWithName(string $companyName): bool
40
    {
41
        $statement = $this->createQueryBuilder('ds')
42
            ->select(['1'])
43
            ->where('ds.companyName = :companyName')
44
            ->setParameter('companyName', $companyName)
45
            ->getQuery()
46
            ->getOneOrNullResult()
47
        ;
48
49
        return null !== $statement;
50
    }
51
52
    /**
53
     * @throws ORMException
54
     */
55
    public function save(Supplier $supplier): void
56
    {
57
        $this->getEntityManager()->persist($supplier);
58
        $this->getEntityManager()->flush();
59
    }
60
61
    /**
62
     * @throws NonUniqueResultException
63
     */
64
    public function findOneByUuid(string $uuid): Supplier
65
    {
66
        $result = $this->createQueryBuilder('s')
67
            ->where('s.uuid = :uuid')
68
            ->setParameter('uuid', $uuid)
69
            ->getQuery()
70
            ->getOneOrNullResult()
71
        ;
72
73
        if (null === $result) {
74
            throw new SupplierNotFound();
75
        }
76
77
        return $result;
78
    }
79
80
    /**
81
     * @throws ORMException
82
     */
83
    final public function remove(Supplier $supplier): void
84
    {
85
        $this->getEntityManager()->remove($supplier);
86
    }
87
}
88