Passed
Push — develop ( 78e2d5...9c7a10 )
by Laurent
02:42 queued 01:21
created

DoctrineSupplierRepository::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
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;
18
use Administration\Infrastructure\Finders\Exceptions\SupplierNotFound;
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\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
class DoctrineSupplierRepository extends ServiceEntityRepository implements SupplierRepositoryProtocol
25
{
26
    public function __construct(ManagerRegistry $registry)
27
    {
28
        parent::__construct($registry, Supplier::class);
29
    }
30
31
    public function remove(Supplier $supplier): void
32
    {
33
        // TODO: Implement remove() method.
34
    }
35
36
    /**
37
     * @throws NonUniqueResultException
38
     */
39
    public function existsWithName(string $name): bool
40
    {
41
        $statement = $this->createQueryBuilder('ds')
42
            ->select(['1'])
43
            ->where('ds.name = :name')
44
            ->setParameter('name', $name)
45
            ->getQuery()
46
            ->getOneOrNullResult()
47
        ;
48
49
        return !(null === $statement);
50
    }
51
52
    /**
53
     * @throws ORMException
54
     */
55
    public function add(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