PasswordObserver   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 13
c 1
b 0
f 0
dl 0
loc 38
ccs 13
cts 13
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A updating() 0 17 3
A creating() 0 3 1
A hash() 0 10 2
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
}