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

DoctrineSupplierRepository::remove()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 2
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\Domain\Protocol\Repository\SupplierRepositoryProtocol;
17
use Administration\Domain\Supplier\Model\Supplier as SupplierModel;
18
use Administration\Infrastructure\Finders\Exceptions\SupplierNotFound;
19
use Administration\Infrastructure\Persistence\DoctrineOrm\Entities\Supplier;
20
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...
21
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...
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 DoctrineSupplierRepository extends ServiceEntityRepository implements SupplierRepositoryProtocol
26
{
27
    public function __construct(ManagerRegistry $registry)
28
    {
29
        parent::__construct($registry, Supplier::class);
30
    }
31
32
    /**
33
     * @throws NonUniqueResultException
34
     */
35
    public function existsWithName(string $companyName): bool
36
    {
37
        $statement = $this->createQueryBuilder('ds')
38
            ->select(['1'])
39
            ->where('ds.companyName = :companyName')
40
            ->setParameter('companyName', $companyName)
41
            ->getQuery()
42
            ->getOneOrNullResult()
43
        ;
44
45
        return null !== $statement;
46
    }
47
48
    /**
49
     * @throws ORMException
50
     */
51
    public function save(SupplierModel $supplier): void
52
    {
53
        $supplierEntity = Supplier::fromModel($supplier);
54
        $this->getEntityManager()->persist($supplierEntity);
55
        $this->getEntityManager()->flush();
56
    }
57
58
    /**
59
     * @throws NonUniqueResultException
60
     */
61
    public function findOneByUuid(string $uuid): SupplierModel
62
    {
63
        $result = $this->createQueryBuilder('s')
64
            ->where('s.uuid = :uuid')
65
            ->setParameter('uuid', $uuid)
66
            ->getQuery()
67
            ->getOneOrNullResult()
68
        ;
69
70
        if (null === $result) {
71
            throw new SupplierNotFound();
72
        }
73
74
        return $result;
75
    }
76
}
77