Passed
Push — master ( f6e0b1...9f2568 )
by Yaro
23:37
created

Markdown   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 50 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 94.44%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 21
loc 42
ccs 17
cts 18
cp 0.9444
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A value() 0 6 2
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\Orderable;
7
use Yaro\Jarboe\Table\Fields\Traits\Translatable;
8
9
class Markdown extends AbstractField
10
{
11
    use Orderable;
12
    use Translatable;
13
14 1
    public function value(Request $request)
15
    {
16 1
        $value = parent::value($request);
17
18 1
        return is_array($value) ? $value : (string) $value;
19
    }
20
21 1 View Code Duplication
    public function getListView($model)
22
    {
23 1
        $template = 'list';
24 1
        if ($this->isTranslatable()) {
25
            $template .= '_translatable';
26
        }
27
28 1
        return view('jarboe::crud.fields.markdown.'. $template, [
29 1
            'model' => $model,
30 1
            'field' => $this,
31
        ]);
32
    }
33
34 1 View Code Duplication
    public function getEditFormView($model)
35
    {
36 1
        $template = $this->isReadonly() ? 'readonly' : 'edit';
37
38 1
        return view('jarboe::crud.fields.markdown.'. $template, [
39 1
            'model' => $model,
40 1
            'field' => $this,
41
        ]);
42
    }
43
44 1
    public function getCreateFormView()
45
    {
46 1
        return view('jarboe::crud.fields.markdown.create', [
47 1
            'field' => $this,
48
        ]);
49
    }
50
}
51