Completed
Push — master ( 4434b2...6b8e46 )
by Yaro
02:04
created

Datetime::default()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 11
loc 11
ccs 5
cts 5
cp 1
rs 9.9
c 0
b 0
f 0
cc 3
nc 2
nop 1
crap 3
1
<?php
2
3
namespace Yaro\Jarboe\Table\Fields;
4
5
use Yaro\Jarboe\Table\Fields\Traits\Nullable;
6
use Yaro\Jarboe\Table\Fields\Traits\Orderable;
7
use Yaro\Jarboe\Table\Fields\Traits\Placeholder;
8
9
class Datetime extends AbstractField
10
{
11
    use Orderable;
12
    use Nullable;
13
    use Placeholder;
14
15
    protected $format = 'YYYY-MM-DD HH:mm:ss';
16
17 1
    public function format(string $momentJsFormat)
18
    {
19 1
        $this->format = $momentJsFormat;
20
21 1
        return $this;
22
    }
23
24 2
    public function getDateFormat()
25
    {
26 2
        return $this->format;
27
    }
28
29 3 View Code Duplication
    public function default($value)
30
    {
31 3
        if (is_object($value) && is_a($value, \DateTime::class)) {
32
            /** @var \DateTime $value */
33 1
            $this->default = $value->format('Y-m-d H:i:s');
34
        } else {
35 2
            $this->default = date('Y-m-d H:i:s', strtotime($value));
36
        }
37
38 3
        return $this;
39
    }
40
41
    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...
42
    {
43
        return view('jarboe::crud.fields.datetime.list', [
44
            'model' => $model,
45
            'field' => $this,
46
        ])->render();
47
    }
48
49
    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...
50
    {
51
        $template = $this->isReadonly() ? 'readonly' : 'edit';
52
53
        return view('jarboe::crud.fields.datetime.'. $template, [
54
            'model' => $model,
55
            'field' => $this,
56
        ])->render();
57
    }
58
59
    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...
60
    {
61
        return view('jarboe::crud.fields.datetime.create', [
62
            'field' => $this,
63
        ])->render();
64
    }
65
}
66