Password::setValueFromRequest()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
ccs 3
cts 3
cp 1
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php 
2
3
namespace Helmut\Forms\Fields\Password;
4
5
use Helmut\Forms\Field;
6
use Helmut\Forms\Utility\Validate;
7
8
class Password extends Field {
9
10
    protected $value = '';
11 3
12 View Code Duplication
    public function hash($value) 
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13 3
    {
14 1
        if (strlen($value) === 0) {
15
            return '';
16
        }
17 3
18
        return password_hash($value, PASSWORD_BCRYPT, ['cost' => 10]);
19
    }
20
21
    public function needsRehash($hash = null)
22
    {
23
        if (is_null($hash)) {
24
            $hash = $this->value;
25
        }
26
27 1
        return password_needs_rehash($hash, PASSWORD_BCRYPT, ['cost' => 10]);
28
    }   
29 1
30 1
    public function matches($hash)
31
    {
32
        if (strlen($hash) === 0) {
33 1
            return false;
34
        }
35 1
36
        $check = $this->form->getRequest()->get($this->name);
37
38 5
        return password_verify($check, $hash);
39
    }
40 5
41
    public function getValue()
42
    {
43 3
        return $this->value;
44
    }
45 3
46
    public function getButtonName()
47
    {
48 10
        //
49
    }
50 10
51
    public function renderWith()
52
    {
53 10
        //
54
    }
55
56 10
    public function setValueFromDefault()
57
    {
58 1
        //
59
    }
60 1
61 1
    public function setValueFromModel($model)
62
    {
63 3
        if (isset($model->{$this->name})) {
64
            $this->value = $model->{$this->name};
65 3
        }
66 3
    }
67
68 4
    public function setValueFromRequest($request)
69
    {
70 4
        $this->value = $this->hash($request->get($this->name));
71 4
    }
72
73 1
    public function fillModelWithValue($model)
74
    {
75 1
        if (isset($model->{$this->name})) {
76
            $model->{$this->name} = $this->value;
77
        }
78
    }   
79
    
80
    public function validateRequired()
81
    {
82
        return Validate::required($this->value);
83
    }
84
85
}