Modal::__construct()   A
last analyzed

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 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 0
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\View\Components\Tool;
4
5
use Illuminate\View\Component;
6
use JeroenNoten\LaravelAdminLte\Helpers\UtilsHelper;
7
8
class Modal extends Component
9
{
10
    /**
11
     * The available modal sizes.
12
     *
13
     * @var array
14
     */
15
    protected $mSizes = ['sm', 'lg', 'xl'];
16
17
    /**
18
     * The modal ID attribute, used to target the modal and show it.
19
     *
20
     * @var string
21
     */
22
    public $id;
23
24
    /**
25
     * The title for the modal header.
26
     *
27
     * @var string
28
     */
29
    public $title;
30
31
    /**
32
     * A Font Awesome icon for the modal header.
33
     *
34
     * @var string
35
     */
36
    public $icon;
37
38
    /**
39
     * The modal size (sm, lg or xl).
40
     *
41
     * @var string
42
     */
43
    public $size;
44
45
    /**
46
     * The modal theme (light, dark, primary, secondary, info, success,
47
     * warning, danger or any other AdminLTE color like lighblue or teal).
48
     *
49
     * @var string
50
     */
51
    public $theme;
52
53
    /**
54
     * Indicates if the modal is vertically centered.
55
     *
56
     * @var bool|mixed
57
     */
58
    public $vCentered;
59
60
    /**
61
     * Indicates if the modal is scrollable. Enable this if the modal content
62
     * is large.
63
     *
64
     * @var bool|mixed
65
     */
66
    public $scrollable;
67
68
    /**
69
     * Indicates if the backdrop is static. When enabled, the modal will not
70
     * close when clicking outside it.
71
     *
72
     * @var bool|mixed
73
     */
74
    public $staticBackdrop;
75
76
    /**
77
     * Indicates if the show/hide fade animations are disabled.
78
     *
79
     * @var bool|mixed
80
     */
81
    public $disableAnimations;
82
83
    /**
84
     * Create a new component instance.
85
     *
86
     * @return void
87
     */
88 3
    public function __construct(
89
        $id, $title = null, $icon = null, $size = null, $theme = null,
90
        $vCentered = null, $scrollable = null, $staticBackdrop = null,
91
        $disableAnimations = null
92
    ) {
93 3
        $this->id = $id;
94 3
        $this->title = UtilsHelper::applyHtmlEntityDecoder($title);
95 3
        $this->icon = $icon;
96 3
        $this->size = $size;
97 3
        $this->theme = $theme;
98 3
        $this->vCentered = $vCentered;
99 3
        $this->scrollable = $scrollable;
100 3
        $this->staticBackdrop = $staticBackdrop;
101 3
        $this->disableAnimations = $disableAnimations;
102
    }
103
104
    /**
105
     * Make the class attribute for the modal.
106
     *
107
     * @return string
108
     */
109 2
    public function makeModalClass()
110
    {
111 2
        $classes = ['modal'];
112
113 2
        if (! isset($this->disableAnimations)) {
114 1
            $classes[] = 'fade';
115
        }
116
117 2
        return implode(' ', $classes);
118
    }
119
120
    /**
121
     * Make the class attribute for the modal dialog.
122
     *
123
     * @return string
124
     */
125 2
    public function makeModalDialogClass()
126
    {
127 2
        $classes = ['modal-dialog'];
128
129 2
        if (isset($this->vCentered)) {
130 1
            $classes[] = 'modal-dialog-centered';
131
        }
132
133 2
        if (isset($this->scrollable)) {
134 1
            $classes[] = 'modal-dialog-scrollable';
135
        }
136
137 2
        if (isset($this->size) && in_array($this->size, $this->mSizes)) {
138 1
            $classes[] = "modal-{$this->size}";
139
        }
140
141 2
        return implode(' ', $classes);
142
    }
143
144
    /**
145
     * Make the class attribute for the modal header.
146
     *
147
     * @return string
148
     */
149 2
    public function makeModalHeaderClass()
150
    {
151 2
        $classes = ['modal-header'];
152
153 2
        if (isset($this->theme)) {
154 1
            $classes[] = "bg-{$this->theme}";
155
        }
156
157 2
        return implode(' ', $classes);
158
    }
159
160
    /**
161
     * Make the class attribute for the close button.
162
     *
163
     * @return string
164
     */
165 2
    public function makeCloseButtonClass()
166
    {
167 2
        $classes = ['bg-secondary'];
168
169 2
        if (isset($this->theme)) {
170 1
            $classes = ["bg-{$this->theme}"];
171
        }
172
173 2
        return implode(' ', $classes);
174
    }
175
176
    /**
177
     * Get the view / contents that represent the component.
178
     *
179
     * @return \Illuminate\View\View|string
180
     */
181 1
    public function render()
182
    {
183 1
        return view('adminlte::components.tool.modal');
184
    }
185
}
186