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