Passed
Pull Request — master (#908)
by Diego
03:21
created

NavbarDarkmodeWidget   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 121
ccs 25
cts 25
cp 1
rs 10
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A makeIconDisabledClass() 0 11 2
A render() 0 3 1
A makeIconClass() 0 13 2
A makeIconEnabledClass() 0 11 2
A __construct() 0 20 3
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\Components\Layout;
4
5
use Illuminate\View\Component;
6
7
class NavbarDarkmodeWidget extends Component
8
{
9
    /**
10
     * The Font Awesome icon to use when darkmode is disabled.
11
     *
12
     * @var string
13
     */
14
    public $iconDisabled = 'far fa-moon';
15
16
    /**
17
     * The Font Awesome icon to use when darkmode is enabled.
18
     *
19
     * @var string
20
     */
21
    public $iconEnabled = 'fas fa-moon';
22
23
    /**
24
     * The AdminLTE color to use for the icon when darkmode is disabled.
25
     *
26
     * @var string
27
     */
28
    public $colorDisabled;
29
30
    /**
31
     * The AdminLTE color to use for the icon when darkmode is enabled.
32
     *
33
     * @var string
34
     */
35
    public $colorEnabled;
36
37
    /**
38
     * Create a new component instance.
39
     *
40
     * @return void
41
     */
42 2
    public function __construct(
43
        $iconDisabled = null, $iconEnabled = null,
44
        $colorDisabled = null, $colorEnabled = null
45
    ) {
46
        // Setup the icon to use when darkmode is disabled.
47
48 2
        if (! empty($iconDisabled)) {
49 1
            $this->iconDisabled = $iconDisabled;
50
        }
51
52
        // Setup the icon to use when darkmode is enabled.
53
54 2
        if (! empty($iconEnabled)) {
55 1
            $this->iconEnabled = $iconEnabled;
56
        }
57
58
        // Setup the icon colors.
59
60 2
        $this->colorDisabled = $colorDisabled;
61 2
        $this->colorEnabled = $colorEnabled;
62 2
    }
63
64
    /**
65
     * Make the class attribute for the darkmode widget icon.
66
     *
67
     * @return string
68
     */
69 1
    public function makeIconClass()
70
    {
71
        // Read the related configuration value and get classes for the icon.
72
73 1
        if (config('adminlte.layout_dark_mode', false)) {
74 1
            $classes = $this->makeIconEnabledClass();
75
        } else {
76 1
            $classes = $this->makeIconDisabledClass();
77
        }
78
79
        // Return the icon classes.
80
81 1
        return implode(' ', $classes);
0 ignored issues
show
Bug introduced by
$classes of type string is incompatible with the type array expected by parameter $pieces of implode(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

81
        return implode(' ', /** @scrutinizer ignore-type */ $classes);
Loading history...
82
    }
83
84
    /**
85
     * Make the class attribute for the icon when darkmode is disabled.
86
     *
87
     * @return string
88
     */
89 1
    public function makeIconDisabledClass()
90
    {
91 1
        $classes = explode(' ', $this->iconDisabled);
92
93 1
        if (! empty($this->colorDisabled)) {
94 1
            $classes[] = "text-{$this->colorDisabled}";
95
        }
96
97
        // Return the icon classes.
98
99 1
        return $classes;
100
    }
101
102
    /**
103
     * Make the class attribute for the icon when darkmode is enabled.
104
     *
105
     * @return string
106
     */
107 1
    public function makeIconEnabledClass()
108
    {
109 1
        $classes = explode(' ', $this->iconEnabled);
110
111 1
        if (! empty($this->colorEnabled)) {
112 1
            $classes[] = "text-{$this->colorEnabled}";
113
        }
114
115
        // Return the icon classes.
116
117 1
        return $classes;
118
    }
119
120
    /**
121
     * Get the view / contents that represent the component.
122
     *
123
     * @return \Illuminate\View\View|string
124
     */
125 1
    public function render()
126
    {
127 1
        return view('adminlte::components.layout.navbar-darkmode-widget');
128
    }
129
}
130