Passed
Push — master ( 5ba9fc...1bdf74 )
by Diego
02:42
created

Card::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 11
dl 0
loc 17
ccs 12
cts 12
cp 1
crap 1
rs 9.9
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\View\Components\Widget;
4
5
use Illuminate\View\Component;
6
7
class Card extends Component
8
{
9
    /**
10
     * The title for the card header.
11
     *
12
     * @var string
13
     */
14
    public $title;
15
16
    /**
17
     * A Font Awesome icon for the card header.
18
     *
19
     * @var string
20
     */
21
    public $icon;
22
23
    /**
24
     * The card theme (light, dark, primary, secondary, info, success,
25
     * warning, danger or any other AdminLTE color like lighblue or teal).
26
     *
27
     * @var string
28
     */
29
    public $theme;
30
31
    /**
32
     * The theme mode (full or outline).
33
     *
34
     * @var string
35
     */
36
    public $themeMode;
37
38
    /**
39
     * Extra classes for the "card-header" element. This provides a way to
40
     * customize the card header container style.
41
     *
42
     * @var string
43
     */
44
    public $headerClass;
45
46
    /**
47
     * Extra classes for the "card-body" element. This provides a way to
48
     * customize the card body container style.
49
     *
50
     * @var string
51
     */
52
    public $bodyClass;
53
54
    /**
55
     * Extra classes for the "card-footer" element. This provides a way to
56
     * customize the card footer container style.
57
     *
58
     * @var string
59
     */
60
    public $footerClass;
61
62
    /**
63
     * Indicates if the card is disabled. When enabled, an overay will show
64
     * over the card.
65
     *
66
     * @var bool|mixed
67
     */
68
    public $disabled;
69
70
    /**
71
     * Indicates if the card is collapsible. When enabled, a button to
72
     * collapse/expand the card will be available. If is set to 'collapsed'
73
     * string, the card will be initiated on collapsed mode.
74
     *
75
     * @var mixed
76
     */
77
    public $collapsible;
78
79
    /**
80
     * Indicates if the card is removable. When enabled, a button to remove
81
     * the card will be available.
82
     *
83
     * @var bool|mixed
84
     */
85
    public $removable;
86
87
    /**
88
     * Indicates if the card is maximizable. When enabled, a button to maximize
89
     * the card will be available.
90
     *
91
     * @var bool|mixed
92
     */
93
    public $maximizable;
94
95
    /**
96
     * Create a new component instance.
97
     *
98
     * @return void
99
     */
100 2
    public function __construct(
101
        $title = null, $icon = null, $theme = null, $themeMode = null,
102
        $headerClass = null, $bodyClass = null, $footerClass = null,
103
        $disabled = null, $collapsible = null, $removable = null,
104
        $maximizable = null
105
    ) {
106 2
        $this->title = $title;
107 2
        $this->icon = $icon;
108 2
        $this->theme = $theme;
109 2
        $this->themeMode = $themeMode;
110 2
        $this->headerClass = $headerClass;
111 2
        $this->bodyClass = $bodyClass;
112 2
        $this->footerClass = $footerClass;
113 2
        $this->disabled = $disabled;
114 2
        $this->removable = $removable;
115 2
        $this->collapsible = $collapsible;
116 2
        $this->maximizable = $maximizable;
117 2
    }
118
119
    /**
120
     * Make the class attribute for the card.
121
     *
122
     * @return string
123
     */
124 1
    public function makeCardClass()
125
    {
126 1
        $classes = ['card'];
127
128 1
        if (isset($this->theme)) {
129 1
            $base = $this->themeMode === 'full' ? 'bg-gradient' : 'card';
130 1
            $classes[] = "{$base}-{$this->theme}";
131
132 1
            if ($this->themeMode === 'outline') {
133 1
                $classes[] = 'card-outline';
134
            }
135
        }
136
137 1
        if ($this->collapsible === 'collapsed') {
138 1
            $classes[] = 'collapsed-card';
139
        }
140
141 1
        return implode(' ', $classes);
142
    }
143
144
    /**
145
     * Make the class attribute for the card header.
146
     *
147
     * @return string
148
     */
149 1
    public function makeCardHeaderClass()
150
    {
151 1
        $classes = ['card-header'];
152
153 1
        if (isset($this->headerClass)) {
154 1
            $classes[] = $this->headerClass;
155
        }
156
157 1
        return implode(' ', $classes);
158
    }
159
160
    /**
161
     * Make the class attribute for the card body.
162
     *
163
     * @return string
164
     */
165 1
    public function makeCardBodyClass()
166
    {
167 1
        $classes = ['card-body'];
168
169 1
        if (isset($this->bodyClass)) {
170 1
            $classes[] = $this->bodyClass;
171
        }
172
173 1
        return implode(' ', $classes);
174
    }
175
176
    /**
177
     * Make the class attribute for the card footer.
178
     *
179
     * @return string
180
     */
181 1
    public function makeCardFooterClass()
182
    {
183 1
        $classes = ['card-footer'];
184
185 1
        if (isset($this->footerClass)) {
186 1
            $classes[] = $this->footerClass;
187
        }
188
189 1
        return implode(' ', $classes);
190
    }
191
192
    /**
193
     * Make the class attribute for the card title.
194
     *
195
     * @return string
196
     */
197 1
    public function makeCardTitleClass()
198
    {
199 1
        $classes = ['card-title'];
200
201 1
        if (isset($this->theme) && $this->themeMode === 'outline') {
202 1
            $classes[] = "text-{$this->theme}";
203
        }
204
205 1
        return implode(' ', $classes);
206
    }
207
208
    /**
209
     * Check if the card header is empty (no items defined for the header).
210
     *
211
     * @param  bool  $hasSlot  Whether the card header slot is defined
212
     * @return bool
213
     */
214 1
    public function isCardHeaderEmpty($hasSlot = false)
215
    {
216 1
        $hasTools = isset($this->collapsible) ||
217 1
                    isset($this->maximizable) ||
218 1
                    isset($this->removable) ||
219 1
                    $hasSlot;
220
221 1
        return empty($this->title) && empty($this->icon) && ! $hasTools;
222
    }
223
224
    /**
225
     * Get the view / contents that represent the component.
226
     *
227
     * @return \Illuminate\View\View|string
228
     */
229 1
    public function render()
230
    {
231 1
        return view('adminlte::components.widget.card');
232
    }
233
}
234