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