Passed
Push — master ( 9925c8...02f327 )
by Thomas
03:39 queued 01:47
created

DateRangeField   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 49
ccs 0
cts 31
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A start() 0 6 1
A end() 0 6 1
A timePicker() 0 7 1
A format() 0 6 1
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