Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| UserInfoObserver | |
0.00% |
0 / 10 |
|
0.00% |
0 / 4 |
90 | |
0.00% |
0 / 1 |
| created | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| updated | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| deleted | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| canSync | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Observers; |
| 4 | |
| 5 | use App\Http\Models\Auth\User; |
| 6 | use App\Http\Models\UserInfo; |
| 7 | use App\Jobs\ProcessUserInfoAsyncJob; |
| 8 | use App\Traits\ObjectMapper; |
| 9 | use Illuminate\Support\Facades\Log; |
| 10 | |
| 11 | class UserInfoObserver |
| 12 | { |
| 13 | use ObjectMapper; |
| 14 | |
| 15 | public function created(UserInfo $user): void |
| 16 | { |
| 17 | if ($this->canSync($user->user_id)) { |
| 18 | ProcessUserInfoAsyncJob::dispatch($user, 'created'); |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | public function updated(UserInfo $user): void |
| 23 | { |
| 24 | if ($this->canSync($user->user_id)) { |
| 25 | ProcessUserInfoAsyncJob::dispatch($user, 'updated'); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | public function deleted(UserInfo $user): void |
| 30 | { |
| 31 | if ($this->canSync($user->user_id)) { |
| 32 | Log::info('User Info deleted: ' . $user->email); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | private function canSync(string $userId) |
| 37 | { |
| 38 | $user = User::find($userId); |
| 39 | |
| 40 | if (!$user) { |
| 41 | return false; |
| 42 | } |
| 43 | |
| 44 | return $user->status !== 'Deactivated' && empty($user->deleted_at); |
| 45 | } |
| 46 | } |