Completed
Push — master ( 51084e...d852c9 )
by Yaro
07:57
created

Password   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 45.16%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 6
dl 0
loc 69
ccs 14
cts 31
cp 0.4516
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
B hash() 0 22 6
A value() 0 6 1
A shouldSkip() 0 4 1
A getListValue() 0 7 1
A getEditFormValue() 0 9 2
A getCreateFormValue() 0 6 1
1
<?php
2
3
namespace Yaro\Jarboe\Table\Fields;
4
5
use Illuminate\Http\Request;
6
use Yaro\Jarboe\Table\Fields\Traits\Nullable;
7
use Yaro\Jarboe\Table\Fields\Traits\Orderable;
8
use Yaro\Jarboe\Table\Fields\Traits\Placeholder;
9
use Yaro\Jarboe\Table\Fields\Traits\Tooltip;
10
11
class Password extends AbstractField
12
{
13
    use Orderable;
14
    use Nullable;
15
    use Tooltip;
16
    use Placeholder;
17
18
    protected $hash = 'bcrypt';
19
20 3
    public function hash($hash)
21
    {
22 3
        if (is_object($hash) && is_a($hash, \Closure::class)) {
23 1
            $this->hash = $hash;
0 ignored issues
show
Documentation Bug introduced by
It seems like $hash of type object is incompatible with the declared type string of property $hash.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
24 1
            return $this;
25
        }
26
27 2
        if (is_string($hash) && function_exists($hash)) {
28 1
            $this->hash = $hash;
29 1
            return $this;
30
        }
31
32
        // dummy
33 1
        if (is_null($hash)) {
34
            $this->hash = function($value) {
0 ignored issues
show
Documentation Bug introduced by
It seems like function ($value) { return $value; } of type object<Closure> is incompatible with the declared type string of property $hash.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
35
                return $value;
36
            };
37
            return $this;
38
        }
39
40 1
        throw new \RuntimeException('Hash for PasswordField must be valid function name or closure');
41
    }
42
43 3
    public function value(Request $request)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
44
    {
45 3
        $hash = $this->hash;
46
47 3
        return $hash(parent::value($request));
48
    }
49
50 2
    public function shouldSkip(Request $request)
51
    {
52 2
        return !$request->get($this->name());
53
    }
54
55
    public function getListValue($model)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
56
    {
57
        return view('jarboe::crud.fields.password.list', [
58
            'model' => $model,
59
            'field' => $this,
60
        ])->render();
61
    }
62
63
    public function getEditFormValue($model)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
64
    {
65
        $template = $this->isReadonly() ? 'readonly' : 'edit';
66
67
        return view('jarboe::crud.fields.password.'. $template, [
68
            'model' => $model,
69
            'field' => $this,
70
        ])->render();
71
    }
72
73
    public function getCreateFormValue()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
74
    {
75
        return view('jarboe::crud.fields.password.create', [
76
            'field' => $this,
77
        ])->render();
78
    }
79
}
80