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