Total Complexity | 4 |
Total Lines | 37 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
23 | class CreateSupplierHandler implements CommandHandlerInterface |
||
24 | { |
||
25 | private DoctrineSupplierRepository $repository; |
||
26 | |||
27 | public function __construct(DoctrineSupplierRepository $repository) |
||
30 | } |
||
31 | |||
32 | public function __invoke(CreateSupplier $command): void |
||
33 | { |
||
34 | if ($this->repository->existsWithName($command->companyName()->getValue())) { |
||
35 | throw new \DomainException("Supplier with name: {$command->companyName()->getValue()} already exists."); |
||
36 | } |
||
37 | |||
38 | $supplier = $this->createSupplier($command); |
||
39 | |||
40 | $this->repository->save(SupplierEntity::fromModel($supplier)); |
||
41 | } |
||
42 | |||
43 | private function createSupplier(CreateSupplier $command): Supplier |
||
60 | ); |
||
61 | } |
||
63 |