Completed
Pull Request — master (#14)
by
unknown
15:13 queued 07:44
created

Password::getEditFormValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Yaro\Jarboe\Table\Fields;
4
5
use Closure;
6
use Illuminate\Http\Request;
7
use Yaro\Jarboe\Table\Fields\Traits\Nullable;
8
use Yaro\Jarboe\Table\Fields\Traits\Orderable;
9
use Yaro\Jarboe\Table\Fields\Traits\Placeholder;
10
use Yaro\Jarboe\Table\Fields\Traits\Tooltip;
11
12
class Password extends AbstractField
13
{
14
    use Orderable;
15
    use Nullable;
16
    use Tooltip;
17
    use Placeholder;
18
19
    /** @var string|Closure */
20
    protected $hash = 'bcrypt';
21
22 4
    public function hash($hash)
23
    {
24 4
        if (is_object($hash) && is_a($hash, Closure::class)) {
25 1
            $this->hash = $hash;
26 1
            return $this;
27
        }
28
29 3
        if (is_string($hash) && function_exists($hash)) {
30 1
            $this->hash = $hash;
31 1
            return $this;
32
        }
33
34
        // dummy
35 2
        if (is_null($hash)) {
36
            $this->hash = function ($value) {
37 1
                return $value;
38
            };
39 1
            return $this;
40
        }
41
42 1
        throw new \RuntimeException('Hash for Password field must be valid function name or Closure');
43
    }
44
45 4
    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...
46
    {
47 4
        $hash = $this->hash;
48
49 4
        return $hash(parent::value($request));
50
    }
51
52 2
    public function shouldSkip(Request $request)
53
    {
54 2
        return !$request->get($this->name());
55
    }
56
57 1
    public function getListView($model)
58
    {
59 1
        return view('jarboe::crud.fields.password.list', [
60 1
            'model' => $model,
61 1
            'field' => $this,
62
        ]);
63
    }
64
65 1
    public function getEditFormView($model)
66
    {
67 1
        $template = $this->isReadonly() ? 'readonly' : 'edit';
68
69 1
        return view('jarboe::crud.fields.password.'. $template, [
70 1
            'model' => $model,
71 1
            'field' => $this,
72
        ]);
73
    }
74
75 1
    public function getCreateFormView()
76
    {
77 1
        return view('jarboe::crud.fields.password.create', [
78 1
            'field' => $this,
79
        ]);
80
    }
81
}
82