Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
75.00% |
9 / 12 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| FamilyStoreService | |
75.00% |
9 / 12 |
|
0.00% |
0 / 1 |
2.06 | |
0.00% |
0 / 1 |
| store | |
75.00% |
9 / 12 |
|
0.00% |
0 / 1 |
2.06 | |||
| 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 Domain\Category\DTOs\FamilyDTO; |
| 9 | use Domain\Integration\Services\IntegrationStoreService; |
| 10 | use Illuminate\Support\Facades\DB; |
| 11 | use Throwable; |
| 12 | |
| 13 | class FamilyStoreService |
| 14 | { |
| 15 | |
| 16 | /** |
| 17 | * @param FamilyDTO $familyDTO |
| 18 | * @param User $user |
| 19 | * @return Family |
| 20 | * @throws Throwable |
| 21 | */ |
| 22 | public function store(FamilyDTO $familyDTO, User $user): Family |
| 23 | { |
| 24 | |
| 25 | try { |
| 26 | DB::beginTransaction(); |
| 27 | |
| 28 | $family = new Family(); |
| 29 | $family->fill($familyDTO->toArray()); |
| 30 | $family->origin()->associate($familyDTO->origin); |
| 31 | $family->save(); |
| 32 | |
| 33 | (new IntegrationStoreService)->store($familyDTO->integrationFamilyDTO, $family, $user); |
| 34 | |
| 35 | DB::commit(); |
| 36 | } catch (Throwable $exception) { |
| 37 | DB::rollBack(); |
| 38 | throw $exception; |
| 39 | } |
| 40 | |
| 41 | ServiceProcessed::dispatch(self::class, $user); |
| 42 | return $family; |
| 43 | } |
| 44 | } |