Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
66.67% covered (warning)
66.67%
6 / 9
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
SyncItemsService
66.67% covered (warning)
66.67%
6 / 9
0.00% covered (danger)
0.00%
0 / 1
2.15
0.00% covered (danger)
0.00%
0 / 1
 sync
66.67% covered (warning)
66.67%
6 / 9
0.00% covered (danger)
0.00%
0 / 1
2.15
1<?php
2
3namespace Domain\Item\Services;
4
5use App\Events\ServiceProcessed;
6use App\Models\User;
7use Domain\Item\DTOs\ItemsDTO;
8use Domain\Item\Interfaces\HasItemsInterface;
9use Exception;
10use Illuminate\Support\Facades\DB;
11use Throwable;
12
13readonly 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}