Passed
Pull Request — master (#856)
by Florian
03:57
created

InputDate   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
dl 0
loc 89
ccs 14
cts 14
cp 1
rs 10
c 1
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A makeItemClass() 0 9 3
A __construct() 0 19 2
A render() 0 3 1
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\Components;
4
5
class InputDate extends InputGroupComponent
6
{
7
    /**
8
     * The default set of icons for the Tempus Dominus plugin configuration.
9
     *
10
     * @var array
11
     */
12
    protected $icons = [
13
        'time'     => 'fas fa-clock',
14
        'date'     => 'fas fa-calendar-alt',
15
        'up'       => 'fas fa-arrow-up',
16
        'down'     => 'fas fa-arrow-down',
17
        'previous' => 'fas fa-chevron-left',
18
        'next'     => 'fas fa-chevron-right',
19
        'today'    => 'fas fa-calendar-check-o',
20
        'clear'    => 'fas fa-trash',
21
        'close'    => 'fas fa-times',
22
    ];
23
24
    /**
25
     * The default set of buttons for the Tempus Dominus plugin configuration.
26
     *
27
     * @var array
28
     */
29
    protected $buttons = [
30
        'showClose' => true,
31
    ];
32
33
    /**
34
     * The Tempus Dominus plugin configuration parameters. Array with
35
     * key => value pairs, where the key should be an existing configuration
36
     * property of the plugin.
37
     *
38
     * @var array
39
     */
40
    public $config;
41
42
    /**
43
     * Create a new component instance.
44
     * Note this component requires the 'Tempus Dominus' plugin.
45
     *
46
     * @return void
47
     */
48 2
    public function __construct(
49
        $name, $label = null, $size = null, $labelClass = null,
50
        $topClass = null, $inputGroupClass = null, $disableFeedback = null,
51
        $config = []
52
    ) {
53 2
        parent::__construct(
54 2
            $name, $label, $size, $labelClass, $topClass,
55
            $inputGroupClass, $disableFeedback
56
        );
57
58 2
        $this->config = is_array($config) ? $config : [];
59
60
        // Setup the default plugin icons option.
61
62 2
        $this->config['icons'] = $this->config['icons'] ?? $this->icons;
63
64
        // Setup the default plugin buttons option.
65
66 2
        $this->config['buttons'] = $this->config['buttons'] ?? $this->buttons;
67 2
    }
68
69
    /**
70
     * Make the class attribute for the input group item.
71
     *
72
     * @param string $invalid
73
     * @return string
74
     */
75 1
    public function makeItemClass($invalid = null)
76
    {
77 1
        $classes = ['form-control', 'datetimepicker'];
78
79 1
        if (! empty($invalid) && ! isset($this->disableFeedback)) {
80 1
            $classes[] = 'is-invalid';
81
        }
82
83 1
        return implode(' ', $classes);
84
    }
85
86
    /**
87
     * Get the view / contents that represent the component.
88
     *
89
     * @return \Illuminate\View\View|string
90
     */
91 1
    public function render()
92
    {
93 1
        return view('adminlte::components.input-date');
94
    }
95
}
96