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

Card::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
nc 1
nop 8
dl 0
loc 13
rs 10
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 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
     * Indicates if the card is disabled. When enabled, an overay will show
40
     * over the card.
41
     *
42
     * @var bool|mixed
43
     */
44
    public $disabled;
45
46
    /**
47
     * Indicates if the card is collapsible. When enabled, a button to
48
     * collapse/expand the card will be available. If is set to 'collapsed'
49
     * string, the card will be initiated on collapsed mode.
50
     *
51
     * @var mixed
52
     */
53
    public $collapsible;
54
55
    /**
56
     * Indicates if the card is removable. When enabled, a button to remove
57
     * the card will be available.
58
     *
59
     * @var bool|mixed
60
     */
61
    public $removable;
62
63
    /**
64
     * Indicates if the card is maximizable. When enabled, a button to maximize
65
     * the card will be available.
66
     *
67
     * @var bool|mixed
68
     */
69
    public $maximizable;
70
71
    /**
72
     * Create a new component instance.
73
     *
74
     * @return void
75
     */
76
    public function __construct(
77
        $title = null, $icon = null, $theme = null, $themeMode = null,
78
        $disabled = null, $collapsible = null, $removable = null,
79
        $maximizable = null
80
    ) {
81
        $this->title = $title;
82
        $this->icon = $icon;
83
        $this->theme = $theme;
84
        $this->themeMode = $themeMode;
85
        $this->disabled = $disabled;
86
        $this->removable = $removable;
87
        $this->collapsible = $collapsible;
88
        $this->maximizable = $maximizable;
89
    }
90
91
    /**
92
     * Make the class attribute for the card.
93
     *
94
     * @return string
95
     */
96
    public function makeCardClass()
97
    {
98
        $classes = ['card'];
99
100
        if (isset($this->theme)) {
101
            $base = $this->themeMode === 'full' ? 'bg-gradient' : 'card';
102
            $classes[] = "{$base}-{$this->theme}";
103
104
            if ($this->themeMode === 'outline') {
105
                $classes[] = 'card-outline';
106
            }
107
        }
108
109
        if ($this->collapsible === 'collapsed') {
110
            $classes[] = 'collapsed-card';
111
        }
112
113
        return implode(' ', $classes);
114
    }
115
116
    /**
117
     * Make the class attribute for the card title.
118
     *
119
     * @return string
120
     */
121
    public function makeCardTitleClass()
122
    {
123
        $classes = ['card-title'];
124
125
        if (isset($this->theme) && $this->themeMode === 'outline') {
126
            $classes[] = "text-{$this->theme}";
127
        }
128
129
        return implode(' ', $classes);
130
    }
131
132
    /**
133
     * Get the view / contents that represent the component.
134
     *
135
     * @return \Illuminate\View\View|string
136
     */
137
    public function render()
138
    {
139
        return view('adminlte::components.card');
140
    }
141
}
142