Passed
Pull Request — master (#22)
by
unknown
18:54
created

Text   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 64
Duplicated Lines 46.88 %

Coupling/Cohesion

Components 1
Dependencies 11

Test Coverage

Coverage 84%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 11
dl 30
loc 64
ccs 21
cts 25
cp 0.84
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A value() 9 9 4
A getListView() 12 12 2
A getCreateFormView() 0 8 1
A getEditFormView() 9 9 2
A getErrorsCount() 0 8 2

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\BelongsToArray;
7
use Yaro\Jarboe\Table\Fields\Traits\Clipboard;
8
use Yaro\Jarboe\Table\Fields\Traits\Inline;
9
use Yaro\Jarboe\Table\Fields\Traits\Maskable;
10
use Yaro\Jarboe\Table\Fields\Traits\Maxlength;
11
use Yaro\Jarboe\Table\Fields\Traits\Nullable;
12
use Yaro\Jarboe\Table\Fields\Traits\Orderable;
13
use Yaro\Jarboe\Table\Fields\Traits\Placeholder;
14
use Yaro\Jarboe\Table\Fields\Traits\Tooltip;
15
use Yaro\Jarboe\Table\Fields\Traits\Translatable;
16
17
class Text extends AbstractField
18
{
19
    use Orderable;
20
    use Nullable;
21
    use Tooltip;
22
    use Clipboard;
23
    use Inline;
24
    use Translatable;
25
    use Maskable;
26
    use Placeholder;
27
    use Maxlength;
28
    use BelongsToArray;
29
30 5 View Code Duplication
    public function value(Request $request)
31
    {
32 5
        $value = parent::value($request);
33 5
        if (is_null($value) && $this->isNullable()) {
34 2
            return null;
35
        }
36
37 5
        return is_array($value) ? $value : (string) $value;
38
    }
39
40 2 View Code Duplication
    public function getListView($model)
41
    {
42 2
        $template = 'list';
43 2
        if ($this->isTranslatable()) {
44 1
            $template .= '_translatable';
45
        }
46
47 2
        return view('jarboe::crud.fields.text.'. $template, [
48 2
            'model' => $model,
49 2
            'field' => $this,
50
        ]);
51
    }
52
53 1 View Code Duplication
    public function getEditFormView($model)
54
    {
55 1
        $template = $this->isReadonly() ? 'readonly' : 'edit';
56
57 1
        return view('jarboe::crud.fields.text.'. $template, [
58 1
            'model' => $model,
59 1
            'field' => $this,
60
        ]);
61
    }
62
63 1
    public function getCreateFormView()
64
    {
65 1
        $template = 'create';
66
67 1
        return view('jarboe::crud.fields.text.'. $template, [
68 1
            'field' => $this,
69
        ]);
70
    }
71
72
    public function getErrorsCount($errors): int
73
    {
74
        if ($this->isTranslatable() === true) {
75
            return count($errors->get(sprintf('%s.*', $this->name())));
76
        }
77
78
        return count($errors->get($this->name()));
79
    }
80
}
81