Passed
Pull Request — master (#962)
by Diego
03:40
created

Options::isDisabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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