GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( a0e705...a0e705 )
by Dave
43:17 queued 27:40
created

Password::allowEmptyValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
ccs 0
cts 0
cp 0
crap 2
1
<?php
2
3
namespace SleepingOwl\Admin\Form\Element;
4
5
class Password extends NamedFormElement
6
{
7
    public function __construct($path, $label = null)
8
    {
9
        parent::__construct($path, $label);
10
11
        $this->setHtmlAttributes([
12
            'class' => 'form-control',
13
            'type'  => 'password',
14
        ]);
15
    }
16
17
    /**
18
     * @var bool
19
     */
20
    protected $allowEmpty = false;
21
22
    /**
23
     * @var string
24
     */
25
    protected $view = 'form.element.password';
26
27
    /**
28
     * @param \Illuminate\Http\Request $request
29
     *
30
     * @return void
31
     */
32
    public function save(\Illuminate\Http\Request $request)
33
    {
34
        $value = $this->getValueFromModel();
35
36
        if (! $this->isAllowedEmptyValue() && $this->getModel()->exists && empty($value)) {
37
            return;
38
        }
39
40
        parent::save($request);
41
    }
42
43
    /**
44
     * Checks if value exists only inside request instance. Otherwise it'll return null, because password hash
45
     * should not be returned from model and rendered inside forms.
46
     *
47
     * @return array|mixed|null|string
48
     */
49
    public function getValueFromModel()
50
    {
51
        if (($value = $this->getValueFromRequest(request())) !== null) {
0 ignored issues
show
introduced by
The condition $value = $this->getValue...est(request()) !== null is always true.
Loading history...
52
            return $value;
53
        }
54
55
        return $this->getDefaultValue();
56
    }
57
58
    /**
59
     * @return array
60
     */
61
    public function getValidationRules()
62
    {
63
        $data = parent::getValidationRules();
64
65
        if (! $this->isAllowedEmptyValue() && $this->getModel()->exists) {
66
            foreach ($data as $field => $rules) {
67
                foreach ($rules as $i => $rule) {
68
                    if ($rule == 'required') {
69
                        unset($data[$field][$i]);
70
                    }
71
                }
72
            }
73
        }
74
75
        return $data;
76
    }
77
78
    /**
79
     * @return bool
80
     */
81
    public function isAllowedEmptyValue()
82
    {
83
        return $this->allowEmpty;
84
    }
85
86
    /**
87
     * @return $this
88
     */
89
    public function allowEmptyValue()
90
    {
91
        $this->allowEmpty = true;
92
93
        return $this;
94
    }
95
96
    /**
97
     * @return $this
98
     */
99
    public function hashWithBcrypt()
100
    {
101
        return $this->mutateValue(function ($value) {
102
            return bcrypt($value);
103
        });
104
    }
105
106
    /**
107
     * @return $this
108
     */
109
    public function hashWithMD5()
110
    {
111
        return $this->mutateValue(function ($value) {
112
            return md5($value);
113
        });
114
    }
115
116
    /**
117
     * @return $this
118
     */
119
    public function hashWithSHA1()
120
    {
121
        return $this->mutateValue(function ($value) {
122
            return sha1($value);
123
        });
124
    }
125
}
126