Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| UpdateSeniorIntegrationService | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
| update | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\User\Services; |
| 4 | |
| 5 | use App\Events\ServiceProcessed; |
| 6 | use App\Models\User; |
| 7 | use Domain\Login\Integrations\AuthenticateSenior; |
| 8 | use Domain\Shared\Integrations\Senior\Exceptions\IntegrationSoapSeniorException; |
| 9 | use Domain\User\DTOs\SeniorAuthenticationDTO; |
| 10 | use Illuminate\Auth\AuthenticationException; |
| 11 | use Illuminate\Support\Facades\Crypt; |
| 12 | use SoapFault; |
| 13 | |
| 14 | readonly class UpdateSeniorIntegrationService |
| 15 | { |
| 16 | /** |
| 17 | * @paparam User $userToUpdate |
| 18 | * @param SeniorAuthenticationDTO $seniorAuthenticationDTO |
| 19 | * @param User $userToUpdate |
| 20 | * @return void SeniorAuthenticationDTO $seniorAuthenticationDTO |
| 21 | * @throws AuthenticationException |
| 22 | * @throws IntegrationSoapSeniorException |
| 23 | * @throws SoapFault |
| 24 | */ |
| 25 | public static function update(SeniorAuthenticationDTO $seniorAuthenticationDTO, User $userToUpdate): void |
| 26 | { |
| 27 | ['user' => $userSenior, 'password' => $passwordSenior] = $seniorAuthenticationDTO->toArray(); |
| 28 | |
| 29 | if ($userSenior && $passwordSenior) { |
| 30 | AuthenticateSenior::login($userSenior, $passwordSenior); |
| 31 | |
| 32 | $passordCrypt = Crypt::encryptString($passwordSenior); |
| 33 | $userCrypt = Crypt::encryptString($userSenior); |
| 34 | |
| 35 | $userToUpdate->setAttribute('integrations->senior->user', $userCrypt); |
| 36 | $userToUpdate->setAttribute('integrations->senior->password', $passordCrypt); |
| 37 | $userToUpdate->save(); |
| 38 | |
| 39 | ServiceProcessed::dispatch(self::class, $userToUpdate); |
| 40 | } |
| 41 | |
| 42 | } |
| 43 | } |