Options   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 94
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 3 1
A isDisabled() 0 3 1
A __construct() 0 10 1
A isSelected() 0 3 1
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\View\Components\Form;
4
5
use Illuminate\Support\Arr;
6
use Illuminate\View\Component;
7
use JeroenNoten\LaravelAdminLte\Helpers\UtilsHelper;
8
9
class Options extends Component
10
{
11
    /**
12
     * The list of options as 'key => value' pairs.
13
     *
14
     * @var array
15
     */
16
    public $options;
17
18
    /**
19
     * The list of selected option keys.
20
     *
21
     * @var array
22
     */
23
    public $selected;
24
25
    /**
26
     * The list of disabled option keys.
27
     *
28
     * @var array
29
     */
30
    public $disabled;
31
32
    /**
33
     * Whether to use strict comparison between the option keys and the keys of
34
     * the selected/disabled options.
35
     *
36
     * @var bool
37
     */
38
    public $strict;
39
40
    /**
41
     * Whether to add a selectable empty option to the list of options. If the
42
     * value is a string, it will be used as the option label, otherwise no
43
     * label will be available for the empty option.
44
     *
45
     * @var bool|string
46
     */
47
    public $emptyOption;
48
49
    /**
50
     * Whether to add a placeholder (non-selectable option) to the list of
51
     * options. If the value is a string, it will be used as the placeholder
52
     * label, otherwise no label will be available for the placeholder.
53
     *
54
     * @var bool|string
55
     */
56
    public $placeholder;
57
58
    /**
59
     * Create a new component instance.
60
     */
61 2
    public function __construct(
62
        $options, $selected = null, $disabled = null,
63
        $strict = null, $emptyOption = null, $placeholder = null
64
    ) {
65 2
        $this->options = Arr::wrap($options);
66 2
        $this->selected = Arr::wrap($selected);
67 2
        $this->disabled = Arr::wrap($disabled);
68 2
        $this->strict = isset($strict);
69 2
        $this->emptyOption = UtilsHelper::applyHtmlEntityDecoder($emptyOption);
70 2
        $this->placeholder = UtilsHelper::applyHtmlEntityDecoder($placeholder);
71
    }
72
73
    /**
74
     * Determines if an option's key is on selected state.
75
     *
76
     * @param  string  $key  The option's key.
77
     * @return bool
78
     */
79 1
    public function isSelected($key)
80
    {
81 1
        return in_array($key, $this->selected, $this->strict);
82
    }
83
84
    /**
85
     * Determines if an option's key is on disabled state.
86
     *
87
     * @param  string  $key  The option's key.
88
     * @return bool
89
     */
90 1
    public function isDisabled($key)
91
    {
92 1
        return in_array($key, $this->disabled, $this->strict);
93
    }
94
95
    /**
96
     * Get the view / contents that represent the component.
97
     *
98
     * @return \Illuminate\View\View|string
99
     */
100 2
    public function render()
101
    {
102 2
        return view('adminlte::components.form.options');
103
    }
104
}
105