Passed
Push — dev5a ( d46f4b...f24c41 )
by Ron
07:14
created

PasswordPolicy::setPolicy()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

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 9
cts 9
cp 1
crap 2
rs 9.9666
1
<?php
2
3
namespace App\Domains\Admin;
4
5
use App\User;
6
use Carbon\Carbon;
7
8
class PasswordPolicy extends SettingsDomain
9
{
10 6
    public function setPolicy($request)
11
    {
12
        //  Update the main policy
13 6
        $this->updateSettings('auth.passwords.settings.expire', $request->expire);
14
15
        //  Update all users to reflect the new policy
16 6
        if($request->expire == 0)
17
        {
18 2
            User::where('password_expires', '>', NOW())->update([
19 2
                'password_expires' => null,
20
            ]);
21
        }
22
        else
23
        {
24 4
            $newExpire = Carbon::now()->addDays($request->expire);
25 4
            User::whereNull('password_expires')->update([
26 4
                'password_expires' => $newExpire,
27
            ]);
28
        }
29
30 6
        return true;
31
    }
32
}
33