ProfileWidget::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 11
c 1
b 0
f 0
nc 2
nop 9
dl 0
loc 20
ccs 12
cts 12
cp 1
crap 2
rs 9.9

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
use JeroenNoten\LaravelAdminLte\Helpers\UtilsHelper;
7
8
class ProfileWidget extends Component
9
{
10
    /**
11
     * The user name of the profile widget.
12
     *
13
     * @var string
14
     */
15
    public $name;
16
17
    /**
18
     * The user description of the profile widget.
19
     *
20
     * @var string
21
     */
22
    public $desc;
23
24
    /**
25
     * The user image of the profile widget.
26
     *
27
     * @var string
28
     */
29
    public $img;
30
31
    /**
32
     * The default icon that will be used when no image is provided.
33
     *
34
     * @var string
35
     */
36
    public $icon;
37
38
    /**
39
     * The profile header theme (light, dark, primary, secondary, info, success,
40
     * warning, danger or any other AdminLTE color like lighblue or teal).
41
     *
42
     * @var string
43
     */
44
    public $theme;
45
46
    /**
47
     * The profile header image cover. Overlays the header theme.
48
     *
49
     * @var string
50
     */
51
    public $cover;
52
53
    /**
54
     * Extra classes for the profile header. This provides a way to customize
55
     * the header style.
56
     *
57
     * @var string
58
     */
59
    public $headerClass;
60
61
    /**
62
     * Extra classes for the profile footer. This provides a way to customize
63
     * the footer style.
64
     *
65
     * @var string
66
     */
67
    public $footerClass;
68
69
    /**
70
     * The profile header layout type (modern or classic).
71
     *
72
     * @var string
73
     */
74
    public $layoutType;
75
76
    /**
77
     * Create a new component instance.
78
     *
79
     * @return void
80
     */
81 3
    public function __construct(
82
        $name = null, $desc = null, $img = null, $theme = null, $cover = null,
83
        $headerClass = null, $footerClass = null, $layoutType = 'modern',
84
        $icon = 'fas fa-user'
85
    ) {
86 3
        $this->name = UtilsHelper::applyHtmlEntityDecoder($name);
87 3
        $this->desc = UtilsHelper::applyHtmlEntityDecoder($desc);
88 3
        $this->img = $img;
89 3
        $this->icon = $icon;
90 3
        $this->theme = $theme;
91 3
        $this->cover = $cover;
92 3
        $this->headerClass = $headerClass;
93 3
        $this->footerClass = $footerClass;
94
95
        // Setup the header layout type.
96
97 3
        $this->layoutType = $layoutType;
98
99 3
        if (! in_array($this->layoutType, ['classic', 'modern'])) {
100 1
            $this->layoutType = 'modern';
101
        }
102
    }
103
104
    /**
105
     * Make the profile card class.
106
     *
107
     * @return string
108
     */
109 2
    public function makeCardClass()
110
    {
111 2
        $classes = ['card', 'card-widget'];
112
113 2
        if ($this->layoutType === 'modern') {
114 1
            $classes[] = 'widget-user';
115 1
        } elseif ($this->layoutType === 'classic') {
116 1
            $classes[] = 'widget-user-2';
117
        }
118
119 2
        return implode(' ', $classes);
120
    }
121
122
    /**
123
     * Make the profile header class.
124
     *
125
     * @return string
126
     */
127 2
    public function makeHeaderClass()
128
    {
129 2
        $classes = ['widget-user-header'];
130
131 2
        if (isset($this->theme) && empty($this->cover)) {
132 1
            $classes[] = "bg-gradient-{$this->theme}";
133
        }
134
135 2
        if (! empty($this->headerClass)) {
136 1
            $classes[] = $this->headerClass;
137
        }
138
139 2
        return implode(' ', $classes);
140
    }
141
142
    /**
143
     * Make the profile header style.
144
     *
145
     * @return string
146
     */
147 2
    public function makeHeaderStyle()
148
    {
149 2
        $style = [];
150
151 2
        if (! empty($this->cover)) {
152 1
            $style[] = "background: url('{$this->cover}') center center";
153
        }
154
155 2
        return implode(';', $style);
156
    }
157
158
    /**
159
     * Make the profile footer class.
160
     *
161
     * @return string
162
     */
163 1
    public function makeFooterClass()
164
    {
165 1
        $classes = ['card-footer'];
166
167 1
        if (! empty($this->footerClass)) {
168 1
            $classes[] = $this->footerClass;
169
        }
170
171 1
        return implode(' ', $classes);
172
    }
173
174
    /**
175
     * Get the view / contents that represent the component.
176
     *
177
     * @return \Illuminate\View\View|string
178
     */
179 1
    public function render()
180
    {
181 1
        return view('adminlte::components.widget.profile-widget');
182
    }
183
}
184