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

Checkbox   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 50
Duplicated Lines 18 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 77.27%

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 3
dl 9
loc 50
ccs 17
cts 22
cp 0.7727
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A value() 9 9 3
A getListView() 0 7 1
A getEditFormView() 0 9 2
A getCreateFormView() 0 6 1
A oldOrAttribute() 0 9 3

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 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
9
class Checkbox extends AbstractField
10
{
11
    use Orderable;
12
    use Nullable;
13
14 2 View Code Duplication
    public function value(Request $request)
15
    {
16 2
        $value = parent::value($request);
17 2
        if (is_null($value) && $this->isNullable()) {
18 1
            return null;
19
        }
20
21 2
        return (bool) $value;
22
    }
23
24 1
    public function getListView($model)
25
    {
26 1
        return view('jarboe::crud.fields.checkbox.list', [
27 1
            'model' => $model,
28 1
            'field' => $this,
29
        ]);
30
    }
31
32 1
    public function getEditFormView($model)
33
    {
34 1
        $template = $this->isReadonly() ? 'readonly' : 'edit';
35
36 1
        return view('jarboe::crud.fields.checkbox.'. $template, [
37 1
            'model' => $model,
38 1
            'field' => $this,
39
        ]);
40
    }
41
42 1
    public function getCreateFormView()
43
    {
44 1
        return view('jarboe::crud.fields.checkbox.create', [
45 1
            'field' => $this,
46
        ]);
47
    }
48
49
    public function oldOrAttribute($model, $locale = null)
50
    {
51
        $value = parent::oldOrAttribute($model, $locale);
52
        if ($value === 'true' || $value === 'false') {
53
            $value = $value === 'true';
54
        }
55
56
        return $value;
57
    }
58
}
59