Passed
Push — master ( 29213f...d0ad7b )
by Florian
03:12
created

Card::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 9
dl 0
loc 14
ccs 10
cts 10
cp 1
crap 1
rs 9.9666
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\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-body" element. This provides a way to
40
     * customize the card body container style.
41
     *
42
     * @var string
43
     */
44
    public $bodyClass;
45
46
    /**
47
     * Indicates if the card is disabled. When enabled, an overay will show
48
     * over the card.
49
     *
50
     * @var bool|mixed
51
     */
52
    public $disabled;
53
54
    /**
55
     * Indicates if the card is collapsible. When enabled, a button to
56
     * collapse/expand the card will be available. If is set to 'collapsed'
57
     * string, the card will be initiated on collapsed mode.
58
     *
59
     * @var mixed
60
     */
61
    public $collapsible;
62
63
    /**
64
     * Indicates if the card is removable. When enabled, a button to remove
65
     * the card will be available.
66
     *
67
     * @var bool|mixed
68
     */
69
    public $removable;
70
71
    /**
72
     * Indicates if the card is maximizable. When enabled, a button to maximize
73
     * the card will be available.
74
     *
75
     * @var bool|mixed
76
     */
77
    public $maximizable;
78
79
    /**
80
     * Create a new component instance.
81
     *
82
     * @return void
83
     */
84 2
    public function __construct(
85
        $title = null, $icon = null, $theme = null, $themeMode = null,
86
        $bodyClass = null, $disabled = null, $collapsible = null,
87
        $removable = null, $maximizable = null
88
    ) {
89 2
        $this->title = $title;
90 2
        $this->icon = $icon;
91 2
        $this->theme = $theme;
92 2
        $this->themeMode = $themeMode;
93 2
        $this->bodyClass = $bodyClass;
94 2
        $this->disabled = $disabled;
95 2
        $this->removable = $removable;
96 2
        $this->collapsible = $collapsible;
97 2
        $this->maximizable = $maximizable;
98 2
    }
99
100
    /**
101
     * Make the class attribute for the card.
102
     *
103
     * @return string
104
     */
105 1
    public function makeCardClass()
106
    {
107 1
        $classes = ['card'];
108
109 1
        if (isset($this->theme)) {
110 1
            $base = $this->themeMode === 'full' ? 'bg-gradient' : 'card';
111 1
            $classes[] = "{$base}-{$this->theme}";
112
113 1
            if ($this->themeMode === 'outline') {
114 1
                $classes[] = 'card-outline';
115
            }
116
        }
117
118 1
        if ($this->collapsible === 'collapsed') {
119 1
            $classes[] = 'collapsed-card';
120
        }
121
122 1
        return implode(' ', $classes);
123
    }
124
125
    /**
126
     * Make the class attribute for the card body.
127
     *
128
     * @return string
129
     */
130 1
    public function makeCardBodyClass()
131
    {
132 1
        $classes = ['card-body'];
133
134 1
        if (isset($this->bodyClass)) {
135 1
            $classes[] = $this->bodyClass;
136
        }
137
138 1
        return implode(' ', $classes);
139
    }
140
141
    /**
142
     * Make the class attribute for the card header.
143
     *
144
     * @return string
145
     */
146 1
    public function makeCardHeaderClass()
147
    {
148 1
        $classes = ['card-header'];
149
150 1
        if ($this->isCardHeaderEmpty()) {
151 1
            $classes[] = 'd-none';
152
        }
153
154 1
        return implode(' ', $classes);
155
    }
156
157
    /**
158
     * Make the class attribute for the card title.
159
     *
160
     * @return string
161
     */
162 1
    public function makeCardTitleClass()
163
    {
164 1
        $classes = ['card-title'];
165
166 1
        if (isset($this->theme) && $this->themeMode === 'outline') {
167 1
            $classes[] = "text-{$this->theme}";
168
        }
169
170 1
        return implode(' ', $classes);
171
    }
172
173
    /**
174
     * Check if the card header is empty (no items defined for the header).
175
     *
176
     * @return bool
177
     */
178 1
    protected function isCardHeaderEmpty()
179
    {
180 1
        $hasTools = isset($this->collapsible) ||
181 1
                    isset($this->maximizable) ||
182 1
                    isset($this->removable);
183
184 1
        return empty($this->title) && empty($this->icon) && ! $hasTools;
185
    }
186
187
    /**
188
     * Get the view / contents that represent the component.
189
     *
190
     * @return \Illuminate\View\View|string
191
     */
192 1
    public function render()
193
    {
194 1
        return view('adminlte::components.widget.card');
195
    }
196
}
197