PasswordObserver::creating()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php namespace Distilleries\Expendable\Observers;
2
3
use \Request;
4
use \Hash;
5
6
class PasswordObserver {
7
8 172
    public function creating($model)
9
    {
10 172
        $this->hash($model, $model->password);
11
    }
12
13
14 8
    public function updating($model)
15
    {
16 8
        $newPassword = Request::get('password');
17
18 8
        if (empty($newPassword))
19
        {
20 4
            if (empty($model->password))
21
            {
22 2
                $newPassword = $model->find($model->id)->password;
23
            } else
24
            {
25 4
                $newPassword = $model->password;
26
            }
27
28
        }
29
30 8
        $this->hash($model, $newPassword);
31
    }
32
33
34 172
    public function hash($model, $password)
35
    {
36
37
38 172
        if (Hash::needsRehash($password))
39
        {
40 6
            $model->password = Hash::make($password);
41
        } else
42
        {
43 172
            $model->password = $password;
44
        }
45
46
    }
47
}