Passed
Push — feat/create-company-bounded-co... ( d79552...d47591 )
by
unknown
01:42
created

EditSupplierHandler::updateSupplier()   A

Complexity

Conditions 5
Paths 16

Size

Total Lines 27
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 19
nc 16
nop 2
dl 0
loc 27
rs 9.3222
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\Domain\Supplier\Handler;
15
16
use Administration\Domain\Supplier\Command\EditSupplier;
17
use Administration\Infrastructure\Persistence\DoctrineOrm\Entities\Supplier as SupplierEntity;
18
use Administration\Infrastructure\Persistence\DoctrineOrm\Repositories\DoctrineSupplierRepository;
19
use Core\Domain\Protocol\Common\Command\CommandHandlerInterface;
20
21
class EditSupplierHandler implements CommandHandlerInterface
22
{
23
    private DoctrineSupplierRepository $repository;
24
25
    public function __construct(DoctrineSupplierRepository $repository)
26
    {
27
        $this->repository = $repository;
28
    }
29
30
    public function __invoke(EditSupplier $command): void
31
    {
32
        $supplierToUpdate = $this->repository->findOneByUuid($command->uuid()->toString());
33
34
        if (null === $supplierToUpdate) {
35
            throw new \DomainException('Supplier provided does not exist!');
36
        }
37
38
        $supplier = $this->updateSupplier($command, $supplierToUpdate);
39
40
        $this->repository->save($supplier);
41
    }
42
43
    private function updateSupplier(EditSupplier $command, SupplierEntity $supplier): SupplierEntity
44
    {
45
        $supplier->setCompanyName($command->name()->getValue());
46
        $supplier->setAddress($command->address());
47
        $supplier->setZipCode($command->zipCode());
48
        $supplier->setTown($command->town());
49
        $supplier->setCountry($command->country());
50
        $supplier->setPhone($command->phone()->getValue());
51
        $supplier->setFacsimile($command->facsimile()->getValue());
52
        $supplier->setEmail($command->email()->getValue());
53
        $supplier->setContactName($command->contact());
54
        $supplier->setCellphone($command->cellPhone()->getValue());
55
56
        if ($supplier->cellPhone() !== $command->cellPhone()->getValue()) {
0 ignored issues
show
Bug introduced by
The method cellPhone() does not exist on Administration\Infrastru...neOrm\Entities\Supplier. ( Ignorable by Annotation )

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

56
        if ($supplier->/** @scrutinizer ignore-call */ cellPhone() !== $command->cellPhone()->getValue()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
57
            $supplier->changeCellphoneNumber($command->cellPhone());
0 ignored issues
show
Bug introduced by
The method changeCellphoneNumber() does not exist on Administration\Infrastru...neOrm\Entities\Supplier. ( Ignorable by Annotation )

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

57
            $supplier->/** @scrutinizer ignore-call */ 
58
                       changeCellphoneNumber($command->cellPhone());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
58
        }
59
        if ($supplier->familyLog() !== $command->familyLog()->path()) {
0 ignored issues
show
Bug introduced by
The method familyLog() does not exist on Administration\Infrastru...neOrm\Entities\Supplier. ( Ignorable by Annotation )

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

59
        if ($supplier->/** @scrutinizer ignore-call */ familyLog() !== $command->familyLog()->path()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
60
            $supplier->reassignFamilyLog($command->familyLog());
0 ignored issues
show
Bug introduced by
The method reassignFamilyLog() does not exist on Administration\Infrastru...neOrm\Entities\Supplier. ( Ignorable by Annotation )

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

60
            $supplier->/** @scrutinizer ignore-call */ 
61
                       reassignFamilyLog($command->familyLog());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
        }
62
        if ($supplier->delayDelivery() !== $command->delayDelivery()) {
0 ignored issues
show
Bug introduced by
The method delayDelivery() does not exist on Administration\Infrastru...neOrm\Entities\Supplier. ( Ignorable by Annotation )

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

62
        if ($supplier->/** @scrutinizer ignore-call */ delayDelivery() !== $command->delayDelivery()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
63
            $supplier->changeDelayDelivery($command->delayDelivery());
0 ignored issues
show
Bug introduced by
The method changeDelayDelivery() does not exist on Administration\Infrastru...neOrm\Entities\Supplier. ( Ignorable by Annotation )

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

63
            $supplier->/** @scrutinizer ignore-call */ 
64
                       changeDelayDelivery($command->delayDelivery());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
64
        }
65
        if ($supplier->orderDays() !== $command->orderDays()) {
0 ignored issues
show
Bug introduced by
The method orderDays() does not exist on Administration\Infrastru...neOrm\Entities\Supplier. ( Ignorable by Annotation )

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

65
        if ($supplier->/** @scrutinizer ignore-call */ orderDays() !== $command->orderDays()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
66
            $supplier->reassignOrderDays($command->orderDays());
0 ignored issues
show
Bug introduced by
The method reassignOrderDays() does not exist on Administration\Infrastru...neOrm\Entities\Supplier. ( Ignorable by Annotation )

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

66
            $supplier->/** @scrutinizer ignore-call */ 
67
                       reassignOrderDays($command->orderDays());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67
        }
68
69
        return $supplier;
70
    }
71
}
72