Completed
Push — master ( 060750...09b9fe )
by Gino
07:17 queued 03:29
created

ClassFormElements::getXoopsFormTextArea()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 9
rs 9.6667
cc 1
eloc 6
nc 1
nop 3
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 29 and the first side effect is on line 24.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
 * tdmcreate module.
14
 *
15
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 *
18
 * @since           2.5.0
19
 *
20
 * @author          Txmod Xoops http://www.txmodxoops.org
21
 *
22
 * @version         $Id: ClassFormElements.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
defined('XOOPS_ROOT_PATH') or die('Restricted access');
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
25
26
/**
27
 * Class ClassFormElements.
28
 */
29
class ClassFormElements extends TDMCreateFile
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
30
{
31
    /*
32
    *  @public function constructor
33
    *  @param null
34
    */
35
    /**
36
     *
37
     */
38
    public function __construct()
39
    {
40
        parent::__construct();
41
        $this->tdmcreate = TDMCreateHelper::getInstance();
42
        $this->tdmcfile = TDMCreateFile::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like \TDMCreateFile::getInstance() of type object<TDMCreateFile> is incompatible with the declared type string of property $tdmcfile.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
43
    }
44
45
    /*
46
    *  @static function &getInstance
47
    *  @param null
48
    */
49
    /**
50
     * @return ClassFormElements
51
     */
52
    public static function &getInstance()
53
    {
54
        static $instance = false;
55
        if (!$instance) {
56
            $instance = new self();
57
        }
58
59
        return $instance;
60
    }
61
62
    /*
63
    *  @public function initForm
64
    *  @param string $module
65
    *  @param string $table
66
    */
67
    /**
68
     * @param $module
69
     * @param $table
70
     */
71
    public function initForm($module, $table)
72
    {
73
        $this->setModule($module);
74
        $this->setTable($table);
75
    }
76
77
    /*
78
    *  @private function getXoopsFormText
79
    *  @param string $language
80
    *  @param string $fieldName
81
    *  @param string $required
82
    */
83
    /**
84
     * @param $language
85
     * @param $fieldName
86
     * @param $required
87
     *
88
     * @return string
89
     */
90
    private function getXoopsFormText($language, $fieldName, $fieldDefault, $required = 'false')
91
    {
92
        $ucfFieldName = $this->tdmcfile->getCamelCase($fieldName, true);
0 ignored issues
show
Bug introduced by
The method getCamelCase cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
93
        $ccFieldName = $this->tdmcfile->getCamelCase($fieldName, false, true);
0 ignored issues
show
Bug introduced by
The method getCamelCase cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
94
        if ($fieldDefault != '') {
95
            $ret = <<<EOT
96
        // Form Text {$ucfFieldName}
97
		\${$ccFieldName} = \$this->isNew() ? '{$fieldDefault}' : \$this->getVar('{$fieldName}');
98
        \$form->addElement( new XoopsFormText({$language}, '{$fieldName}', 20, 150, \${$ccFieldName}){$required} );\n
99
EOT;
100
        } else {
101
            $ret = <<<EOT
102
        // Form Text {$ucfFieldName}
103
        \$form->addElement( new XoopsFormText({$language}, '{$fieldName}', 50, 255, \$this->getVar('{$fieldName}')){$required} );\n
104
EOT;
105
        }
106
107
        return $ret;
108
    }
109
110
    /*
111
    *  @private function getXoopsFormText
112
    *  @param string $language
113
    *  @param string $fieldName
114
    *  @param string $required
115
    */
116
    /**
117
     * @param        $language
118
     * @param        $fieldName
119
     * @param string $required
120
     *
121
     * @return string
122
     */
123
    private function getXoopsFormTextArea($language, $fieldName, $required = 'false')
124
    {
125
        $ret = <<<EOT
126
        // Form Text Area
127
        \$form->addElement( new XoopsFormTextArea({$language}, '{$fieldName}', \$this->getVar('{$fieldName}'), 4, 47){$required} );\n
128
EOT;
129
130
        return $ret;
131
    }
132
133
    /*
134
    *  @private function getXoopsFormDhtmlTextArea
135
    *  @param string $language
136
    *  @param string $moduleDirname
137
    *  @param string $fieldName
138
    *  @param string $required
139
    */
140
    /**
141
     * @param        $language
142
     * @param        $moduleDirname
143
     * @param        $fieldName
144
     * @param string $required
145
     *
146
     * @return string
147
     */
148
    private function getXoopsFormDhtmlTextArea($language, $moduleDirname, $fieldName, $required = 'false')
149
    {
150
        $rpFieldName = $this->tdmcfile->getRightString($fieldName);
0 ignored issues
show
Bug introduced by
The method getRightString cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
151
        $ret = <<<EOT
152
        // Form Dhtml Text Area
153
        \$editor_configs = array();
154
        \$editor_configs['name'] = '{$fieldName}';
155
        \$editor_configs['value'] = \$this->getVar('{$fieldName}', 'e');
156
        \$editor_configs['rows'] = 5;
157
        \$editor_configs['cols'] = 40;
158
        \$editor_configs['width'] = '100%';
159
        \$editor_configs['height'] = '400px';
160
        \$editor_configs['editor'] = \$this->{$moduleDirname}->getConfig('{$moduleDirname}_editor_{$rpFieldName}');
161
        \$form->addElement( new XoopsFormEditor({$language}, '{$fieldName}', \$editor_configs){$required} );\n
162
EOT;
163
164
        return $ret;
165
    }
166
167
    /*
168
    *  @private function getXoopsFormCheckBox
169
    *  @param string $language
170
    *  @param string $fieldName
171
    *  @param string $required
172
    */
173
    /**
174
     * @param        $language
175
     * @param        $fieldName
176
     * @param string $required
177
     *
178
     * @return string
179
     */
180
    private function getXoopsFormCheckBox($language, $tableSoleName, $fieldName, $fieldElementId, $required = 'false')
181
    {
182
        $stuTableSoleName = strtoupper($tableSoleName);
183
        $ucfFieldName = $this->tdmcfile->getCamelCase($fieldName, true);
0 ignored issues
show
Bug introduced by
The method getCamelCase cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
184
        $ccFieldName = $this->tdmcfile->getCamelCase($fieldName, false, true);
0 ignored issues
show
Bug introduced by
The method getCamelCase cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
185
        if (in_array(5, $fieldElementId) > 1) {
186
            $ret = <<<EOT
187
        // Form Check Box List Array
188
		\$checkOption          = \$this->getOptions();
189
        \$check{$ucfFieldName} = new XoopsFormCheckbox('<hr />', '{$tableSoleName}_option', \$checkOption, false);
190
        \$check{$ucfFieldName}->setDescription({$language}{$stuTableSoleName}_OPTIONS_DESC);
191
        foreach(\$this->options as \$option) {
192
            \$check{$ucfFieldName}->addOption(\$option, {$language}{$stuTableSoleName}_ . strtoupper(\$option));
193
        }
194
		\$form->addElement(\$check{$ucfFieldName}{$required} );\n
195
EOT;
196
        } else {
197
            $ret = <<<EOT
198
        // Form Check Box
199
        \${$ccFieldName} = \$this->isNew() ? 0 : \$this->getVar('{$fieldName}');
200
        \$check{$ucfFieldName} = new XoopsFormCheckBox({$language}, '{$fieldName}', \${$ccFieldName});
201
        \$check{$ucfFieldName}->addOption(1, " ");
202
        \$form->addElement( \$check{$ucfFieldName}{$required} );\n
203
EOT;
204
        }
205
206
        return $ret;
207
    }
208
209
    /*
210
    *  @private function getXoopsFormHidden
211
    *  @param string $fieldName
212
    */
213
    /**
214
     * @param $fieldName
215
     *
216
     * @return string
217
     */
218
    private function getXoopsFormHidden($fieldName)
219
    {
220
        $ret = <<<EOT
221
        // Form Hidden
222
        \$form->addElement( new XoopsFormHidden('{$fieldName}', \$this->getVar('{$fieldName}')) );\n
223
EOT;
224
225
        return $ret;
226
    }
227
228
    /*
229
    *  @private function getXoopsFormImageList
230
    *  @param string $language
231
    *  @param string $moduleDirname
232
    *  @param string $tableName
233
    *  @param string $fieldName
234
    *  @param string $required
235
    */
236
    /**
237
     * @param        $language
238
     * @param        $moduleDirname
239
     * @param        $tableName
240
     * @param        $tableSoleName
241
     * @param        $fieldName
242
     * @param string $required
243
     *
244
     * @return string
245
     */
246
    private function getXoopsFormImageList($language, $moduleDirname, $tableName, $tableSoleName, $fieldName, $required = 'false')
247
    {
248
        $stuTableName = strtoupper($tableName);
249
        $stuFieldName = strtoupper($fieldName);
0 ignored issues
show
Unused Code introduced by
$stuFieldName 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...
250
        $rpFieldName = $this->tdmcfile->getRightString($fieldName);
0 ignored issues
show
Bug introduced by
The method getRightString cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
251
        $stuSoleName = strtoupper($tableSoleName.'_'.$rpFieldName);
252
        $ucfFieldName = $this->tdmcfile->getCamelCase($fieldName, true);
0 ignored issues
show
Bug introduced by
The method getCamelCase cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
253
        $ccFieldName = $this->tdmcfile->getCamelCase($fieldName, false, true);
0 ignored issues
show
Bug introduced by
The method getCamelCase cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
254
        $ret = <<<EOT
255
        // Form Frameworks Image Files
256
        \$get{$ucfFieldName} = \$this->getVar('{$fieldName}');
257
        \${$ccFieldName} = \$get{$ucfFieldName} ? \$get{$ucfFieldName} : 'blank.gif';
258
        \$imageDirectory = '/Frameworks/moduleclasses/icons/32';
259
        \$imageTray = new XoopsFormElementTray({$language}{$stuSoleName},'<br />');
260
        \$imageSelect = new XoopsFormSelect(sprintf({$language}FORM_IMAGE_PATH, ".{\$imageDirectory}/"), '{$fieldName}', \${$ccFieldName}, 5);
261
        \$imageArray = XoopsLists::getImgListAsArray( XOOPS_ROOT_PATH . \$imageDirectory );
262
        foreach( \$imageArray as \$image1 ) {
263
            \$imageSelect->addOption("{\$image1}", \$image1);
264
        }
265
        \$imageSelect->setExtra( "onchange='showImgSelected(\"image1\", \"{$fieldName}\", \"".\$imageDirectory."\", \"\", \"".XOOPS_URL."\")'" );
266
        \$imageTray->addElement(\$imageSelect, false);
267
        \$imageTray->addElement( new XoopsFormLabel( '', "<br /><img src='".XOOPS_URL."/".\$imageDirectory."/".\${$ccFieldName}."' name='image1' id='image1' alt='' />" ) );
268
        // Form File
269
        \$fileSelectTray = new XoopsFormElementTray('','<br />');
270
        \$fileSelectTray->addElement(new XoopsFormFile({$language}FORM_IMAGE_LIST_{$stuTableName} , 'attachedfile', \$this->{$moduleDirname}->getConfig('maxsize')));
271
        \$fileSelectTray->addElement(new XoopsFormLabel(''));
272
        \$imageTray->addElement(\$fileSelectTray);
273
        \$form->addElement( \$imageTray{$required} );\n
274
EOT;
275
276
        return $ret;
277
    }
278
279
    /*
280
    *  @private function getXoopsFormSelectFile
281
    *  @param string $language
282
    *  @param string $moduleDirname
283
    *  @param string $fieldName
284
    *  @param string $fieldDefault
285
    *  @param string $fieldElement
286
    *  @param string $required
287
    */
288
    /**
289
     * @param        $language
290
     * @param        $moduleDirname
291
     * @param        $fieldName
292
     * @param        $fieldElement
293
     * @param string $required
294
     *
295
     * @return string
296
     */
297
    private function getXoopsFormSelectFile($language, $moduleDirname, $fieldName, $fieldElement, $required = 'false')
0 ignored issues
show
Unused Code introduced by
The parameter $fieldElement 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...
298
    {
299
        $ucfFieldName = $this->tdmcfile->getCamelCase($fieldName, true);
0 ignored issues
show
Bug introduced by
The method getCamelCase cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Unused Code introduced by
$ucfFieldName 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...
300
        $ccFieldName = $this->tdmcfile->getCamelCase($fieldName, false, true);
0 ignored issues
show
Bug introduced by
The method getCamelCase cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
301
        $ret = <<<EOT
302
        // Image Select or Upload
303
        if ( \$this->{$moduleDirname}->getConfig('useshots') ) {
304
            \${$ccFieldName} = \$this->getVar('{$fieldName}');
305
            \$uploadDirectory = '/uploads/{$moduleDirname}/images/shots';
306
            \${$moduleDirname}ShotImage = \${$fieldName} ? \${$fieldName} : 'blank.gif';
307
            //
308
            \$imageTray = new XoopsFormElementTray({$language}FORM_IMAGE,'<br />');
309
            \$imageSelect = new XoopsFormSelect(sprintf({$language}_FORM_PATH, \$uploadDirectory ), 'selected_image',\${$moduleDirname}ShotImage);
310
            \$imageArray = XoopsLists::getImgListAsArray( XOOPS_ROOT_PATH . \$uploadDirectory );
311
            foreach( \$imageArray as \$image ) {
312
                \$imageSelect->addOption("{\$image}", \$image);
313
            }
314
            \$imageSelect->setExtra( "onchange='showImgSelected(\"image3\", \"selected_image\", \"" . \$uploadDirectory . "\", \"\", \"" . XOOPS_URL . "\")'" );
315
            \$imageTray->addElement(\$imageSelect,false);
316
            \$imageTray -> addElement( new XoopsFormLabel( '', "<br /><img src='" . XOOPS_URL . "/" . \$uploadDirectory . "/" . \${$moduleDirname}ShotImage . "' name='image3' id='image3' alt='' />" ) );
317
            \$fileSelectTray= new XoopsFormElementTray('','<br />');
318
            //if (\$permissionUpload == true) {
319
                \$fileSelectTray->addElement(new XoopsFormFile({$language}_FORM_UPLOAD , 'attachedimage', \$this->{$moduleDirname}->getConfig('maxuploadsize')){$required});
320
            //}
321
            \$imageTray->addElement(\$fileSelectTray);
322
            \$form->addElement(\$imageTray);
323
        }\n
324
EOT;
325
326
        return $ret;
327
    }
328
329
    /*
330
    *  @private function getXoopsFormUrlFile
331
    *  @param string $language
332
    *  @param string $moduleDirname
333
    *  @param string $fieldName
334
    *  @param string $fieldDefault
335
    *  @param string $fieldElement
336
    *  @param string $required
337
    */
338
    /**
339
     * @param        $language
340
     * @param        $moduleDirname
341
     * @param        $fieldName
342
     * @param        $fieldDefault
343
     * @param        $fieldElement
344
     * @param string $required
345
     *
346
     * @return string
347
     */
348
    private function getXoopsFormUrlFile($language, $moduleDirname, $fieldName, $fieldDefault, $fieldElement, $required = 'false')
0 ignored issues
show
Unused Code introduced by
The parameter $fieldElement 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...
349
    {
350
        $ret = <<<EOT
351
        // Form Url Text File
352
        \$formUrlFile = new XoopsFormElementTray({$language}FORM_FILE,'<br /><br />');
353
        \$formUrl     = \$this->isNew() ? '{$fieldDefault}' : \$this->getVar('{$fieldName}');
354
        \$formText    = new XoopsFormText({$language}FORM_TEXT, '{$fieldName}', 75, 255, \$formUrl);
355
        \$formUrlFile->addElement(\$formText{$required} );
356
        \$formUrlFile->addElement(new XoopsFormFile({$language}FORM_UPLOAD , 'attachedfile', \$this->{$moduleDirname}->getConfig('maxsize')){$required});
357
        \$form->addElement(\$formUrlFile);\n
358
EOT;
359
360
        return $ret;
361
    }
362
363
    /*
364
    *  @private function getXoopsFormUploadImage
365
    *  @param string $language
366
    *  @param string $moduleDirname
367
    *  @param string $tableName
368
    *  @param string $required
369
    */
370
    /**
371
     * @param        $language
372
     * @param        $moduleDirname
373
     * @param        $tableName
374
     * @param string $required
375
     *
376
     * @return string
377
     */
378
    private function getXoopsFormUploadImage($language, $moduleDirname, $tableName, $tableSoleName, $fieldName, $required = 'false')
379
    {
380
        $stuModuleDirname = strtoupper($moduleDirname);
0 ignored issues
show
Unused Code introduced by
$stuModuleDirname 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...
381
        $stuTableName = strtoupper($tableName);
382
        $stuSoleName = strtoupper($tableSoleName);
383
        $ucfFieldName = $this->tdmcfile->getCamelCase($fieldName, true);
0 ignored issues
show
Bug introduced by
The method getCamelCase cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
384
        $ccFieldName = $this->tdmcfile->getCamelCase($fieldName, false, true);
0 ignored issues
show
Bug introduced by
The method getCamelCase cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
385
        $ret = <<<EOT
386
        // Form Upload Image
387
        \$get{$ucfFieldName} = \$this->getVar('{$fieldName}');
388
        \${$ccFieldName} = \$get{$ucfFieldName} ? \$get{$ucfFieldName} : 'blank.gif';
389
        \$imageDirectory = '/uploads/{$moduleDirname}/images/{$tableName}';
390
        //
391
        \$imageTray   = new XoopsFormElementTray({$language}{$stuSoleName}_IMAGE,'<br />');
392
        \$imageSelect = new XoopsFormSelect(sprintf({$language}FORM_IMAGE_PATH, ".{\$imageDirectory}/"), '{$fieldName}', \${$ccFieldName}, 5);
393
        \$imageArray  = XoopsLists::getImgListAsArray( XOOPS_ROOT_PATH . \$imageDirectory );
394
        foreach( \$imageArray as \$image ) {
395
            \$imageSelect->addOption("{\$image}", \$image);
396
        }
397
        \$imageSelect->setExtra( "onchange='showImgSelected(\"image2\", \"{$fieldName}\", \"".\$imageDirectory."\", \"\", \"".XOOPS_URL."\")'" );
398
        \$imageTray->addElement(\$imageSelect, false);
399
        \$imageTray->addElement( new XoopsFormLabel( '', "<br /><img src='".XOOPS_URL."/".\$imageDirectory."/".\${$ccFieldName}."' name='image2' id='image2' alt='' />" ) );
400
        // Form File
401
        \$fileSelectTray = new XoopsFormElementTray('','<br />');
402
        \$fileSelectTray->addElement(new XoopsFormFile({$language}FORM_UPLOAD_IMAGE_{$stuTableName} , 'attachedfile', \$this->{$moduleDirname}->getConfig('maxsize')));
403
        \$fileSelectTray->addElement(new XoopsFormLabel(''));
404
        \$imageTray->addElement(\$fileSelectTray);
405
        \$form->addElement( \$imageTray{$required} );\n
406
EOT;
407
408
        return $ret;
409
    }
410
411
    /*
412
    *  @private function getXoopsFormUploadFile
413
    *  @param string $language
414
    *  @param string $moduleDirname
415
    *  @param string $tableName
416
    *  @param string $fieldName
417
    *  @param string $required
418
    */
419
    /**
420
     * @param        $language
421
     * @param        $moduleDirname
422
     * @param        $tableName
423
     * @param        $fieldName
424
     * @param string $required
425
     *
426
     * @return string
427
     */
428
    private function getXoopsFormUploadFile($language, $moduleDirname, $tableName, $fieldName, $required = 'false')
429
    {
430
        $stuTableName = strtoupper($tableName);
431
        $ret = <<<EOT
432
        // Form file
433
        \$form->addElement( new XoopsFormFile({$language}FORM_UPLOAD_FILE_{$stuTableName}, '{$fieldName}', \$this->{$moduleDirname}->getConfig('maxsize')){$required} );\n
434
EOT;
435
436
        return $ret;
437
    }
438
439
    /*
440
    *  @private function getXoopsFormColorPicker
441
    *  @param string $language
442
    *  @param string $fieldName
443
    *  @param string $required
444
    */
445
    /**
446
     * @param        $language
447
     * @param        $moduleDirname
448
     * @param        $fieldName
449
     * @param string $required
450
     *
451
     * @return string
452
     */
453
    private function getXoopsFormColorPicker($language, $moduleDirname, $fieldName, $required = 'false')
454
    {
455
        $ret = <<<EOT
456
        // Form Color Picker
457
        \$form->addElement( new XoopsFormColorPicker({$language}, '{$fieldName}', \$this->{$moduleDirname}->getConfig('maxsize')){$required} );\n
458
EOT;
459
460
        return $ret;
461
    }
462
463
    /*
464
    *  @private function getXoopsFormSelectBox
465
    *  @param string $language
466
    *  @param string $tableName
467
    *  @param string $fieldName
468
    *  @param string $required
469
    */
470
    /**
471
     * @param $language
472
     * @param $moduleDirname
473
     * @param $tableName
474
     * @param $fieldName
475
     * @param $required
476
     *
477
     * @return string
478
     */
479 View Code Duplication
    private function getXoopsFormSelectBox($language, $moduleDirname, $tableName, $fieldName, $required = 'false')
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...
480
    {
481
        $ucfTableName = ucfirst($tableName);
482
        $ccFieldName = $this->tdmcfile->getCamelCase($fieldName, false, true);
0 ignored issues
show
Bug introduced by
The method getCamelCase cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
483
        $ret = <<<EOT
484
        // {$ucfTableName} handler
485
		\${$tableName}Handler =& \$this->{$moduleDirname}->getHandler('{$tableName}');
486
		// Form Select
487
        \${$ccFieldName}Select = new XoopsFormSelect({$language}, '{$fieldName}', \$this->getVar('{$fieldName}'));
488
        \${$ccFieldName}Select->addOption('Empty');
489
        \${$ccFieldName}Select->addOptionArray(\${$tableName}Handler->getList());
490
        \$form->addElement( \${$ccFieldName}Select{$required} );\n
491
EOT;
492
493
        return $ret;
494
    }
495
496
    /*
497
    *  @private function getXoopsFormSelectUser
498
    *  @param string $language
499
    *  @param string $fieldName
500
    *  @param string $required
501
    */
502
    /**
503
     * @param        $language
504
     * @param        $fieldName
505
     * @param string $required
506
     *
507
     * @return string
508
     */
509
    private function getXoopsFormSelectUser($language, $fieldName, $required = 'false')
510
    {
511
        $ret = <<<EOT
512
        // Form Select User
513
        \$form->addElement( new XoopsFormSelectUser({$language}, '{$fieldName}', false, \$this->getVar('{$fieldName}'), 1, false){$required} );\n
514
EOT;
515
516
        return $ret;
517
    }
518
519
    /*
520
    *  @private function getXoopsFormRadioYN
521
    *  @param string $language
522
    *  @param string $fieldName
523
    *  @param string $required
524
    */
525
    /**
526
     * @param        $language
527
     * @param        $fieldName
528
     * @param string $required
529
     *
530
     * @return string
531
     */
532
    private function getXoopsFormRadioYN($language, $fieldName, $required = 'false')
533
    {
534
        $ccFieldName = $this->tdmcfile->getCamelCase($fieldName, false, true);
0 ignored issues
show
Bug introduced by
The method getCamelCase cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
535
        $ret = <<<EOT
536
        // Form Radio Yes/No
537
        \${$ccFieldName} = \$this->isNew() ? 0 : \$this->getVar('{$fieldName}');
538
        \$form->addElement( new XoopsFormRadioYN({$language}, '{$fieldName}', \${$ccFieldName}){$required} );\n
539
EOT;
540
541
        return $ret;
542
    }
543
544
    /*
545
    *  @private function getXoopsFormTextDateSelect
546
    *  @param string $language
547
    *  @param string $fieldName
548
    *  @param string $required
549
    */
550
    /**
551
     * @param        $language
552
     * @param        $moduleDirname
553
     * @param        $fieldName
554
     * @param string $required
555
     *
556
     * @return string
557
     */
558
    private function getXoopsFormTextDateSelect($language, $moduleDirname, $fieldName, $required = 'false')
0 ignored issues
show
Unused Code introduced by
The parameter $moduleDirname 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...
559
    {
560
        $ret = <<<EOT
561
        // Form Text Date Select
562
        \$form->addElement( new XoopsFormTextDateSelect({$language}, '{$fieldName}', '', \$this->getVar('{$fieldName}')){$required} );\n
563
EOT;
564
565
        return $ret;
566
    }
567
568
    /*
569
    *  @private function getXoopsFormTable
570
    *  @param string $language
571
    *  @param string $moduleDirname
572
    *  @param string $table
573
    *  @param string $fields
574
    *  @param string $required
575
    */
576
    /**
577
     * @param        $language
578
     * @param        $moduleDirname
579
     * @param        $tableName
580
     * @param        $fieldName
581
     * @param        $fieldElement
582
     * @param string $required
583
     *
584
     * @return string
585
     */
586
    private function getXoopsFormTable($language, $moduleDirname, $tableName, $fieldName, $fieldElement, $required = 'false')
587
    {
588
        $ucfTableName = ucfirst($tableName);
589
        if ($fieldElement > 15) {
590
            $fElement = $this->tdmcreate->getHandler('fieldelements')->get($fieldElement);
591
            $rpFieldelementName = strtolower(str_replace('Table : ', '', $fElement->getVar('fieldelement_name')));
592
        }
593
        $ccFieldName = $this->tdmcfile->getCamelCase($fieldName, false, true);
0 ignored issues
show
Bug introduced by
The method getCamelCase cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
594
        $ret = <<<EOT
595
        // Form Table {$ucfTableName}
596
        \${$rpFieldelementName}Handler =& \$this->{$moduleDirname}->getHandler('{$rpFieldelementName}');
0 ignored issues
show
Bug introduced by
The variable $rpFieldelementName does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
597
        \${$ccFieldName}Select = new XoopsFormSelect({$language}, '{$fieldName}', \$this->getVar('{$fieldName}'));
598
        \${$ccFieldName}Select->addOptionArray(\${$rpFieldelementName}Handler->getList());
599
        \$form->addElement( \${$ccFieldName}Select{$required} );\n
600
EOT;
601
602
        return $ret;
603
    }
604
605
    /*
606
    *  @private function getXoopsFormTopic
607
    *  @param string $language
608
    *  @param string $moduleDirname
609
    *  @param string $table
610
    *  @param string $fields
611
    *  @param string $required
612
    */
613
    /**
614
     * @param        $language
615
     * @param        $moduleDirname
616
     * @param        $table
617
     * @param        $fields
618
     * @param string $required
619
     *
620
     * @return string
621
     */
622
    private function getXoopsFormTopic($language, $moduleDirname, $topicTableName, $fieldId, $fieldPid, $fieldMain, $required = 'false')
623
    {
624
        $ucfTopicTableName = ucfirst($topicTableName);
625
        $stlTopicTableName = strtolower($topicTableName);
626
        $ccFieldPid = $this->tdmcfile->getCamelCase($fieldPid, false, true);
0 ignored issues
show
Bug introduced by
The method getCamelCase cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
627
        $ret = <<<EOT
628
        // Form Topic {$ucfTopicTableName}
629
        \${$stlTopicTableName}Handler = \$this->{$moduleDirname}->getHandler('{$stlTopicTableName}');
630
        \$criteria = new CriteriaCompo();
631
        \${$stlTopicTableName}Count = \${$stlTopicTableName}Handler->getCount( \$criteria );
632
        if(\${$stlTopicTableName}Count) {
633
            include_once(XOOPS_ROOT_PATH . '/class/tree.php');
634
			\${$stlTopicTableName}All = \${$stlTopicTableName}Handler->getAll(\$criteria);
635
            \${$stlTopicTableName}Tree = new XoopsObjectTree( \${$stlTopicTableName}All, '{$fieldId}', '{$fieldPid}' );
636
            \${$ccFieldPid} = \${$stlTopicTableName}Tree->makeSelBox( '{$fieldPid}', '{$fieldMain}', '--', \$this->getVar('{$fieldPid}', 'e' ), true );
637
            \$form->addElement( new XoopsFormLabel ( {$language}, \${$ccFieldPid} ){$required} );
638
        }
639
		unset(\$criteria);\n
640
EOT;
641
642
        return $ret;
643
    }
644
645
    /*
646
    *  @private function getXoopsFormTag
647
    *  @param string $moduleDirname
648
    *  @param string $fieldId
649
    *  @param string $required
650
    */
651
    /**
652
     * @param        $moduleDirname
653
     * @param        $fieldId
654
     * @param string $required
655
     *
656
     * @return string
657
     */
658
    private function getXoopsFormTag($moduleDirname, $fieldId, $required = 'false')
659
    {
660
        $ret = <<<EOT
661
		// Use tag module
662
		\$dirTag = is_dir(XOOPS_ROOT_PATH . '/modules/tag') ? true : false;
663
        if ((\$this->{$moduleDirname}->getConfig('usetag') == 1) && \$dirTag){
664
            \$tagId = \$this->isNew() ? 0 : \$this->getVar('{$fieldId}');
665
            include_once XOOPS_ROOT_PATH.'/modules/tag/include/formtag.php';
666
            \$form->addElement(new XoopsFormTag('tag', 60, 255, \$tagId, 0){$required});
667
        }\n
668
EOT;
669
670
        return $ret;
671
    }
672
673
    /*
674
    *  @public function renderElements
675
    *  @param null
676
    */
677
    /**
678
     * @return string
679
     */
680
    public function renderElements()
681
    {
682
        $module = $this->getModule();
683
        $table = $this->getTable();
684
        $moduleDirname = $module->getVar('mod_dirname');
685
        $tableName = $table->getVar('table_name');
686
        $tableSoleName = $table->getVar('table_solename');
687
        $languageFunct = $this->getLanguage($moduleDirname, 'AM');
688
        //$language_table = $languageFunct . strtoupper($tableName);
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
689
        $ret = '';
690
        $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'), 'field_order ASC, field_id');
691
        $fieldElementId = array();
692
        foreach (array_keys($fields) as $f) {
693
            $fieldName = $fields[$f]->getVar('field_name');
694
            $fieldDefault = $fields[$f]->getVar('field_default');
695
            $fieldElement = $fields[$f]->getVar('field_element');
696
            $fieldParent = $fields[$f]->getVar('field_parent');
697
            $fieldInForm = $fields[$f]->getVar('field_inform');
698
            if ((0 == $f) && (1 == $table->getVar('table_autoincrement'))) {
699
                $fieldId = $fieldName;
700
            }
701
            /*if (1 == $fields[$f]->getVar('field_parent')) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
702
                $fieldPid = $fieldName;
703
            }*/
704
            /*if (1 == $fields[$f]->getVar('field_main')) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
705
                $fieldMain = $fieldName;
706
            }*/
707
            $rpFieldName = $this->tdmcfile->getRightString($fieldName);
0 ignored issues
show
Bug introduced by
The method getRightString cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
708
            $language = $languageFunct.strtoupper($tableSoleName).'_'.strtoupper($rpFieldName);
709
            $required = (1 == $fields[$f]->getVar('field_required')) ? ', true' : '';
710
            //
711
            $fieldElements = $this->tdmcreate->getHandler('fieldelements')->get($fieldElement);
712
            $fieldElementId[] = $fieldElements->getVar('fieldelement_id');
713
            //
714
            if (1 == $fieldInForm) {
715
                // Switch elements
716
                switch ($fieldElement) {
717
                    case 1:
718
                        break;
719
                    case 2:
720
                        $ret .= $this->getXoopsFormText($language, $fieldName, $fieldDefault, $required);
721
                        break;
722
                    case 3:
723
                        $ret .= $this->getXoopsFormTextArea($language, $fieldName, $required);
724
                        break;
725
                    case 4:
726
                        $ret .= $this->getXoopsFormDhtmlTextArea($language, $moduleDirname, $fieldName, $required);
727
                        break;
728
                    case 5:
729
                        $ret .= $this->getXoopsFormCheckBox($language, $tableSoleName, $fieldName, $fieldElementId, $required);
730
                        break;
731
                    case 6:
732
                        $ret .= $this->getXoopsFormRadioYN($language, $fieldName, $required);
733
                        break;
734
                    case 7:
735
                        $ret .= $this->getXoopsFormSelectBox($language, $moduleDirname, $tableName, $fieldName, $required);
736
                        break;
737
                    case 8:
738
                        $ret .= $this->getXoopsFormSelectUser($language, $fieldName, $required);
739
                        break;
740
                    case 9:
741
                        $ret .= $this->getXoopsFormColorPicker($language, $moduleDirname, $fieldName, $required);
742
                        break;
743
                    case 10:
744
                        $ret .= $this->getXoopsFormImageList($languageFunct, $moduleDirname, $tableName, $tableSoleName, $fieldName, $required);
745
                        break;
746
                    case 11:
747
                        $ret .= $this->getXoopsFormSelectFile($language, $moduleDirname, $fieldName, $fieldElement, $required);
748
                        break;
749
                    case 12:
750
                        $ret .= $this->getXoopsFormUrlFile($language, $moduleDirname, $fieldName, $fieldDefault, $fieldElement, $required);
751
                        break;
752
                    case 13:
753
                        $ret .= $this->getXoopsFormUploadImage($languageFunct, $moduleDirname, $tableName, $tableSoleName, $fieldName, $required);
754
                        break;
755
                    case 14:
756
                        $ret .= $this->getXoopsFormUploadFile($language, $moduleDirname, $tableName, $fieldName, $required);
757
                        break;
758
                    case 15:
759
                        $ret .= $this->getXoopsFormTextDateSelect($language, $moduleDirname, $fieldName, $required);
760
                        break;
761
                    default:
762
                        // If we use tag module
763
                        if (1 == $table->getVar('table_tag')) {
764
                            $ret .= $this->getXoopsFormTag($moduleDirname, $fieldId, $required);
0 ignored issues
show
Bug introduced by
The variable $fieldId does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
765
                        }
766
                        // If we want to hide XoopsFormHidden() or field id
767
                        if ((0 == $f) && (1 == $table->getVar('table_autoincrement'))) {
768
                            $ret .= $this->getXoopsFormHidden($fieldName);
769
                        }
770
                        break;
771
                }
772
                /*if (($fieldElement <= 15)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
773
                    $ret .= $this->getXoopsFormTopic($language, $moduleDirname, $tableName, $fieldId, $fieldPid, $fieldMain, $required);
774
                }*/
775
                if ($fieldElement > 15) {
776
                    if (1 == $table->getVar('table_category') || (1 == $fieldParent)) {
777
                        $fieldElements = $this->tdmcreate->getHandler('fieldelements')->get($fieldElement);
778
                        $fieldElementMid = $fieldElements->getVar('fieldelement_mid');
779
                        $fieldElementTid = $fieldElements->getVar('fieldelement_tid');
780
                        $fieldElementName = $fieldElements->getVar('fieldelement_name');
781
                        $fieldNameDesc = substr($fieldElementName, strrpos($fieldElementName, ':'), strlen($fieldElementName));
782
                        $topicTableName = str_replace(': ', '', $fieldNameDesc);
783
                        $fieldsTopics = $this->getTableFields($fieldElementMid, $fieldElementTid);
784 View Code Duplication
                        foreach (array_keys($fieldsTopics) as $f) {
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...
785
                            $fieldNameTopic = $fieldsTopics[$f]->getVar('field_name');
786
                            if ((0 == $f) && (1 == $table->getVar('table_autoincrement'))) {
787
                                $fieldIdTopic = $fieldNameTopic;
788
                            }
789
                            if (1 == $fieldsTopics[$f]->getVar('field_parent')) {
790
                                $fieldPidTopic = $fieldNameTopic;
791
                            }
792
                            if (1 == $fieldsTopics[$f]->getVar('field_main')) {
793
                                $fieldMainTopic = $fieldNameTopic;
794
                            }
795
                        }
796
                        $ret .= $this->getXoopsFormTopic($language, $moduleDirname, $topicTableName, $fieldIdTopic, $fieldPidTopic, $fieldMainTopic, $required);
0 ignored issues
show
Bug introduced by
The variable $fieldIdTopic does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $fieldPidTopic does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $fieldMainTopic does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
797
                    } else {
798
                        $ret .= $this->getXoopsFormTable($language, $moduleDirname, $tableName, $fieldName, $fieldElement, $required);
799
                    }
800
                }
801
            }
802
        }
803
        unset($fieldElementId);
804
805
        return $ret;
806
    }
807
}
808