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