Passed
Pull Request — master (#721)
by Florian
03:35
created

ProfileWidget::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
c 1
b 0
f 0
nc 2
nop 8
dl 0
loc 18
ccs 11
cts 11
cp 1
crap 2
rs 9.9332

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