Passed
Push — dev5a ( 01b7fe...d46f4b )
by Ron
07:10
created

PasswordPolicy::setPolicy()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 21
ccs 0
cts 9
cp 0
crap 6
rs 9.9666
1
<?php
2
3
namespace App\Domains\Admin;
4
5
use App\User;
6
use Carbon\Carbon;
7
use Illuminate\Support\Facades\Auth;
8
use Illuminate\Support\Facades\Log;
9
10
11
class PasswordPolicy extends SettingsDomain
12
{
13
    public function setPolicy($request)
14
    {
15
        //  Update the main policy
16
        $this->updateSettings('auth.passwords.settings.expire', $request->expire);
17
18
        //  Update all users to reflect the new policy
19
        if($request->expire == 0)
20
        {
21
            User::where('password_expires', '>', NOW())->update([
22
                'password_expires' => null,
23
            ]);
24
        }
25
        else
26
        {
27
            $newExpire = Carbon::now()->addDays($request->expire);
28
            User::whereNull('password_expires')->update([
29
                'password_expires' => $newExpire,
30
            ]);
31
        }
32
33
        return true;
34
    }
35
}
36