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
AddressChangeStatusService
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
 changeStatus
66.67% covered (warning)
66.67%
6 / 9
0.00% covered (danger)
0.00%
0 / 1
2.15
1<?php
2
3namespace Domain\Address\Services;
4
5use App\Events\ServiceProcessed;
6use App\Models\Address\Address;
7use App\Models\User;
8use Exception;
9use Illuminate\Support\Facades\DB;
10
11readonly class AddressChangeStatusService
12{
13    /**
14     * @param Address $address
15     * @param User $user
16     * @return Address
17     * @throws Exception
18     */
19    public function changeStatus(Address $address, User $user): Address
20    {
21
22        try {
23            DB::beginTransaction();
24
25            $address->setAttribute('status', !$address->getAttribute('status'));
26            $address->save();
27
28            DB::commit();
29        } catch (Exception $exception) {
30            DB::rollBack();
31            throw $exception;
32        }
33
34        ServiceProcessed::dispatch(self::class, $user);
35        return $address;
36    }
37
38}