Completed
Pull Request — master (#5)
by Michael
01:37
created

Form::dropdown_add()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 4
Ratio 33.33 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 8
dl 4
loc 12
rs 9.8666
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 XoopsModules\Smallworld;
4
5
/**
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
/**
16
 * SmallWorld
17
 *
18
 * @copyright    The XOOPS Project (https://xoops.org)
19
 * @copyright    2011 Culex
20
 * @license      GNU GPL (http://www.gnu.org/licenses/gpl-2.0.html/)
21
 * @package      SmallWorld
22
 * @since        1.0
23
 * @author       Michael Albertsen (http://culex.dk) <[email protected]>
24
 */
25
class Form
26
{
27
    /**
28
     * @create a dropdown select
29
     * @param string $name
30
     * @param string $selected (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $selected not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
31
     * @return string
32
     */
33
    public function dropdown($name, array $options, $selected = null)
34
    {
35
        $dropdown = '<select name="' . $name . '" id="' . $name . '">' . '<br>';
36
        $selected = $selected;
0 ignored issues
show
Bug introduced by
Why assign $selected to itself?

This checks looks for cases where a variable has been assigned to itself.

This assignement can be removed without consequences.

Loading history...
37 View Code Duplication
        foreach ($options as $key => $option) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
            $select   = $selected == $key ? ' selected="yes"' : '';
39
            $dropdown .= '<option value="' . $key . '"' . $select . '>' . $option . '</option>' . '<br>';
40
        }
41
        $dropdown .= '</select>' . '<br>';
42
43
        return $dropdown;
44
    }
45
46
    /**
47
     * @create a radio select
48
     * @param string $name
49
     * @param string $selected (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $selected not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
50
     * @return string
51
     */
52
    public function radio($name, array $options, $selected = null)
53
    {
54
        $selected = $selected;
0 ignored issues
show
Bug introduced by
Why assign $selected to itself?

This checks looks for cases where a variable has been assigned to itself.

This assignement can be removed without consequences.

Loading history...
55
        $form     = '';
56
        foreach ($options as $value => $option) {
57
            $select = $selected == $value ? ' checked' : ' checked="unchecked"';
58
            $form   .= '<input type="checkbox" name="' . $name . '[]" id="' . $name . '" value="' . $value . '" ' . $select . '> ' . $option . '<br>';
59
        }
60
61
        return $form;
62
    }
63
64
    /**
65
     * @param string $name
66
     * @param array  $options
67
     * @param array  $valuearray
68
     * @param string $selected (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $selected not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
69
     * @return string
70
     */
71
    public function RetrieveRadio($name, $options, $valuearray, $selected = null)
0 ignored issues
show
Unused Code introduced by
The parameter $selected is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
72
    {
73
        $form = '';
74
        $a    = count($options) - 1;
75
        for ($i = 0; $i <= $a; ++$i) {
76
            if (in_array($i, $valuearray)) {
77
                $form .= '<input type="checkbox" id="' . $name . '-' . $i . '" name="' . $name . '[]" value="' . $i . '" checked>' . $options[$i] . '<br>';
78
            } else {
79
                $form .= '<input type="checkbox" id="' . $name . '-' . $i . '" name="' . $name . '[]" value="' . $i . '" >' . $options[$i] . '<br>';
80
            }
81
        }
82
83
        return $form;
84
    }
85
86
    /**
87
     * @param string $name
88
     * @param string $id
89
     * @param string $class
90
     * @param int    $size   (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $size not be integer|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
91
     * @param string $preset (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $preset not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
92
     * @return string
93
     */
94 View Code Duplication
    public function input($name, $id, $class, $size = null, $preset = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
95
    {
96
        $s    = $size ?: '50px';
97
        $data = "<input type='text' size='" . $s . "' name='" . $name . "' id='" . $id . "' class='" . $class . "' value='" . $preset . "' >";
98
99
        return $data;
100
    }
101
102
    /**
103
     * @param string $name
104
     * @param string $id
105
     * @param string $preset (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $preset not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
106
     * @return string
107
     */
108
    public function hidden($name, $id, $preset = null)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
109
    {
110
        $data = "<input type='hidden' name='" . $name . "' value='" . $preset . "' >";
111
112
        return $data;
113
    }
114
115
    /**
116
     * @param string $value
117
     * @return string
118
     */
119
    public function simpleText($value)
120
    {
121
        $data = $value;
122
123
        return $data;
124
    }
125
126
    /**
127
     * @param string  $class
128
     * @param string  $name
129
     * @param         $name2
130
     * @param string  $rel
131
     * @param string  $textmore
132
     * @param string  $selected (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $selected not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
133
     * @param string  $preset   (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $preset not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
134
     * @return string
135
     */
136
    public function dropdown_add($class, $name, $name2, $rel, array $options, $textmore, $selected = null, $preset = null)
0 ignored issues
show
Unused Code introduced by
The parameter $class is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $rel is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $textmore is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
137
    {
138
        $dropdown = '<span id="' . $name . '"><input type="text" name="' . $name2 . '[]" value="' . $preset . '">';
139
        $dropdown .= '<select class="smallworld_select" name="' . $name . '[]" id="' . $name . '"></p>' . '<br>';
140 View Code Duplication
        foreach ($options as $key => $option) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
141
            $select   = $selected == $key ? ' selected' : null;
142
            $dropdown .= '<option value="' . $key . '"' . $select . '>' . $option . '</option>' . '<br>';
143
        }
144
        $dropdown .= '</select></span>';
145
146
        return $dropdown;
147
    }
148
149
    /**
150
     * @param string  $class
151
     * @param string  $name
152
     * @param         $name2
153
     * @param string  $rel
154
     * @param int     $size
155
     * @param string  $textmore
156
     * @param string  $preset (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $preset not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
157
     * @param string  $id     (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $id not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
158
     * @return dynamic|string
159
     */
160 View Code Duplication
    public function input_add($class, $name, $name2, $rel, $size, $textmore, $preset = null, $id = null)
0 ignored issues
show
Unused Code introduced by
The parameter $class is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $rel is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $textmore is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
161
    {
162
        $s    = $size ?: '50px';
163
        $i    = $id ?: '';
164
        $data = "<span id='" . $name . "'><input type='text' size='" . $s . "' name='" . $name2 . "[]' value='" . $preset . "' id='" . $i . "'></span>";
165
166
        return $data;
167
    }
168
169
    /**
170
     * @param string $name
171
     * @param string $id
172
     * @param string $title
173
     * @param string $rows
174
     * @param string $cols
175
     * @param string $class
176
     * @param string $preset (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $preset not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
177
     * @return string|textarea
178
     * @return string
179
     */
180
    public function textarea($name, $id, $title, $rows, $cols, $class, $preset = null)
181
    {
182
        return "<textarea name='" . $name . "' id='" . $id . "'  title='" . $title . "' rows='" . $rows . "' cols='" . $cols . "' class='" . $class . "'>" . $preset . '</textarea>';
183
    }
184
185
    /**
186
     * @param string $class
187
     * @param string $name
188
     * @param string $name2
189
     * @param string $rel
190
     * @param string $textmore
191
     * @param string $selected      (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $selected not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
192
     * @param string $preset        (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $preset not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
193
     * @param string $selectedstart (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $selectedstart not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
194
     * @param string $selectedstop  (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $selectedstop not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
195
     * @return dynamic|string
196
     * @return string
197
     */
198
    public function school_add(
199
        $class,
0 ignored issues
show
Unused Code introduced by
The parameter $class is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
200
        $name,
201
        $name2,
202
        $rel,
0 ignored issues
show
Unused Code introduced by
The parameter $rel is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
203
        array $options,
204
        $textmore,
0 ignored issues
show
Unused Code introduced by
The parameter $textmore is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
205
        $selected = null,
206
        $preset = null,
207
        $selectedstart = null,
208
        $selectedstop = null
209
    ) {
210
        $dropdown = '<div id="' . $name . '"><p class="smallworld_clonebreaker">' . _SMALLWORLD_SCHOOLNAME . '<input class="school" type="text" value="' . $preset . '" name="' . $name2 . '[]">';
211
        $dropdown .= '<br><br>' . _SMALLWORLD_SCHOOLTYPE . '<select class="school" name="' . $name . '[]" id="' . $name . '"">' . '<br>';
212 View Code Duplication
        foreach ($options as $key => $option) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
213
            $select   = $selected == $key ? ' selected="selected"' : null;
214
            $dropdown .= '<option  class="school" value="' . $key . '"' . $select . '>' . $option . '</option>' . '<br>';
215
        }
216
        $dropdown .= '</select>';
217
        $dropdown .= '<br><br>';
218
        $dropdown .= _SMALLWORLD_START . '<select class="schooltime" name="schoolstart[]" id="schoolstart">';
219
        $array    = SmallworldGetTimestampsToForm();
220 View Code Duplication
        foreach ($array as $key => $option) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
221
            $selectstart = $selectedstart == $key ? ' selected="selected"' : null;
222
            $dropdown    .= '<option value="' . $key . '"' . $selectstart . '>' . $option . '</option>' . '<br>';
223
        }
224
        $dropdown .= '</select>';
225
        $dropdown .= '<br><br>';
226
        $dropdown .= _SMALLWORLD_STOP . '<select class="schooltime" name="schoolstop[]" id="schoolstop">';
227
        $array    = SmallworldGetTimestampsToForm();
228 View Code Duplication
        foreach ($array as $key => $option) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
229
            $selectstop = $selectedstop == $key ? ' selected="selected"' : null;
230
            $dropdown   .= '<option value="' . $key . '"' . $selectstop . '>' . $option . '</option>' . '<br>';
231
        }
232
        $dropdown .= '</select><br></p></div>';
233
234
        return $dropdown;
235
    }
236
237
    /**
238
     * @param string  $class
239
     * @param string  $name
240
     * @param         $name2
241
     * @param string  $rel
242
     * @param string  $textmore
243
     * @param string  $employer      (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $employer not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
244
     * @param string  $position      (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $position not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
245
     * @param string  $selectedstart (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $selectedstart not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
246
     * @param string  $selectedstop  (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $selectedstop not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
247
     * @param string  $description   (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $description not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
248
     * @return dynamic|string
249
     */
250
    public function job(
251
        $class,
0 ignored issues
show
Unused Code introduced by
The parameter $class is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
252
        $name,
253
        $name2,
0 ignored issues
show
Unused Code introduced by
The parameter $name2 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
254
        $rel,
0 ignored issues
show
Unused Code introduced by
The parameter $rel is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
255
        $textmore,
0 ignored issues
show
Unused Code introduced by
The parameter $textmore is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
256
        $employer = null,
257
        $position = null,
258
        $selectedstart = null,
259
        $selectedstop = null,
260
        $description = null
261
    ) {
262
        $text = '<div id="' . $name . '"><p class="smallworld_clonebreaker">' . _SMALLWORLD_EMPLOYER . '<input class="job" id="job" value="' . $employer . '" type="text" name="employer[]">';
263
        $text .= '<br><br>' . _SMALLWORLD_POSITION . '<input class="job" type="text" value="' . $position . '" name="position[]">';
264
        $text .= '<br><br>' . _SMALLWORLD_JOBSTART . '<input class="jobstart" type="text" value="' . $selectedstart . '" name="jobstart[]">';
265
        $text .= '<br><br>' . _SMALLWORLD_JOBSTOP . '<input class="jobstop" value="' . $selectedstop . '" type="text" name="jobstop[]">';
266
        $text .= '<br><br><span class="jobdescText">' . _SMALLWORLD_DESCRIPTION . '</span><textarea class="jobdesc" name="description[]" rows="20" cols="20">' . $description . '</textarea><br></p></div>';
267
        $text .= '' . '<br>';
268
269
        return $text;
270
    }
271
272
    /**
273
     * @param int $userID
274
     * @return file|string
275
     * @return string
276
     */
277
    public function uploadform($userID)
0 ignored issues
show
Unused Code introduced by
The parameter $userID is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
278
    {
279
        $text = '<form action="../imgupload.php" method="POST" enctype="multipart/form-data">';
280
        $text .= '<input type="file" name="file[]" multiple>';
281
        $text .= '<button type="submit">' . _SMALLWORLD_UPLOADTEXT . '</button>';
282
        $text .= '<span class="file_upload_label">' . _SMALLWORLD_UPLOADFILESTEXT . '</span>';
283
        $text .= '</form>';
284
285
        return $text;
286
    }
287
288
    /**
289
     * @param int    $userID
290
     * @param string $imgurl
291
     * @param string $imgdesc
292
     * @param string $id
293
     * @return dynamic|string
294
     * @return string
295
     */
296
    public function edit_images($userID, $imgurl, $imgdesc, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $userID is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
297
    {
298
        global $xoopsUser;
299
        $text = '<p class="smallworld_clonebreaker"><br>';
300
        $text .= '<table class="smallworld_table" border="0" cellspacing="0" cellpadding="0">';
301
        $text .= '<tr>';
302
        $text .= '<td><img class="smallworld_edit_image" src="' . $imgurl . '" height="100px" width="80px;"></td>';
303
        $text .= '<td><span class="smallworld_editTextSpan">' . _SMALLWORLD_UPLOADDESC . '</span><br><br><textarea class="smallworld_edit_desc" name="imgdesc[]" rows="1" cols="1">' . stripslashes($imgdesc) . '</textarea><br><br></td>';
304
        $text .= '<input value="' . $id . '" type="hidden" name="id[]"></p>';
305
        $text .= '</tr></table>';
306
307
        return $text;
308
    }
309
310
    /**
311
     * @create a radio select
312
     * @param $userid
313
     * @return string
314
     */
315
    public function usersettings($userid)
316
    {
317
        global $xoopsUser, $xoopsDB;
318
319
        $form = "<div style='display:none'><div class='smallworld_usersetings'>";
320
        $form .= '<fieldset><legend>' . _SMALLWORLD_SHOWIFPUBLICORPRIVATE . '</legend>';
321
        $form .= "<form id='perset'>";
322
        if ($xoopsUser) {
323
            $sql    = 'SELECT value FROM ' . $xoopsDB->prefix('smallworld_settings') . ' WHERE userid = ' . (int)$userid;
324
            $result = $xoopsDB->queryF($sql);
325
            $i      = $xoopsDB->getRowsNum($result);
326
            $v      = [];
0 ignored issues
show
Unused Code introduced by
$v is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
327
            if ($i >= 1) {
328
                while (false !== ($row = $xoopsDB->fetchArray($result))) {
329
                    $v    = unserialize(stripslashes($row['value']));
330
                    $pv   = ('1' == $v['posts']) ? ' checked' : '';
331
                    $cv   = ('1' == $v['comments']) ? ' checked' : '';
332
                    $nv   = ('1' == $v['notify']) ? ' checked' : '';
333
                    $form .= '<input type="checkbox" name="usersettings[]" id="posts" value="' . $v['posts'] . '" ' . $pv . '> ' . _SMALLWORLD_SHOWMYPOSTS . '<br>';
334
                    $form .= '<input type="checkbox" name="usersettings[]" id="comments" value="' . $v['comments'] . '" ' . $cv . '> ' . _SMALLWORLD_SHOWMYCOMMENTS . '<br>';
335
                    $form .= '<input type="checkbox" name="usersettings[]" id="notify" value="' . $v['notify'] . '" ' . $nv . '> ' . _SMALLWORLD_NOTIFYME . '<br>';
336
                }
337
            } else {
338
                $form .= '<input type="checkbox" name="usersettings[]" id="posts" value="0"> ' . _SMALLWORLD_SHOWMYPOSTS . '<br>';
339
                $form .= '<input type="checkbox" name="usersettings[]" id="comments" value="0"> ' . _SMALLWORLD_SHOWMYCOMMENTS . '<br>';
340
                $form .= '<input type="checkbox" name="usersettings[]" id="notify" value="0"> ' . _SMALLWORLD_NOTIFYME . '<br>';
341
            }
342
        }
343
        $form .= "<br><input type='submit' id='smallworld_privsave' value='" . _SMALLWORLD_SUBMIT . "' class='smallworld_finish'>";
344
        $form .= '</form></fieldset></div></div>';
345
346
        return $form;
347
    }
348
}
349