Completed
Push — master ( 72a246...6ab249 )
by Helmut
05:19
created

NewPassword::setValueFromRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php 
2
3
namespace Helmut\Forms\Fields\NewPassword;
4
5
use Helmut\Forms\Field;
6
use Helmut\Forms\Utility\Validate;
7
8
class NewPassword extends Field {
9
10
    protected $value = '';
11
    protected $value_confirmation = '';
12
13 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...
14
    {
15
        if (strlen($value) === 0) {
16
            return '';
17
        }
18
19
        return password_hash($value, PASSWORD_BCRYPT, ['cost' => 10]);
20
    }
21
22
    public function getValue()
23
    {
24
        $values = [];
25
        $values[$this->name] = $this->value;
26
        $values[$this->name.'_confirmation'] = $this->value_confirmation;
27
        return $values;
28
    }
29
30
    public function getButtonName()
31
    {
32
        //
33
    }
34
35
    public function renderWith()
36
    {
37
        return [    
38
            'name' => $this->name, 
39
            'name_confirmation' => $this->name.'_confirmation', 
40
            'value' => $this->value,
41
            'value_confirmation' => $this->value_confirmation,
42
        ];
43
    }
44
45
    public function setValueFromDefault()
46
    {
47
        //
48
    }
49
50
    public function setValueFromModel($model)
51
    {
52
        //
53
    }
54
55
    public function setValueFromRequest($request)
56
    {
57
        $this->value = $request->get($this->name);
58
        $this->value_confirmation = $request->get($this->name.'_confirmation');
59
    }
60
61
    public function fillModelWithValue($model)
62
    {
63
        if (property_exists($model, $this->name)) {
64
            $model->{$this->name} = $this->hash($this->value);
65
        }
66
    }
67
68
    public function validate()
69
    {
70
        $this->matches();
0 ignored issues
show
Bug introduced by
The method matches() does not exist on Helmut\Forms\Fields\NewPassword\NewPassword. Did you maybe mean validateMatches()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
71
    }
72
73
    public function validateMatches()
74
    {
75
        return Validate::matches($this->value, $this->value_confirmation);
76
    }    
77
    
78
    public function validateRequired()
79
    {
80
        return Validate::required($this->value);
81
    }
82
83
}