Completed
Push — master ( 51084e...d852c9 )
by Yaro
07:57
created

Date   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 71
Duplicated Lines 15.49 %

Coupling/Cohesion

Components 3
Dependencies 5

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 11
lcom 3
cbo 5
dl 11
loc 71
ccs 15
cts 30
cp 0.5
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A default() 11 11 3
A format() 0 6 1
A getDateFormat() 0 4 1
A months() 0 6 1
A getMonths() 0 4 1
A getListValue() 0 7 1
A getEditFormValue() 0 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 Yaro\Jarboe\Table\Fields\Traits\Inline;
6
use Yaro\Jarboe\Table\Fields\Traits\Nullable;
7
use Yaro\Jarboe\Table\Fields\Traits\Orderable;
8
use Yaro\Jarboe\Table\Fields\Traits\Placeholder;
9
10
class Date extends AbstractField
11
{
12
    use Orderable;
13
    use Nullable;
14
    use Inline;
15
    use Placeholder;
16
17
    protected $format = 'YYYY-MM-DD';
18
    protected $months = 1;
19
20 3 View Code Duplication
    public function default($value)
21
    {
22 3
        if (is_object($value) && is_a($value, \DateTime::class)) {
23
            /** @var \DateTime $value */
24 1
            $this->default = $value->format('Y-m-d');
25
        } else {
26 2
            $this->default = date('Y-m-d', strtotime($value));
27
        }
28
29 3
        return $this;
30
    }
31
32 1
    public function format(string $momentJsFormat)
33
    {
34 1
        $this->format = $momentJsFormat;
35
36 1
        return $this;
37
    }
38
39 2
    public function getDateFormat()
40
    {
41 2
        return $this->format;
42
    }
43
44 2
    public function months(int $months)
45
    {
46 2
        $this->months = $months;
47
48 2
        return $this;
49
    }
50
51 2
    public function getMonths()
52
    {
53 2
        return $this->months;
54
    }
55
56
    public function getListValue($model)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
57
    {
58
        return view('jarboe::crud.fields.date.list', [
59
            'model' => $model,
60
            'field' => $this,
61
        ])->render();
62
    }
63
64
    public function getEditFormValue($model)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
65
    {
66
        $template = $this->isReadonly() ? 'readonly' : 'edit';
67
68
        return view('jarboe::crud.fields.date.'. $template, [
69
            'model' => $model,
70
            'field' => $this,
71
        ])->render();
72
    }
73
74
    public function getCreateFormValue()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
75
    {
76
        return view('jarboe::crud.fields.date.create', [
77
            'field' => $this,
78
        ])->render();
79
    }
80
}
81