Password   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 78
Duplicated Lines 10.26 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 8
loc 78
c 0
b 0
f 0
wmc 16
lcom 1
cbo 4
rs 10
ccs 28
cts 28
cp 1

11 Methods

Rating   Name   Duplication   Size   Complexity  
A hash() 8 8 2
A needsRehash() 0 8 2
A matches() 0 10 2
A getValue() 0 4 1
A getButtonName() 0 4 1
A renderWith() 0 4 1
A setValueFromDefault() 0 4 1
A setValueFromModel() 0 6 2
A setValueFromRequest() 0 4 1
A fillModelWithValue() 0 6 2
A validateRequired() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}