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

Time::getPlacement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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 Time extends AbstractField
10
{
11
    use Orderable;
12
    use Nullable;
13
    use Placeholder;
14
15
    const TOP    = 'top';
16
    const RIGHT  = 'right';
17
    const BOTTOM = 'bottom';
18
    const LEFT   = 'left';
19
20
    protected $placement = 'bottom';
21
22 2
    public function placement(string $placement)
23
    {
24 2
        $placement = strtolower($placement);
25
        switch ($placement) {
26 2
            case self::TOP:
27 2
            case self::RIGHT:
28 2
            case self::BOTTOM:
29 2
            case self::LEFT:
30 1
                $this->placement = $placement;
31 1
                break;
32
            default:
33 1
                $this->placement = self::BOTTOM;
34
        }
35
36 2
        return $this;
37
    }
38
39 3
    public function getPlacement()
40
    {
41 3
        return $this->placement;
42
    }
43
44 3 View Code Duplication
    public function default($value)
45
    {
46 3
        if (is_object($value) && is_a($value, \DateTime::class)) {
47
            /** @var \DateTime $value */
48 1
            $this->default = $value->format('H:i:s');
49
        } else {
50 2
            $this->default = date('H:i:s', strtotime($value));
51
        }
52
53 3
        return $this;
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.time.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.time.'. $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.time.create', [
77
            'field' => $this,
78
        ])->render();
79
    }
80
}
81