Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 17 |
| OrderRedoHandler | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 17 |
| __construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| __invoke | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 14 |
|||
| <?php | |
| declare(strict_types=1); | |
| namespace App\Order\Application\Command\Handler; | |
| use App\Order\Application\Command\OrderRedoCommandInterface; | |
| use App\Order\Application\Service\CheckIfThereAreStockUnitsInterface; | |
| use App\Order\Domain\Exception\NonStockUnitsForOrderItemException; | |
| use App\Order\Domain\Exception\OrderNotFoundException; | |
| use App\Order\Domain\Model\Order; | |
| use App\Order\Domain\ValueObject\OrderId; | |
| use App\Order\Infrastructure\Persistence\Repository\OrderRepositoryInterface; | |
| use Symfony\Component\Messenger\Handler\MessageHandlerInterface; | |
| final class OrderRedoHandler implements MessageHandlerInterface | |
| { | |
| private OrderRepositoryInterface $repository; | |
| private CheckIfThereAreStockUnitsInterface $stockChecker; | |
| public function __construct( | |
| OrderRepositoryInterface $repository, | |
| CheckIfThereAreStockUnitsInterface $stockChecker | |
| ) { | |
| $this->repository = $repository; | |
| $this->stockChecker = $stockChecker; | |
| } | |
| public function __invoke(OrderRedoCommandInterface $command): void | |
| { | |
| $originalOrder = $this->repository->get(OrderId::fromString($command->getFromOrderId())); | |
| if (!$originalOrder instanceof Order) { | |
| throw new OrderNotFoundException(sprintf('Could not find original order %s', $command->getFromOrderId())); | |
| } | |
| $stockUnits = $this->stockChecker->execute($originalOrder->items()->toArray()); | |
| if (false === $stockUnits) { | |
| throw new NonStockUnitsForOrderItemException('The order has items out of stock. Please chose another item'); | |
| } | |
| $order = Order::register( | |
| OrderId::fromString($command->getOrderId()), | |
| $originalOrder->establishment(), | |
| $originalOrder->catalogFlow(), | |
| $originalOrder->tableIdentifier(), | |
| $originalOrder->items() | |
| ); | |
| $this->repository->save($order); | |
| } | |
| } |