Completed
Pull Request — master (#163)
by
unknown
08:39
created

Date::prepare()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Form\Field;
4
5
use Encore\Admin\Form\Field;
6
7
class Date extends Field
8
{
9
    protected static $css = [
10
        '/packages/admin/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css',
11
    ];
12
13
    protected static $js = [
14
        '/packages/admin/moment/min/moment-with-locales.min.js',
15
        '/packages/admin/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js',
16
    ];
17
18
    protected $format = 'YYYY-MM-DD';
19
20
    public function format($format)
21
    {
22
        $this->format = $format;
23
24
        return $this;
25
    }
26
27
    public function prepare($value)
28
    {
29
        if ($value === '') {
30
            $value = null;
31
        }
32
33
        return $value;
34
    }
35
36 View Code Duplication
    public function render()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
    {
38
        $this->options['format'] = $this->format;
39
        $this->options['locale'] = config('app.locale');
40
41
        $this->script = "$('#{$this->id}').datetimepicker(".json_encode($this->options).');';
42
43
        return parent::render();
44
    }
45
}
46