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

DoctrineSupplierFinder::findOneByUuid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 21
nc 1
nop 1
dl 0
loc 25
rs 9.584
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\Finders\DoctrineOrm;
15
16
use Administration\Application\Protocol\Finders\SupplierFinderProtocol;
17
use Administration\Application\Supplier\ReadModel\Supplier as SupplierModel;
18
use Administration\Application\Supplier\ReadModel\Suppliers;
19
use Administration\Domain\Supplier\Model\Supplier;
20
use Core\Domain\Common\Model\VO\ContactUuid;
21
use Core\Domain\Common\Model\VO\EmailField;
22
use Core\Domain\Common\Model\VO\NameField;
23
use Core\Domain\Common\Model\VO\PhoneField;
24
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...
25
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...
26
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...
27
28
class DoctrineSupplierFinder extends ServiceEntityRepository implements SupplierFinderProtocol
29
{
30
    public function __construct(ManagerRegistry $registry)
31
    {
32
        parent::__construct($registry, Supplier::class);
33
    }
34
35
    /**
36
     * @throws NonUniqueResultException
37
     */
38
    public function findOneByUuid(string $uuid): SupplierModel
39
    {
40
        $result = $this->createQueryBuilder('s')
41
            ->where('s.uuid = :uuid')
42
            ->setParameter('uuid', $uuid)
43
            ->getQuery()
44
            ->getOneOrNullResult()
45
        ;
46
47
        return new SupplierModel(
48
            ContactUuid::fromString($result->getUuid()),
0 ignored issues
show
Bug introduced by
Core\Domain\Common\Model...ing($result->getUuid()) of type Core\Domain\Common\Model\VO\ContactUuid is incompatible with the type string expected by parameter $uuid of Administration\Applicati...Supplier::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

48
            /** @scrutinizer ignore-type */ ContactUuid::fromString($result->getUuid()),
Loading history...
49
            NameField::fromString($result->getName()),
0 ignored issues
show
Bug introduced by
Core\Domain\Common\Model...ing($result->getName()) of type Core\Domain\Common\Model\VO\NameField is incompatible with the type string expected by parameter $name of Administration\Applicati...Supplier::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

49
            /** @scrutinizer ignore-type */ NameField::fromString($result->getName()),
Loading history...
50
            $result->getAddress(),
51
            $result->getZipCode(),
52
            $result->getTown(),
53
            $result->getCountry(),
54
            PhoneField::fromString($result->getPhone()),
0 ignored issues
show
Bug introduced by
Core\Domain\Common\Model...ng($result->getPhone()) of type Core\Domain\Common\Model\VO\PhoneField is incompatible with the type string expected by parameter $phone of Administration\Applicati...Supplier::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

54
            /** @scrutinizer ignore-type */ PhoneField::fromString($result->getPhone()),
Loading history...
55
            PhoneField::fromString($result->getFacsimile()),
0 ignored issues
show
Bug introduced by
Core\Domain\Common\Model...result->getFacsimile()) of type Core\Domain\Common\Model\VO\PhoneField is incompatible with the type string expected by parameter $facsimile of Administration\Applicati...Supplier::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

55
            /** @scrutinizer ignore-type */ PhoneField::fromString($result->getFacsimile()),
Loading history...
56
            EmailField::fromString($result->getEmail()),
0 ignored issues
show
Bug introduced by
Core\Domain\Common\Model...ng($result->getEmail()) of type Core\Domain\Common\Model\VO\EmailField is incompatible with the type string expected by parameter $email of Administration\Applicati...Supplier::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

56
            /** @scrutinizer ignore-type */ EmailField::fromString($result->getEmail()),
Loading history...
57
            $result->getContact(),
58
            PhoneField::fromString($result->getCellphone()),
0 ignored issues
show
Bug introduced by
Core\Domain\Common\Model...result->getCellphone()) of type Core\Domain\Common\Model\VO\PhoneField is incompatible with the type string expected by parameter $cellphone of Administration\Applicati...Supplier::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

58
            /** @scrutinizer ignore-type */ PhoneField::fromString($result->getCellphone()),
Loading history...
59
            $result->getFamilyLog(),
60
            $result->getDelayDelivery(),
61
            $result->getOrderDay(),
62
            $result->getSlug()
63
        );
64
    }
65
66
    public function findAllActive(): Suppliers
67
    {
68
        $statement = $this->createQueryBuilder('s')
69
            ->where('s.active = 1')
70
            ->getQuery()
71
            ->getResult()
72
        ;
73
74
        return new Suppliers(
75
            ...\array_map(static function (Supplier $supplier) {
76
                return new SupplierModel(
77
                    $supplier->uuid(),
78
                    $supplier->name(),
79
                    $supplier->address(),
80
                    $supplier->zipCode(),
81
                    $supplier->town(),
82
                    $supplier->country(),
83
                    $supplier->phone(),
84
                    $supplier->facsimile(),
85
                    $supplier->email(),
86
                    $supplier->contact(),
87
                    $supplier->cellphone(),
88
                    $supplier->familyLog(),
89
                    $supplier->delayDelivery(),
90
                    $supplier->orderDays(),
91
                    $supplier->getSlug()
92
                );
93
            }, $statement)
94
        );
95
    }
96
}
97