|
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()) { |
|
|
|
|
|
|
57
|
|
|
$supplier->changeCellphoneNumber($command->cellPhone()); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
if ($supplier->familyLog() !== $command->familyLog()->path()) { |
|
|
|
|
|
|
60
|
|
|
$supplier->reassignFamilyLog($command->familyLog()); |
|
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
if ($supplier->delayDelivery() !== $command->delayDelivery()) { |
|
|
|
|
|
|
63
|
|
|
$supplier->changeDelayDelivery($command->delayDelivery()); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
if ($supplier->orderDays() !== $command->orderDays()) { |
|
|
|
|
|
|
66
|
|
|
$supplier->reassignOrderDays($command->orderDays()); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return $supplier; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
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.