Passed
Pull Request — master (#962)
by Diego
02:18
created

Options::isSelected()   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
     * Create a new component instance.
40
     */
41 2
    public function __construct(
42
        $options, $selected = null, $disabled = null, $strict = null
43
    ) {
44 2
        $this->options = Arr::wrap($options);
45 2
        $this->selected = Arr::wrap($selected);
46 2
        $this->disabled = Arr::wrap($disabled);
47 2
        $this->strict = isset($strict);
48 2
    }
49
50
    /**
51
     * Determines if an option's key is on selected state.
52
     *
53
     * @param string $key The option's key.
54
     * @return bool
55
     */
56 1
    public function isSelected($key)
57
    {
58 1
        return in_array($key, $this->selected, $this->strict);
59
    }
60
61
    /**
62
     * Determines if an option's key is on disabled state.
63
     *
64
     * @param string $key The option's key.
65
     * @return bool
66
     */
67 1
    public function isDisabled($key)
68
    {
69 1
        return in_array($key, $this->disabled, $this->strict);
70
    }
71
72
    /**
73
     * Get the view / contents that represent the component.
74
     *
75
     * @return \Illuminate\View\View|string
76
     */
77 2
    public function render()
78
    {
79 2
        return view('adminlte::components.form.options');
80
    }
81
}
82