Completed
Push — master ( 2c922b...25c121 )
by Song
02:51 queued 10s
created

DateMultiple::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23

Duplication

Lines 23
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 23
loc 23
rs 9.552
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Form\Field;
4
5
class DateMultiple extends Text
6
{
7
    protected static $css = [
8
        'https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css',
9
        'https://cdn.jsdelivr.net/npm/[email protected]/dist/themes/light.min.css',
10
11
    ];
12
13
    protected static $js = [
14
        'https://cdn.jsdelivr.net/npm/flatpickr',
15
        'https://cdn.jsdelivr.net/npm/[email protected]/dist/shortcut-buttons-flatpickr.min.js',
16
        'https://npmcdn.com/[email protected]/dist/l10n/zh.js',
17
18
         
19
    ];
20
21
    protected $format = 'YYYY-MM-DD';
22
23
    public function format($format)
24
    {
25
        $this->format = $format;
26
27
        return $this;
28
    }
29
30
    public function prepare($value)
31
    {
32
        if ($value === '') {
33
            $value = null;
34
        }
35
36
        return $value;
37
    }
38
39 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...
40
    {
41
        $this->options['format'] = $this->format;
42
        $this->options['locale'] = array_key_exists('locale', $this->options) ? $this->options['locale'] : config('app.locale');
43
        $this->options['allowInputToggle'] = true;
44
45
        $this->script = "$('{$this->getElementClassSelector()}').flatpickr({mode: 'multiple',dateFormat: 'Y-m-d', locale: 'zh', plugins: [
46
            ShortcutButtonsPlugin({
47
              button: {
48
                label: 'Clear',
49
              },
50
              onClick: (index, fp) => {
51
                fp.clear();
52
                fp.close();
53
              }
54
            })
55
          ]});";
56
57
        $this->prepend('<i class="fa fa-calendar fa-fw"></i>')
58
            ->defaultAttribute('style', 'width: 100%');
59
60
        return parent::render();
0 ignored issues
show
Bug Compatibility introduced by
The expression parent::render(); of type Illuminate\Contracts\Vie...minate\View\View|string adds the type Illuminate\Contracts\View\Factory to the return on line 60 which is incompatible with the return type declared by the interface Illuminate\Contracts\Support\Renderable::render of type string.
Loading history...
61
    }
62
}
63