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