Passed
Push — master ( 97042f...0d0c81 )
by Yaro
13:28
created

Textarea   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 79
Duplicated Lines 37.97 %

Coupling/Cohesion

Components 2
Dependencies 10

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 13
lcom 2
cbo 10
dl 30
loc 79
ccs 30
cts 30
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A expandable() 0 6 1
A isExpandable() 0 4 1
A resizable() 0 6 1
A isResizable() 0 4 1
A value() 9 9 4
A getListView() 12 12 2
A getEditFormView() 9 9 2
A getCreateFormView() 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\Clipboard;
7
use Yaro\Jarboe\Table\Fields\Traits\Inline;
8
use Yaro\Jarboe\Table\Fields\Traits\Maxlength;
9
use Yaro\Jarboe\Table\Fields\Traits\Nullable;
10
use Yaro\Jarboe\Table\Fields\Traits\Orderable;
11
use Yaro\Jarboe\Table\Fields\Traits\Placeholder;
12
use Yaro\Jarboe\Table\Fields\Traits\Rows;
13
use Yaro\Jarboe\Table\Fields\Traits\Tooltip;
14
use Yaro\Jarboe\Table\Fields\Traits\Translatable;
15
16
class Textarea extends AbstractField
17
{
18
    use Orderable;
19
    use Nullable;
20
    use Tooltip;
21
    use Clipboard;
22
    use Inline;
23
    use Translatable;
24
    use Placeholder;
25
    use Maxlength;
26
    use Rows;
27
28
    protected $expandable = false;
29
    protected $resizable = false;
30
31 1
    public function expandable(bool $expandable = true)
32
    {
33 1
        $this->expandable = $expandable;
34
35 1
        return $this;
36
    }
37
38 2
    public function isExpandable()
39
    {
40 2
        return $this->expandable;
41
    }
42
43 1
    public function resizable(bool $resizable = true)
44
    {
45 1
        $this->resizable = $resizable;
46
47 1
        return $this;
48
    }
49
50 2
    public function isResizable()
51
    {
52 2
        return $this->resizable;
53
    }
54
55 3 View Code Duplication
    public function value(Request $request)
56
    {
57 3
        $value = parent::value($request);
58 3
        if (is_null($value) && $this->isNullable()) {
59 1
            return null;
60
        }
61
62 3
        return is_array($value) ? $value : (string) $value;
63
    }
64
65 2 View Code Duplication
    public function getListView($model)
66
    {
67 2
        $template = 'list';
68 2
        if ($this->isTranslatable()) {
69 1
            $template .= '_translatable';
70
        }
71
72 2
        return view('jarboe::crud.fields.textarea.'. $template, [
73 2
            'model' => $model,
74 2
            'field' => $this,
75
        ]);
76
    }
77
78 1 View Code Duplication
    public function getEditFormView($model)
79
    {
80 1
        $template = $this->isReadonly() ? 'readonly' : 'edit';
81
82 1
        return view('jarboe::crud.fields.textarea.'. $template, [
83 1
            'model' => $model,
84 1
            'field' => $this,
85
        ]);
86
    }
87
88 1
    public function getCreateFormView()
89
    {
90 1
        return view('jarboe::crud.fields.textarea.create', [
91 1
            'field' => $this,
92
        ]);
93
    }
94
}
95