InputDate::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 11
dl 0
loc 20
ccs 9
cts 9
cp 1
crap 2
rs 10
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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