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

Date::format()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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