Passed
Pull Request — master (#832)
by Florian
09:14
created

ProfileWidget::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
nc 2
nop 8
dl 0
loc 18
rs 9.9332
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;
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
    public function __construct(
74
        $name = null, $desc = null, $img = null, $theme = null, $cover = null,
75
        $headerClass = null, $footerClass = null, $layoutType = 'modern'
76
    ) {
77
        $this->name = $name;
78
        $this->desc = $desc;
79
        $this->img = $img;
80
        $this->theme = $theme;
81
        $this->cover = $cover;
82
        $this->headerClass = $headerClass;
83
        $this->footerClass = $footerClass;
84
85
        // Setup the header layout type.
86
87
        $this->layoutType = $layoutType;
88
89
        if (! in_array($this->layoutType, ['classic', 'modern'])) {
90
            $this->layoutType = 'modern';
91
        }
92
    }
93
94
    /**
95
     * Make the profile card class.
96
     *
97
     * @return string
98
     */
99
    public function makeCardClass()
100
    {
101
        $classes = ['card', 'card-widget'];
102
103
        if ($this->layoutType === 'modern') {
104
            $classes[] = 'widget-user';
105
        } elseif ($this->layoutType === 'classic') {
106
            $classes[] = 'widget-user-2';
107
        }
108
109
        return implode(' ', $classes);
110
    }
111
112
    /**
113
     * Make the profile header class.
114
     *
115
     * @return string
116
     */
117
    public function makeHeaderClass()
118
    {
119
        $classes = ['widget-user-header'];
120
121
        if (isset($this->theme) && empty($this->cover)) {
122
            $classes[] = "bg-gradient-{$this->theme}";
123
        }
124
125
        if (! empty($this->headerClass)) {
126
            $classes[] = $this->headerClass;
127
        }
128
129
        return implode(' ', $classes);
130
    }
131
132
    /**
133
     * Make the profile header style.
134
     *
135
     * @return string
136
     */
137
    public function makeHeaderStyle()
138
    {
139
        $style = [];
140
141
        if (! empty($this->cover)) {
142
            $style[] = "background: url('{$this->cover}') center center";
143
        }
144
145
        return implode(';', $style);
146
    }
147
148
    /**
149
     * Make the profile footer class.
150
     *
151
     * @return string
152
     */
153
    public function makeFooterClass()
154
    {
155
        $classes = ['card-footer'];
156
157
        if (! empty($this->footerClass)) {
158
            $classes[] = $this->footerClass;
159
        }
160
161
        return implode(' ', $classes);
162
    }
163
164
    /**
165
     * Get the view / contents that represent the component.
166
     *
167
     * @return \Illuminate\View\View|string
168
     */
169
    public function render()
170
    {
171
        return view('adminlte::components.profile-widget');
172
    }
173
}
174