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

Options   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 72
ccs 12
cts 12
cp 1
rs 10
c 2
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 3 1
A isSelected() 0 3 1
A __construct() 0 7 1
A isDisabled() 0 3 1
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