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

Textarea   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 91
Duplicated Lines 23.08 %

Coupling/Cohesion

Components 3
Dependencies 9

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 15
lcom 3
cbo 9
dl 21
loc 91
ccs 35
cts 35
cp 1
rs 10
c 0
b 0
f 0

10 Methods

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