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