UserObserver::created()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Infinitypaul\LaravelPasswordHistoryValidation\Observers;
4
5
use Illuminate\Support\Arr;
6
use Infinitypaul\LaravelPasswordHistoryValidation\Models\PasswordHistoryRepo;
7
8
class UserObserver
9
{
10
    public function updated($user)
11
    {
12
        $configPasswordColumn = config('password-history.observe.column');
13
        if ($password = Arr::get($user->getChanges(), $configPasswordColumn)) {
14
            PasswordHistoryRepo::storeCurrentPasswordInHistory($password, $user->id);
15
        }
16
    }
17
18
    public function created($user)
19
    {
20
        $password = config('password-history.observe.column') ?? 'password';
21
        PasswordHistoryRepo::storeCurrentPasswordInHistory($user->{$password}, $user->id);
22
    }
23
}
24