Completed
Pull Request — master (#5)
by Michael
02:20
created

Form   A

Complexity

Total Complexity 37

Size/Duplication

Total Lines 318
Duplicated Lines 6.29 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 20
loc 318
rs 9.44
c 0
b 0
f 0
wmc 37
lcom 0
cbo 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
A dropdown() 4 11 3
A radio() 0 10 3
A RetrieveRadio() 0 13 3
A input() 0 6 2
A hidden() 0 5 1
A simpleText() 0 5 1
A dropdown_add() 4 11 3
A input_add() 0 7 3
A textarea() 0 4 1
B school_add() 12 37 7
A job() 0 20 1
A uploadform() 0 9 1
A edit_images() 0 12 1
B usersettings() 0 32 7

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php namespace XoopsModules\Smallworld;
2
3
/**
4
 * You may not change or alter any portion of this comment or credits
5
 * of supporting developers from this source code or any supporting source code
6
 * which is considered copyrighted (c) material of the original comment or credit authors.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * SmallWorld
15
 *
16
 * @copyright    The XOOPS Project (https://xoops.org)
17
 * @copyright    2011 Culex
18
 * @license      GNU GPL (http://www.gnu.org/licenses/gpl-2.0.html/)
19
 * @package      SmallWorld
20
 * @since        1.0
21
 * @author       Michael Albertsen (http://culex.dk) <[email protected]>
22
 */
23
class Form
24
{
25
    /**
26
     * @create a dropdown select
27
     * @param string $name
28
     * @param array  $options
29
     * @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...
30
     * @return string
31
     */
32
    public function dropdown($name, array $options, $selected = null)
33
    {
34
        $dropdown = '<select name="' . $name . '" id="' . $name . '">' . '<br>';
35
        $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...
36 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...
37
            $select   = $selected == $key ? ' selected="yes"' : '';
38
            $dropdown .= '<option value="' . $key . '"' . $select . '>' . $option . '</option>' . '<br>';
39
        }
40
        $dropdown .= '</select>' . '<br>';
41
        return $dropdown;
42
    }
43
44
    /**
45
     * @create a radio select
46
     * @param string $name
47
     * @param array  $options
48
     * @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...
49
     * @return string
50
     */
51
    public function radio($name, array $options, $selected = null)
52
    {
53
        $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...
54
        $form     = '';
55
        foreach ($options as $value => $option) {
56
            $select = $selected == $value ? ' checked' : ' checked="unchecked"';
57
            $form   .= '<input type="checkbox" name="' . $name . '[]" id="' . $name . '" value="' . $value . '" ' . $select . '> ' . $option . '<br>';
58
        }
59
        return $form;
60
    }
61
62
    /**
63
     * @param string $name
64
     * @param array  $options
65
     * @param array  $valuearray
66
     * @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...
67
     * @return string
68
     */
69
    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...
70
    {
71
        $form = '';
72
        $a    = count($options) - 1;
73
        for ($i = 0; $i <= $a; ++$i) {
74
            if (in_array($i, $valuearray)) {
75
                $form .= '<input type="checkbox" id="' . $name . '-' . $i . '" name="' . $name . '[]" value="' . $i . '" checked>' . $options[$i] . '<br>';
76
            } else {
77
                $form .= '<input type="checkbox" id="' . $name . '-' . $i . '" name="' . $name . '[]" value="' . $i . '" >' . $options[$i] . '<br>';
78
            }
79
        }
80
        return $form;
81
    }
82
83
    /**
84
     * @param string $name
85
     * @param string $id
86
     * @param string $class
87
     * @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...
88
     * @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...
89
     * @return string
90
     */
91
    public function input($name, $id, $class, $size = null, $preset = null)
92
    {
93
        $s    = $size ?: '50px';
94
        $data = "<input type='text' size='" . $s . "' name='" . $name . "' id='" . $id . "' class='" . $class . "' value='" . $preset . "' >";
95
        return $data;
96
    }
97
98
    /**
99
     * @param string $name
100
     * @param string $id
101
     * @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...
102
     * @return string
103
     */
104
    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...
105
    {
106
        $data = "<input type='hidden' name='" . $name . "' value='" . $preset . "' >";
107
        return $data;
108
    }
109
110
    /**
111
     * @param string $value
112
     * @return string
113
     */
114
    public function simpleText($value)
115
    {
116
        $data = $value;
117
        return $data;
118
    }
119
120
    /**
121
     *
122
     * @param string  $class
123
     * @param string  $name
124
     * @param         $name2
125
     * @param string  $rel
126
     * @param array   $options
127
     * @param string  $textmore
128
     * @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...
129
     * @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...
130
     * @return as|string
131
     */
132
    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...
133
    {
134
        $dropdown = '<span id="' . $name . '"><input type="text" name="' . $name2 . '[]" value="' . $preset . '">';
135
        $dropdown .= '<select class="smallworld_select" name="' . $name . '[]" id="' . $name . '"></p>' . '<br>';
136 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...
137
            $select   = $selected == $key ? ' selected' : null;
138
            $dropdown .= '<option value="' . $key . '"' . $select . '>' . $option . '</option>' . '<br>';
139
        }
140
        $dropdown .= '</select></span>';
141
        return $dropdown;
142
    }
143
144
    /**
145
     *
146
     * @param string  $class
147
     * @param string  $name
148
     * @param         $name2
149
     * @param string  $rel
150
     * @param int     $size
151
     * @param string  $textmore
152
     * @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...
153
     * @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...
154
     * @return dynamic|string
155
     */
156
    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...
157
    {
158
        $s    = $size ?: '50px';
159
        $i    = $id ?: '';
160
        $data = "<span id='" . $name . "'><input type='text' size='" . $s . "' name='" . $name2 . "[]' value='" . $preset . "' id='" . $i . "'></span>";
161
        return $data;
162
    }
163
164
    /**
165
     * @param string $name
166
     * @param string $id
167
     * @param string $title
168
     * @param string $rows
169
     * @param string $cols
170
     * @param string $class
171
     * @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...
172
     * @return string|textarea
173
     * @return string
174
     */
175
    public function textarea($name, $id, $title, $rows, $cols, $class, $preset = null)
176
    {
177
        return "<textarea name='" . $name . "' id='" . $id . "'  title='" . $title . "' rows='" . $rows . "' cols='" . $cols . "' class='" . $class . "'>" . $preset . '</textarea>';
178
    }
179
180
    /**
181
     * @param string $class
182
     * @param string $name
183
     * @param string $name2
184
     * @param string $rel
185
     * @param array  $options
186
     * @param string $textmore
187
     * @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...
188
     * @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...
189
     * @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...
190
     * @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...
191
     * @return dynamic|string
192
     * @return string
193
     */
194
    public function school_add(
195
        $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...
196
        $name,
197
        $name2,
198
        $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...
199
        array $options,
200
        $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...
201
        $selected = null,
202
        $preset = null,
203
        $selectedstart = null,
204
        $selectedstop = null
205
    ) {
206
        $dropdown = '<div id="' . $name . '"><p class="smallworld_clonebreaker">' . _SMALLWORLD_SCHOOLNAME . '<input class="school" type="text" value="' . $preset . '" name="' . $name2 . '[]">';
207
        $dropdown .= '<br><br>' . _SMALLWORLD_SCHOOLTYPE . '<select class="school" name="' . $name . '[]" id="' . $name . '"">' . '<br>';
208 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...
209
            $select   = $selected == $key ? ' selected="selected"' : null;
210
            $dropdown .= '<option  class="school" value="' . $key . '"' . $select . '>' . $option . '</option>' . '<br>';
211
        }
212
        $dropdown .= '</select>';
213
        $dropdown .= '<br><br>';
214
        $dropdown .= _SMALLWORLD_START . '<select class="schooltime" name="schoolstart[]" id="schoolstart">';
215
        $array    = SmallworldGetTimestampsToForm();
216 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...
217
            $selectstart = $selectedstart == $key ? ' selected="selected"' : null;
218
            $dropdown    .= '<option value="' . $key . '"' . $selectstart . '>' . $option . '</option>' . '<br>';
219
        }
220
        $dropdown .= '</select>';
221
        $dropdown .= '<br><br>';
222
        $dropdown .= _SMALLWORLD_STOP . '<select class="schooltime" name="schoolstop[]" id="schoolstop">';
223
        $array    = SmallworldGetTimestampsToForm();
224 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...
225
            $selectstop = $selectedstop == $key ? ' selected="selected"' : null;
226
            $dropdown   .= '<option value="' . $key . '"' . $selectstop . '>' . $option . '</option>' . '<br>';
227
        }
228
        $dropdown .= '</select><br></p></div>';
229
        return $dropdown;
230
    }
231
232
    /**
233
     *
234
     * @param string  $class
235
     * @param string  $name
236
     * @param         $name2
237
     * @param string  $rel
238
     * @param string  $textmore
239
     * @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...
240
     * @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...
241
     * @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...
242
     * @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...
243
     * @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...
244
     * @return dynamic|string
245
     */
246
    public function job(
247
        $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...
248
        $name,
249
        $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...
250
        $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...
251
        $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...
252
        $employer = null,
253
        $position = null,
254
        $selectedstart = null,
255
        $selectedstop = null,
256
        $description = null
257
    ) {
258
        $text = '<div id="' . $name . '"><p class="smallworld_clonebreaker">' . _SMALLWORLD_EMPLOYER . '<input class="job" id="job" value="' . $employer . '" type="text" name="employer[]">';
259
        $text .= '<br><br>' . _SMALLWORLD_POSITION . '<input class="job" type="text" value="' . $position . '" name="position[]">';
260
        $text .= '<br><br>' . _SMALLWORLD_JOBSTART . '<input class="jobstart" type="text" value="' . $selectedstart . '" name="jobstart[]">';
261
        $text .= '<br><br>' . _SMALLWORLD_JOBSTOP . '<input class="jobstop" value="' . $selectedstop . '" type="text" name="jobstop[]">';
262
        $text .= '<br><br><span class="jobdescText">' . _SMALLWORLD_DESCRIPTION . '</span><textarea class="jobdesc" name="description[]" rows="20" cols="20">' . $description . '</textarea><br></p></div>';
263
        $text .= '' . '<br>';
264
        return $text;
265
    }
266
267
    /**
268
     * @param int $userID
269
     * @return file|string
270
     * @return string
271
     */
272
    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...
273
    {
274
        $text = '<form action="imgupload.php" method="POST" enctype="multipart/form-data">';
275
        $text .= '<input type="file" name="file[]" multiple>';
276
        $text .= '<button type="submit">' . _SMALLWORLD_UPLOADTEXT . '</button>';
277
        $text .= '<span class="file_upload_label">' . _SMALLWORLD_UPLOADFILESTEXT . '</span>';
278
        $text .= '</form>';
279
        return $text;
280
    }
281
282
    /**
283
     * @param int    $userID
284
     * @param string $imgurl
285
     * @param string $imgdesc
286
     * @param string $id
287
     * @return dynamic|string
288
     * @return string
289
     */
290
    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...
291
    {
292
        global $xoopsUser;
293
        $text = '<p class="smallworld_clonebreaker"><br>';
294
        $text .= '<table class="smallworld_table" border="0" cellspacing="0" cellpadding="0">';
295
        $text .= '<tr>';
296
        $text .= '<td><img class="smallworld_edit_image" src="' . $imgurl . '" height="100px" width="80px;"></td>';
297
        $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>';
298
        $text .= '<input value="' . $id . '" type="hidden" name="id[]"></p>';
299
        $text .= '</tr></table>';
300
        return $text;
301
    }
302
303
    /**
304
     * @create a radio select
305
     * @param $userid
306
     * @return string
307
     */
308
    public function usersettings($userid)
309
    {
310
        global $xoopsUser, $xoopsDB;
311
312
        $form = "<div style='display:none'><div class='smallworld_usersetings'>";
313
        $form .= '<fieldset><legend>' . _SMALLWORLD_SHOWIFPUBLICORPRIVATE . '</legend>';
314
        $form .= "<form id='perset'>";
315
        if ($xoopsUser) {
316
            $sql    = 'SELECT value FROM ' . $xoopsDB->prefix('smallworld_settings') . ' WHERE userid = ' . (int)$userid;
317
            $result = $xoopsDB->queryF($sql);
318
            $i      = $xoopsDB->getRowsNum($result);
319
            $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...
320
            if ($i >= 1) {
321
                while ($row = $xoopsDB->fetchArray($result)) {
322
                    $v    = unserialize(stripslashes($row['value']));
323
                    $pv   = ('1' == $v['posts']) ? ' checked' : '';
324
                    $cv   = ('1' == $v['comments']) ? ' checked' : '';
325
                    $nv   = ('1' == $v['notify']) ? ' checked' : '';
326
                    $form .= '<input type="checkbox" name="usersettings[]" id="posts" value="' . $v['posts'] . '" ' . $pv . '> ' . _SMALLWORLD_SHOWMYPOSTS . '<br>';
327
                    $form .= '<input type="checkbox" name="usersettings[]" id="comments" value="' . $v['comments'] . '" ' . $cv . '> ' . _SMALLWORLD_SHOWMYCOMMENTS . '<br>';
328
                    $form .= '<input type="checkbox" name="usersettings[]" id="notify" value="' . $v['notify'] . '" ' . $nv . '> ' . _SMALLWORLD_NOTIFYME . '<br>';
329
                }
330
            } else {
331
                $form .= '<input type="checkbox" name="usersettings[]" id="posts" value="0"> ' . _SMALLWORLD_SHOWMYPOSTS . '<br>';
332
                $form .= '<input type="checkbox" name="usersettings[]" id="comments" value="0"> ' . _SMALLWORLD_SHOWMYCOMMENTS . '<br>';
333
                $form .= '<input type="checkbox" name="usersettings[]" id="notify" value="0"> ' . _SMALLWORLD_NOTIFYME . '<br>';
334
            }
335
        }
336
        $form .= "<br><input type='submit' id='smallworld_privsave' value='" . _SMALLWORLD_SUBMIT . "' class='smallworld_finish'>";
337
        $form .= '</form></fieldset></div></div>';
338
        return $form;
339
    }
340
}
341