Completed
Push — master ( 814073...4a1646 )
by Yaro
10:23 queued 02:16
created

Checkbox   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 22.5 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 9
loc 40
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A value() 0 9 3
A getListValue() 0 7 1
A getEditFormValue() 9 9 2
A getCreateFormValue() 0 6 1

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
    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 getListValue($model)
25
    {
26 1
        return view('jarboe::crud.fields.checkbox.list', [
27 1
            'model' => $model,
28 1
            'field' => $this,
29
        ]);
30
    }
31
32 1 View Code Duplication
    public function getEditFormValue($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 getCreateFormValue()
43
    {
44 1
        return view('jarboe::crud.fields.checkbox.create', [
45 1
            'field' => $this,
46
        ]);
47
    }
48
}
49