Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
66.67% |
6 / 9 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| SyncItemsService | |
66.67% |
6 / 9 |
|
0.00% |
0 / 1 |
2.15 | |
0.00% |
0 / 1 |
| sync | |
66.67% |
6 / 9 |
|
0.00% |
0 / 1 |
2.15 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\Item\Services; |
| 4 | |
| 5 | use App\Events\ServiceProcessed; |
| 6 | use App\Models\User; |
| 7 | use Domain\Item\DTOs\ItemsDTO; |
| 8 | use Domain\Item\Interfaces\HasItemsInterface; |
| 9 | use Exception; |
| 10 | use Illuminate\Support\Facades\DB; |
| 11 | use Throwable; |
| 12 | |
| 13 | readonly class SyncItemsService |
| 14 | { |
| 15 | /** |
| 16 | * @param ItemsDTO $itemsDTO |
| 17 | * @param HasItemsInterface $hasItems |
| 18 | * @param User $user |
| 19 | * @return void |
| 20 | * @throws Exception |
| 21 | * @throws Throwable |
| 22 | */ |
| 23 | public function sync(ItemsDTO $itemsDTO, HasItemsInterface $hasItems, User $user): void |
| 24 | { |
| 25 | try { |
| 26 | DB::beginTransaction(); |
| 27 | |
| 28 | $productsHandler = new ProductsItemsHandler; |
| 29 | $productsHandler->setNext(new StorageItemsHandler); |
| 30 | |
| 31 | $productsHandler->handle($itemsDTO, $hasItems, $user); |
| 32 | |
| 33 | DB::commit(); |
| 34 | } catch (Exception $exception) { |
| 35 | DB::rollBack(); |
| 36 | throw $exception; |
| 37 | } |
| 38 | |
| 39 | ServiceProcessed::dispatch(self::class, $user); |
| 40 | } |
| 41 | } |