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.
Passed
Push — master ( b2510c...ee0bb8 )
by
unknown
12:46
created

Password::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
ccs 0
cts 7
cp 0
crap 2
rs 9.6666
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() and $this->getModel()->exists and empty($value)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
37
            return;
38
        }
39
40
        parent::save($request);
41
    }
42
43
    /**
44
     * @return array
45
     */
46
    public function getValidationRules()
47
    {
48
        $data = parent::getValidationRules();
49
50
        if (! $this->isAllowedEmptyValue() and $this->getModel()->exists) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
51
            foreach ($data as $field => $rules) {
52
                foreach ($rules as $i => $rule) {
53
                    if ($rule == 'required') {
54
                        unset($data[$field][$i]);
55
                    }
56
                }
57
            }
58
        }
59
60
        return $data;
61
    }
62
63
    /**
64
     * @return bool
65
     */
66
    public function isAllowedEmptyValue()
67
    {
68
        return $this->allowEmpty;
69
    }
70
71
    /**
72
     * @return $this
73
     */
74
    public function allowEmptyValue()
75
    {
76
        $this->allowEmpty = true;
77
78
        return $this;
79
    }
80
81
    /**
82
     * @return $this
83
     */
84
    public function hashWithBcrypt()
85
    {
86
        return $this->mutateValue(function ($value) {
87
            return bcrypt($value);
88
        });
89
    }
90
91
    /**
92
     * @return $this
93
     */
94
    public function hashWithMD5()
95
    {
96
        return $this->mutateValue(function ($value) {
97
            return md5($value);
98
        });
99
    }
100
101
    /**
102
     * @return $this
103
     */
104
    public function hashWithSHA1()
105
    {
106
        return $this->mutateValue(function ($value) {
107
            return sha1($value);
108
        });
109
    }
110
}
111