Passed
Push — develop ( 577144...bf5480 )
by
unknown
01:39
created

EditSupplierHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 43
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 11 2
A updateSupplier() 0 17 1
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
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
23
class EditSupplierHandler implements CommandHandlerInterface
24
{
25
    private DoctrineSupplierRepository $repository;
26
27
    public function __construct(DoctrineSupplierRepository $repository)
28
    {
29
        $this->repository = $repository;
30
    }
31
32
    /**
33
     * @throws NonUniqueResultException
34
     * @throws ORMException
35
     */
36
    public function __invoke(EditSupplier $command): void
37
    {
38
        $supplierToUpdate = $this->repository->findOneByUuid($command->uuid()->toString());
39
40
        if (null === $supplierToUpdate) {
41
            throw new \DomainException('Supplier provided does not exist!');
42
        }
43
44
        $supplier = $this->updateSupplier($command, $supplierToUpdate);
45
46
        $this->repository->save($supplier);
47
    }
48
49
    private function updateSupplier(EditSupplier $command, SupplierEntity $supplier): SupplierEntity
50
    {
51
        $supplier->setCompanyName($command->name()->getValue());
52
        $supplier->setAddress($command->address());
53
        $supplier->setZipCode($command->zipCode());
54
        $supplier->setTown($command->town());
55
        $supplier->setCountry($command->country());
56
        $supplier->setPhone($command->phone()->getValue());
57
        $supplier->setFacsimile($command->facsimile()->getValue());
58
        $supplier->setEmail($command->email()->getValue());
59
        $supplier->setContactName($command->contactName());
60
        $supplier->setCellphone($command->cellphone()->getValue());
61
        $supplier->setFamilyLog($command->familyLog()->path());
62
        $supplier->setDelayDelivery($command->delayDelivery());
63
        $supplier->setOrderDays($command->orderDays());
64
65
        return $supplier;
66
    }
67
}
68