Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ItemDeleteService | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| delete | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\Item\Services; |
| 4 | |
| 5 | use App\Events\ServiceProcessed; |
| 6 | use App\Models\Item\Item; |
| 7 | use App\Models\User; |
| 8 | use Domain\Integration\Services\IntegrationDeleteService; |
| 9 | use Illuminate\Support\Facades\DB; |
| 10 | use Throwable; |
| 11 | |
| 12 | readonly class ItemDeleteService |
| 13 | { |
| 14 | /** |
| 15 | * @param Item $item |
| 16 | * @param User $user |
| 17 | * @return Item |
| 18 | * @throws Throwable |
| 19 | */ |
| 20 | public function delete(Item $item, User $user): Item |
| 21 | { |
| 22 | try { |
| 23 | DB::beginTransaction(); |
| 24 | |
| 25 | (new IntegrationDeleteService())->delete($item->integration, $user); |
| 26 | $item->delete(); |
| 27 | |
| 28 | DB::commit(); |
| 29 | } catch (Throwable $throwable) { |
| 30 | DB::rollBack(); |
| 31 | throw $throwable; |
| 32 | } |
| 33 | |
| 34 | ServiceProcessed::dispatch(self::class, $user); |
| 35 | return $item; |
| 36 | } |
| 37 | } |