DateRangeField::start()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Webfactor\Laravel\Backpack\FluentSyntax\Fields;
4
5
use Carbon\Carbon;
6
use Webfactor\Laravel\Backpack\FluentSyntax\Contracts\CrudFieldAbstract;
7
use Webfactor\Laravel\Backpack\FluentSyntax\Traits\Defaultable;
8
use Webfactor\Laravel\Backpack\FluentSyntax\Traits\Hintable;
9
10
class DateRangeField extends CrudFieldAbstract
11
{
12
    use Hintable, Defaultable;
13
14
    protected $type = 'date_range';
15
16
    public function __construct(string $uniqueName, string $startColumn, string $endColumn)
17
    {
18
        parent::__construct($uniqueName);
19
20
        $this->options['start_name'] = $startColumn;
21
        $this->options['end_name'] = $endColumn;
22
23
        $now = Carbon::now()->toDateTimeString();
24
        $this->start($now);
25
        $this->end($now);
26
27
        $this->format('DD.MM.YYYY');
28
    }
29
30
    public function start(string $startDefault)
31
    {
32
        $this->options['start_default'] = $startDefault;
33
34
        return $this;
35
    }
36
37
    public function end(string $endDefault)
38
    {
39
        $this->options['end_default'] = $endDefault;
40
41
        return $this;
42
    }
43
44
    public function timePicker()
45
    {
46
        $this->options['date_range_options']['timePicker'] = true;
47
        $this->format('DD.MM.YYYY HH:mm');
48
49
        return $this;
50
    }
51
52
    public function format(string $format)
53
    {
54
        $this->options['date_range_options']['locale']['format'] = $format;
55
56
        return $this;
57
    }
58
}
59