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