Passed
Push — master ( 31be8b...e5334d )
by Gino
04:04
created

TDMCreateXoopsCode::getXoopsCodeGetItemIds()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 6
1
<?php
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: TDMCreateXoopsCode.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
25
/**
26
 * Class TDMCreateXoopsCode.
27
 */
28
class TDMCreateXoopsCode
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...
29
{
30
    /*
31
    * @var mixed
32
    */
33
    private $tdmcfile = null;
34
35
    /*
36
    * @var mixed
37
    */
38
    private $phpcode = null;
39
40
    /*
41
    * @var string
42
    */
43
    protected $xoopscode;
44
45
    /*
46
    *  @public function constructor
47
    *  @param null
48
    */
49
    /**
50
     *
51
     */
52
    public function __construct()
53
    {
54
        $this->tdmcfile = TDMCreateFile::getInstance();
55
        $this->phpcode = TDMCreatePhpCode::getInstance();
56
    }
57
58
    /*
59
    *  @static function &getInstance
60
    *  @param null
61
    */
62
    /**
63
     * @return TDMCreateXoopsCode
64
     */
65
    public static function &getInstance()
66
    {
67
        static $instance = false;
68
        if (!$instance) {
69
            $instance = new self();
70
        }
71
72
        return $instance;
73
    }
74
75
    /*
76
     *  @public function getXoopsCodeSwitch
77
     *  @param $op
78
     *  @param $cases
79
     *  @param $defaultAfterCase
80
     *  @param $default
81
     *  @param $t - Indentation 
82
     *
83
     * @return string
84
     */
85
    public function getXoopsCodeSwitch($op = '', $cases = array(), $defaultAfterCase = false, $default = false, $t = '')
86
    {
87
        $contentSwitch = $this->phpcode->getPhpCodeCaseSwitch($cases, $defaultAfterCase, $default, $t);
88
89
        return $this->phpcode->getPhpCodeSwitch($op, $contentSwitch, $t);
90
    }
91
92
    /*
93
    *  @public function getXoopsCodeEqualsOperator
94
    *  @param $var
95
    *  @param $value
96
    *  @param $interlock
97
    *  @param $ref
98
    *  @param $t - Indentation 
99
    *
100
    *  @return string
101
    */
102
    public function getXoopsCodeEqualsOperator($var, $value, $interlock = null, $ref = false, $t = '')
103
    {
104
        if (false === $ref) {
105
            $ret = "{$t}{$var} {$interlock}= {$value};\n";
106
        } else {
107
            $ret = "{$t}{$var} =& {$value};\n";
108
        }
109
110
        return $ret;
111
    }
112
113
    /*
114
    *  @public function getXoopsCodeCPHeader
115
    *  @param null
116
    *  @return string
117
    */
118
    public function getXoopsCodeCPHeader()
119
    {
120
        return "xoops_cp_header();\n";
121
    }
122
123
    /*
124
    *  @public function getXoopsCodeCPFooter
125
    *  @param null
126
    *  @return string
127
    */
128
    public function getXoopsCodeCPFooter()
129
    {
130
        return "xoops_cp_footer();\n";
131
    }
132
133
    /**
134
     *  @public function getXoopsCodeLoad
135
     *
136
     *  @param $var
137
     *
138
     *  @return string
139
     */
140
    public function getXoopsCodeLoad($var = '', $t = '')
141
    {
142
        return "{$t}xoops_load('{$var}');\n";
143
    }
144
145
    /**
146
     *  @public function getXoopsCodeLoadLanguage
147
     *
148
     *  @param $lang
149
     *
150
     *  @return string
151
     */
152
    public function getXoopsCodeLoadLanguage($lang, $t = '')
153
    {
154
        return "{$t}xoops_loadLanguage('{$lang}');\n";
155
    }
156
157
    /*
158
    *  @public function getXoopsCodeAnchorFunction
159
    *  @param $anchor
160
    *  @param $name
161
    *  @param $vars
162
    *
163
    *  @return string
164
    */
165
    public function getXoopsCodeAnchorFunction($anchor, $name, $vars)
166
    {
167
        return "\${$anchor}->{$name}({$vars})";
168
    }
169
170
    /*
171
    *  @public function getXoopsCodeSetVar
172
    *  @param $tableName
173
    *  @param $fieldName
174
    *  @param $var
175
    *  @return string
176
    */
177
    public function getXoopsCodeSetVar($tableName, $fieldName, $var, $t = '')
178
    {
179
        return "{$t}\${$tableName}Obj->setVar('{$fieldName}', {$var});\n";
180
    }
181
182
    /*
183
    *  @public function getXoopsCodeGetVar
184
    *  @param $varLeft
185
    *  @param $handle
186
    *  @param $var
187
    *  @param $isParam
188
    *
189
    *  @return string
190
    */
191
    public function getXoopsCodeGetVar($varLeft = '', $handle = '', $var = '', $isParam = false, $t = '')
192
    {
193
        if (!$isParam) {
194
            $ret = "{$t}\${$varLeft} = \${$handle}->getVar('{$var}');\n";
195
        } else {
196
            $ret = "\${$handle}->getVar('{$var}')";
197
        }
198
199
        return $ret;
200
    }
201
202
    /*
203
    *  @public function getXoopsCodeGroupPermForm
204
    *  @param $varLeft
205
    *  @param $formTitle
206
    *  @param $moduleId
207
    *  @param $permName
208
    *  @param $permDesc
209
    *  @param $filename
210
    *
211
    *  @return string
212
    */
213
    public function getXoopsCodeGroupPermForm($varLeft = '', $formTitle = '', $moduleId = '', $permName = '', $permDesc = '', $filename = '', $t = '')
214
    {
215
        return "{$t}\${$varLeft} = new XoopsGroupPermForm({$formTitle}, {$moduleId}, {$permName}, {$permDesc}, {$filename});\n";
216
    }
217
218
    /*
219
    *  @public function getXoopsCodeAddItem
220
    *  @param $varLeft
221
    *  @param $paramLeft
222
    *  @param $paramRight
223
    *
224
    *  @return string
225
    */
226
    public function getXoopsCodeAddItem($varLeft = '', $paramLeft = '', $paramRight = '', $t = '')
227
    {
228
        return "{$t}\${$varLeft}->addItem({$paramLeft}, {$paramRight});\n";
229
    }
230
231
    /*
232
    *  @public function getXoopsCodeGetGroupIds
233
    *  @param $var
234
    *  @param $param1
235
    *  @param $param2
236
    *  @param $param3
237
    *
238
    *  @return string
239
    */
240
    public function getXoopsCodeGetGroupIds($var = '', $anchor = '', $param1 = null, $param2 = null, $param3 = null, $t = '')
0 ignored issues
show
Unused Code introduced by
The parameter $param3 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...
241
    {
242
        return "{$t}\${$var} = \${$anchor}->getGroupIds({$param1}, {$param2}, {$param2});\n";
243
    }
244
	
245
	/*
246
    *  @public function getXoopsCodeGetItemIds
247
    *  @param $var
248
    *  @param $param1
249
    *  @param $param2
250
    *  @param $param3
251
    *
252
    *  @return string
253
    */
254
    public function getXoopsCodeGetItemIds($var = '', $anchor = '', $param1 = null, $param2 = null, $param3 = null, $t = '')
0 ignored issues
show
Unused Code introduced by
The parameter $param3 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
    {
256
        return "{$t}\${$var} = \${$anchor}->getItemIds({$param1}, {$param2}, {$param2});\n";
257
    }
258
259
    /*
260
    *  @public function getXoopsCodeTextDateSelectSetVar
261
    *  @param $tableName
262
    *  @param $fieldName
263
    *  @return string
264
    */
265
    public function getXoopsCodeTextDateSelectSetVar($tableName, $fieldName)
266
    {
267
        return $this->getXoopsCodeSetVar($tableName, $fieldName, "strtotime(\$_POST['{$fieldName}'])");
268
    }
269
270
    /*
271
    *  @public function getXoopsCodeCheckBoxOrRadioYNSetVar
272
    *  @param $tableName
273
    *  @param $fieldName
274
    *  @return string
275
    */
276
    public function getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName)
277
    {
278
        return $this->getXoopsCodeSetVar($tableName, $fieldName, "((1 == \$_REQUEST['{$fieldName}']) ? '1' : '0')");
279
    }
280
281
    /*
282
    *  @public function getXoopsCodeXoopsMediaUploader
283
    *  @param $var
284
    *  @param $dirPath
285
    *  @param $tableName
286
    *  @param $moduleDirname
287
    *  @return string
288
    */
289
    public function getXoopsCodeXoopsMediaUploader($var = '', $dirPath, $tableName, $moduleDirname, $t = '')
290
    {
291
        $mimetypes = $this->getXoopsCodeGetConfig($moduleDirname, 'mimetypes');
292
        $maxsize = $this->getXoopsCodeGetConfig($moduleDirname, 'maxsize');
293
294
        return "{$t}\${$var} = new XoopsMediaUploader({$dirPath} . '/{$tableName}', {$mimetypes}, {$maxsize}, null, null);\n";
295
    }
296
297
    /*
298
    *  @public function getXoopsCodeXoopsCaptcha
299
    *  @param $var
300
    *  @param $instance
301
    *
302
    *  @return string
303
    */
304
    public function getXoopsCodeGetInstance($var = '', $instance = '', $t = '')
305
    {
306
        return "{$t}\${$var} = {$instance}::getInstance();\n";
307
    }
308
309
    /*
310
    *  @public function getXoopsCodeXoopsCaptcha
311
    *  @param null
312
    *  @return string
313
    */
314
    public function getXoopsCodeXoopsCaptcha($t = '')
315
    {
316
        return "{$t}\$xoopsCaptcha = XoopsCaptcha::getInstance();\n";
317
    }
318
319
    /*
320
    *  @public function getXoopsCodeGetConfig
321
    *  @param $moduleDirname
322
    *  @param $name
323
    *  @return string
324
    */
325
    public function getXoopsCodeGetConfig($moduleDirname, $name, $t = '')
0 ignored issues
show
Unused Code introduced by
The parameter $t 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...
326
    {
327
        return "\${$moduleDirname}->getConfig('{$name}')";
328
    }
329
330
    /*
331
    *  @public function getXoopsCodeIdGetVar
332
    *  @param $lpFieldName
333
    *  @return string
334
    */
335
    public function getXoopsCodeIdGetVar($lpFieldName, $t = '')
336
    {
337
        return "{$t}\${$lpFieldName}['id'] = \$i;\n";
338
    }
339
340
    /*
341
    *  @public function getXoopsCodeGetVarAll
342
    *  @param $lpFieldName
343
    *  @param $rpFieldName
344
    *  @param $tableName
345
    *  @param $fieldName
346
    *  @return string
347
    */
348
    public function getXoopsCodeGetVarAll($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '')
349
    {
350
        return "{$t}\${$lpFieldName}['{$rpFieldName}'] = \${$tableName}All[\$i]->getVar('{$fieldName}');\n";
351
    }
352
353
    /*
354
    *  @public function getXoopsHandlerInstance
355
    *  @param $moduleDirname
356
    *  
357
    *  @return string
358
    */
359
    public function getXoopsHandlerInstance($moduleDirname, $t = '')
360
    {
361
        $ucfModuleDirname = ucfirst($moduleDirname);
362
        $ret = "{$t}// Get instance of module\n";
363
        $ret .= "{$t}\${$moduleDirname} = {$ucfModuleDirname}Helper::getInstance();\n";
364
365
        return $ret;
366
    }
367
368
    /*
369
    *  @public function getXoopsHandlerLine
370
    *  @param $moduleDirname
371
    *  @param $tableName
372
    *  @return string
373
    */
374
    public function getXoopsHandlerLine($moduleDirname, $tableName, $t = '')
375
    {
376
        return "{$t}\${$tableName}Handler =& \${$moduleDirname}->getHandler('{$tableName}');\n";
377
    }
378
379
    /*
380
    *  @public function getXoopsFormSelect
381
    *  @param $varSelect
382
    *  @param $caption
383
    *  @param $var
384
    *  @param $options
385
    *  @param $setExtra
386
    *  
387
    *  @return string
388
    */
389
    public function getXoopsFormSelect($varSelect = '', $caption = '', $var = '', $options = array(), $setExtra = true, $t = '')
390
    {
391
        $ret = "{$t}\${$varSelect} = new XoopsFormSelect({$caption}, '{$var}', \${$var});\n";
392
        if (false !== $setExtra) {
393
            $ret .= "{$t}\${$varSelect}->setExtra('{$setExtra}');\n";
394
        }
395
        foreach ($options as $key => $value) {
396
            $ret .= "{$t}\${$varSelect}->addOption('{$key}', {$value});\n";
397
        }
398
399
        return $ret;
400
    }
401
402
    /*
403
     *  @public function getXoopsCodeUnameFromId
404
     *  @param $left
405
     *  @param $tableName
406
     *
407
     * @return string
408
     */
409
    public function getXoopsCodeUnameFromId($left, $value, $t = '')
410
    {
411
        return "{$t}\${$left} = XoopsUser::getUnameFromId({$value});\n";
412
    }
413
414
    /*
415
    *  @public function getXoopsCodeFormatTimeStamp
416
    *  @param $lpFieldName
417
    *  @param $rpFieldName
418
    *  @param $tableName
419
    *  @param $fieldName
420
    *  @return string
421
    */
422
    public function getXoopsCodeFormatTimeStamp($left, $value, $format = 's', $t = '')
0 ignored issues
show
Unused Code introduced by
The parameter $t 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...
423
    {
424
        return "\${$left} = formatTimeStamp({$value}, '{$format}');\n";
425
    }
426
427
    /*
428
    *  @public function getXoopsCodeTopicGetVar
429
    *  @param $lpFieldName
430
    *  @param $rpFieldName
431
    *  @param $tableName
432
    *  @param $tableNameTopic
433
    *  @param $fieldNameParent
434
    *  @param $fieldNameTopic
435
    *  @return string
436
    */
437
    public function getXoopsCodeTopicGetVar($lpFieldName, $rpFieldName, $tableName, $tableNameTopic, $fieldNameParent, $fieldNameTopic, $t = '')
0 ignored issues
show
Unused Code introduced by
The parameter $t 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...
438
    {
439
        $ret = <<<EOT
440
\t\t\t\t// Get Var {$fieldNameParent}
441
\t\t\t\t\${$rpFieldName} =& \${$tableNameTopic}Handler->get(\${$tableName}All[\$i]->getVar('{$fieldNameParent}'));
442
\t\t\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$rpFieldName}->getVar('{$fieldNameTopic}');\n
443
EOT;
444
445
        return $ret;
446
    }
447
448
    /*
449
    *  @public function getXoopsCodeParentTopicGetVar
450
    *  @param $moduleDirname
451
    *  @param $lpFieldName
452
    *  @param $rpFieldName
453
    *  @param $tableName
454
    *  @param $tableSoleNameTopic
455
    *  @param $tableNameTopic
456
    *  @param $fieldNameParent
457
    *  @return string
458
    */
459
    public function getXoopsCodeParentTopicGetVar($moduleDirname, $lpFieldName, $rpFieldName, $tableName, $tableSoleNameTopic, $tableNameTopic, $fieldNameParent, $t = '')
0 ignored issues
show
Unused Code introduced by
The parameter $t 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...
460
    {
461
        $ret = <<<EOT
462
\t\t\t\tif(!isset(\${$tableNameTopic}Handler)) {
463
\t\t\t\t\t// Get {$tableNameTopic} Handler
464
\t\t\t\t\t\${$tableNameTopic}Handler =& \${$moduleDirname}->getHandler('{$tableNameTopic}');
465
\t\t\t\t}
466
\t\t\t\t// Get Var {$fieldNameParent}
467
\t\t\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$tableNameTopic}Handler->get{$tableSoleNameTopic}FromId(\${$tableName}All[\$i]->getVar('{$fieldNameParent}'));\n
468
EOT;
469
470
        return $ret;
471
    }
472
473
    /*
474
    *  @public function getXoopsCodeUploadImageGetVar
475
    *  @param $lpFieldName
476
    *  @param $rpFieldName
477
    *  @param $tableName
478
    *  @param $fieldName
479
    *  @return string
480
    */
481
    public function getXoopsCodeUploadImageGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
482
    {
483
        $ret = <<<EOT
484
\t\t\t\t// Get Var {$fieldName}
485
\t\t\t\t\${$fieldName} = \${$tableName}All[\$i]->getVar('{$fieldName}');
486
\t\t\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$fieldName} ? \${$fieldName} : 'blank.gif';\n
487
EOT;
488
489
        return $ret;
490
    }
491
    /*
492
    *  @public function getXoopsCodeUrlFileGetVar
493
    *  @param $lpFieldName
494
    *  @param $rpFieldName
495
    *  @param $tableName
496
    *  @param $fieldName
497
    *  @return string
498
    */
499
    public function getXoopsCodeUrlFileGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
500
    {
501
        return $this->getXoopsCodeGetVarAll($lpFieldName, $rpFieldName, $tableName, $fieldName);
502
    }
503
    /*
504
    *  @public function getXoopsCodeTextAreaGetVar
505
    *  @param $lpFieldName
506
    *  @param $rpFieldName
507
    *  @param $tableName
508
    *  @param $fieldName
509
    *  @return string
510
    */
511
    public function getXoopsCodeTextAreaGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '')
512
    {
513
        return "{$t}\${$lpFieldName}['{$rpFieldName}'] = strip_tags(\${$tableName}All[\$i]->getVar('{$fieldName}'));\n";
514
    }
515
516
    /*
517
    *  @public function getXoopsCodeSelectUserGetVar
518
    *  @param $lpFieldName
519
    *  @param $rpFieldName
520
    *  @param $tableName
521
    *  @param $fieldName
522
    * @return string
523
    */
524
    public function getXoopsCodeSelectUserGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '')
525
    {
526
        return "{$t}\${$lpFieldName}['{$rpFieldName}'] = XoopsUser::getUnameFromId(\${$tableName}All[\$i]->getVar('{$fieldName}'), 's');\n";
527
    }
528
529
    /*
530
    *  @public function getXoopsCodeTextDateSelectGetVar
531
    *  @param $lpFieldName
532
    *  @param $rpFieldName
533
    *  @param $tableName
534
    *  @param $fieldName
535
    *  @return string
536
    */
537
    public function getXoopsCodeTextDateSelectGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '')
538
    {
539
        return "{$t}\${$lpFieldName}['{$rpFieldName}'] = formatTimeStamp(\${$tableName}All[\$i]->getVar('{$fieldName}'), 's');\n";
540
    }
541
542
    /*
543
    *  @public function getXoopsCodeUserHeader
544
    *  @param $moduleDirname
545
    *  @param $tableName
546
    *  @return string
547
    */
548
    public function getXoopsCodeXoopsOptionTemplateMain($moduleDirname, $tableName, $t = '')
549
    {
550
        return "{$t}\$GLOBALS['xoopsOption']['template_main'] = '{$moduleDirname}_{$tableName}.tpl';\n";
551
    }
552
553
    /*
554
    *  @public function getXoopsCodeUserHeader
555
    *  @param $moduleDirname
556
    *  @param $tableName
557
    *  @return string
558
    */
559
    public function getXoopsCodeUserHeader($moduleDirname, $tableName)
560
    {
561
        $ret = $this->phpcode->getPhpCodeIncludeDir('__DIR__', 'header');
562
        $ret .= $this->getXoopsCodeXoopsOptionTemplateMain($moduleDirname, $tableName);
563
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'header', true);
564
565
        return $ret;
566
    }
567
568
    /*
569
    *  @public function getXoopsCodePermissionsHeader
570
    *  @param null
571
    */
572
    /**
573
     * @return string
574
     */
575
    public function getXoopsCodePermissionsHeader()
576
    {
577
        $ret = $this->phpcode->getPhpCodeCommentLine('Permission');
578
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/xoopsform/grouppermform', true);
579
        $ret .= $this->getXoopsCodeEqualsOperator('$gpermHandler', "xoops_gethandler('groupperm')", true);
580
        $groups = $this->getXoopsCodeEqualsOperator('$groups', '$xoopsUser->getGroups()');
581
        $elseGroups = $this->getXoopsCodeEqualsOperator('$groups', 'XOOPS_GROUP_ANONYMOUS');
582
        $ret .= $this->phpcode->getPhpCodeConditions('is_object($xoopsUser)', '', $type = '', $groups, $elseGroups);
583
584
        return $ret;
585
    }
586
587
    /**
588
     *  @public function getXoopsCodeGetFieldId
589
     *
590
     *  @param $fields
591
     *
592
     *  @return string
593
     */
594
    public function getXoopsCodeGetFieldId($fields)
595
    {
596
        $fieldId = 'id';
597
        foreach (array_keys($fields) as $f) {
598
            $fieldName = $fields[$f]->getVar('field_name');
599
            if (0 == $f) {
600
                $fieldId = $fieldName;
601
            }
602
        }
603
604
        return $fieldId;
605
    }
606
607
    /**
608
     *  @public function getXoopsCodeGetFieldName
609
     *
610
     *  @param $fields
611
     *
612
     *  @return string
613
     */
614
    public function getXoopsCodeGetFieldName($fields)
615
    {
616
        foreach (array_keys($fields) as $f) {
617
            $fieldName = $fields[$f]->getVar('field_name');
618
        }
619
620
        return $fieldName;
0 ignored issues
show
Bug introduced by
The variable $fieldName 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...
621
    }
622
623
    /**
624
     *  @public function getXoopsCodeGetFieldParentId
625
     *
626
     *  @param $fields
627
     *
628
     *  @return string
629
     */
630
    public function getXoopsCodeGetFieldParentId($fields)
631
    {
632
        $fieldPid = 'pid';
633
        foreach (array_keys($fields) as $f) {
634
            $fieldName = $fields[$f]->getVar('field_name');
635
            if (1 == $fields[$f]->getVar('field_parent')) {
636
                $fieldPid = $fieldName;
637
            }
638
        }
639
640
        return $fieldPid;
641
    }
642
643
    /**
644
     *  @public function getXoopsCodeUserSaveElements
645
     *
646
     *  @param $moduleDirname
647
     *  @param $tableName
648
     *  @param $fields
649
     *
650
     *  @return string
651
     */
652
    public function getXoopsCodeUserSaveElements($moduleDirname, $tableName, $fields)
653
    {
654
        $ret = '';
655
        foreach (array_keys($fields) as $f) {
656
            $fieldName = $fields[$f]->getVar('field_name');
657
            $fieldElement = $fields[$f]->getVar('field_element');
658
            if (1 == $fields[$f]->getVar('field_main')) {
659
                $fieldMain = $fieldName;
660
            }
661
            if ((5 == $fieldElement) || (6 == $fieldElement)) {
662
                $ret .= $this->getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName);
663
            } elseif (13 == $fieldElement) {
664
                $ret .= $this->getXoopsCodeUploadImageSetVar($moduleDirname, $tableName, $fieldName, $fieldMain);
0 ignored issues
show
Bug introduced by
The variable $fieldMain 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 method getXoopsCodeUploadImageSetVar() does not exist on TDMCreateXoopsCode. Did you maybe mean getXoopsCodeUploadImageGetVar()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
665
            } elseif (14 == $fieldElement) {
666
                $ret .= $this->getXoopsCodeUploadFileSetVar($moduleDirname, $tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The method getXoopsCodeUploadFileSetVar() does not seem to exist on object<TDMCreateXoopsCode>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
667
            } elseif (15 == $fieldElement) {
668
                $ret .= $this->getXoopsCodeTextDateSelectSetVar($tableName, $fieldName);
669
            } else {
670
                $ret .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
671
            }
672
        }
673
674
        return $ret;
675
    }
676
677
    /*
678
    *  @public function getXoopsCodeXoopsRequest
679
    *  @param $left
680
    *  @param $var1
681
    *  @param $var2
682
    *  @param $type
683
    *  @param $metod
684
    *  @return string
685
    */
686
    public function getXoopsCodeXoopsRequest($left = '', $var1 = '', $var2 = '', $type = 'String', $metod = false, $t = '')
687
    {
688
        $ret = '';
689
        $intVars = ($var2 != '') ? "'{$var1}', {$var2}" : "'{$var1}'";
690
        if ($type == 'String') {
691
            $ret .= "{$t}\${$left} = XoopsRequest::getString('{$var1}', '{$var2}');\n";
692
        } elseif ($type == 'Int') {
693
            $ret .= "{$t}\${$left} = XoopsRequest::getInt({$intVars});\n";
694
        } elseif ($type == 'Int' && $metod !== false) {
695
            $ret .= "{$t}\${$left} = XoopsRequest::getInt({$intVars}, '{$metod}');\n";
696
        }
697
698
        return $ret;
699
    }
700
701
    /**
702
     *  @public function getXoopsCodeTplAssign     
703
     *
704
     *  @param $tplString
705
     *  @param $phpRender
706
     *  @param $leftIsString 
707
     *
708
     *  @return string
709
     */
710
    public function getXoopsCodeTplAssign($tplString, $phpRender, $leftIsString = true, $t = '')
711
    {
712
        $assign = "{$t}\$GLOBALS['xoopsTpl']->assign(";
713
        if ($leftIsString === false) {
714
            $ret = $assign."{$tplString}, {$phpRender});\n";
715
        } else {
716
            $ret = $assign."'{$tplString}', {$phpRender});\n";
717
        }
718
719
        return $ret;
720
    }
721
722
    /**
723
     *  @public function getXoopsCodeXoopsTplAppend
724
     *
725
     *  @param $tplString
726
     *  @param $phpRender
727
     *
728
     *  @return string
729
     */
730
    public function getXoopsCodeXoopsTplAppend($tplString, $phpRender, $t = '')
731
    {
732
        return "{$t}\$GLOBALS['xoopsTpl']->append('{$tplString}', {$phpRender});\n";
733
    }
734
735
    /**
736
     *  @public function getXoopsCodeXoopsTplAppendByRef
737
     *
738
     *  @param $tplString
739
     *  @param $phpRender
740
     *
741
     *  @return string
742
     */
743
    public function getXoopsCodeXoopsTplAppendByRef($tplString, $phpRender, $t = '')
744
    {
745
        return "{$t}\$GLOBALS['xoopsTpl']->appendByRef('{$tplString}', {$phpRender});\n";
746
    }
747
748
    /**
749
     *  @public function getXoopsCodePath
750
     *
751
     *  @param $directory
752
     *  @param $filename
753
     *  @param $isParam
754
     *
755
     *  @return string
756
     */
757
    public function getXoopsCodePath($directory, $filename, $isParam = false, $t = '')
758
    {
759
        if (!$isParam) {
760
            $ret = "{$t}\$GLOBALS['xoops']->path({$directory}.'/{$filename}.php');\n";
761
        } else {
762
            $ret = "\$GLOBALS['xoops']->path({$directory}.'/{$filename}.php')";
763
        }
764
765
        return $ret;
766
    }
767
768
    /**
769
     *  @public function getXoopsCodeTplDisplay
770
     *
771
     *  @param $displayTpl
772
     *
773
     *  @return string
774
     */
775
    public function getXoopsCodeTplDisplay($displayTpl = '{$templateMain}', $t = '')
776
    {
777
        return "{$t}\$GLOBALS['xoopsTpl']->display(\"db:{$displayTpl}\");\n";
778
    }
779
780
    /**
781
     *  @public function getXoopsCodeGetInfo
782
     *
783
     *  @param $left
784
     *  @param $string
785
     *  @param $isParam
786
     *
787
     *  @return string
788
     */
789
    public function getXoopsCodeGetInfo($left = '', $string, $isParam = false, $t = '')
790
    {
791
        if (!$isParam) {
792
            $ret = "{$t}\${$left} = \$GLOBALS['xoopsModule']->getInfo('{$string}');\n";
793
        } else {
794
            $ret = "\$GLOBALS['xoopsModule']->getInfo('{$string}')";
795
        }
796
797
        return $ret;
798
    }
799
800
    /**
801
     *  @public function getXoopsCodeAddRight
802
     *
803
     *  @param $anchor
804
     *  @param $permString
805
     *  @param $var
806
     *  @param $groups
807
     *  @param $mid
808
     *  @param $isParam
809
     *
810
     *  @return string
811
     */
812
    public function getXoopsCodeAddRight($anchor, $permString = '', $var = '', $groups = '', $mid = '', $isParam = false, $t = '')
813
    {
814
        if (!$isParam) {
815
            $ret = "{$t}\${$anchor}->addRight('{$permString}', {$var}, {$groups}, {$mid});\n";
816
        } else {
817
            $ret = "\${$anchor}->addRight('{$permString}', {$var}, {$groups}, {$mid})";
818
        }
819
820
        return $ret;
821
    }
822
823
    /**
824
     *  @public function getXoopsCodeCheckRight
825
     *
826
     *  @param $anchor
827
     *  @param $permString
828
     *  @param $var
829
     *  @param $groups
830
     *  @param $mid
831
     *  @param $isParam
832
     *
833
     *  @return string
834
     */
835
    public function getXoopsCodeCheckRight($anchor, $permString = '', $var = '', $groups = '', $mid = '', $isParam = false, $t = '')
836
    {
837
        if (!$isParam) {
838
            $ret = "{$t}{$anchor}->checkRight('{$permString}', {$var}, {$groups}, {$mid});\n";
839
        } else {
840
            $ret = "{$anchor}->checkRight('{$permString}', {$var}, {$groups}, {$mid})";
841
        }
842
843
        return $ret;
844
    }
845
846
    /**
847
     *  @public function getXoopsCodeObjHandlerCreate
848
     *
849
     *  @param $tableName
850
     *
851
     *  @return string
852
     */
853
    public function getXoopsCodeObjHandlerCreate($tableName, $t = '')
854
    {
855
        return "{$t}\${$tableName}Obj =& \${$tableName}Handler->create();\n";
856
    }
857
858
    /**
859
     *  @public function getXoopsCodeObjHandlerCount
860
     *
861
     *  @param $tableName
862
     *
863
     *  @return string
864
     */
865
    public function getXoopsCodeObjHandlerCount($tableName, $t = '')
866
    {
867
        $ucfTableName = ucfirst($tableName);
868
        $ret = "{$t}\${$tableName}Count = \${$tableName}Handler->getCount{$ucfTableName}();\n";
869
870
        return $ret;
871
    }
872
873
    /**
874
     *  @public function getXoopsCodeObjHandlerAll
875
     *
876
     *  @param $tableName
877
     *  @param $fieldMain
878
     *  @param $start
879
     *  @param $limit
880
     *
881
     *  @return string
882
     */
883
    public function getXoopsCodeObjHandlerAll($tableName, $fieldMain = '', $start = '0', $limit = '0', $t = '')
884
    {
885
        $ucfTableName = ucfirst($tableName);
886
        $startLimit = ($limit != '0') ? "{$start}, {$limit}" : '0';
887
        $params = ($fieldMain != '') ? "{$startLimit}, '{$fieldMain}'" : $startLimit;
888
        $ret = "{$t}\${$tableName}All = \${$tableName}Handler->getAll{$ucfTableName}({$params});\n";
889
890
        return $ret;
891
    }
892
893
    /**
894
     *  @public function getXoopsCodeGetValues
895
     *
896
     *  @param $tableName
897
     *  @param $tableSoleName
898
     *
899
     *  @return string
900
     */
901
    public function getXoopsCodeGetValues($tableName, $tableSoleName, $index = 'i', $noArray = false, $t = '')
902
    {
903
        $ucfTableName = ucfirst($tableName);
904
        if (!$noArray) {
905
            $ret = "{$t}\${$tableSoleName} = \${$tableName}All[\${$index}]->getValues{$ucfTableName}();\n";
906
        } else {
907
            $ret = "{$t}\${$tableSoleName} = \${$tableName}->getValues{$ucfTableName}();\n";
908
        }
909
910
        return $ret;
911
    }
912
913
    /**
914
     *  @public function getXoopsCodeObjectTree
915
     *
916
     *  @param $var
917
     *  @param $tableName
918
     *  @param $fieldId
919
     *  @param $fieldParent
920
     *
921
     *  @return string
922
     */
923
    public function getXoopsCodeObjectTree($var = 'mytree', $tableName, $fieldId, $fieldParent, $t = '')
924
    {
925
        $ret = "{$t}\${$var} = new XoopsObjectTree(\${$tableName}All, '{$fieldId}', '{$fieldParent}');\n";
926
927
        return $ret;
928
    }
929
930
    /**
931
     *  @public function getXoopsCodeSetVarsObjects
932
     *
933
     *  @param $moduleDirname
934
     *  @param $tableName
935
     *  @param $fields
936
     *
937
     *  @return string
938
     */
939
    public function getXoopsCodeSetVarsObjects($moduleDirname, $tableName, $fields, $t = '')
0 ignored issues
show
Unused Code introduced by
The parameter $t 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...
940
    {
941
        $ret = '';
942
        foreach (array_keys($fields) as $f) {
943
            $fieldName = $fields[$f]->getVar('field_name');
944
            $fieldElement = $fields[$f]->getVar('field_element');
945
            if (1 == $fields[$f]->getVar('field_main')) {
946
                $fieldMain = $fieldName;
947
            }
948
            if ($f > 0) { // If we want to hide field id
949
                switch ($fieldElement) {
950
                    case 5:
951
                    case 6:
952
                        $ret .= $this->getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName);
953
                        break;
954
                    case 11:
955
                        $ret .= $this->getXoopsCodeImageListSetVar($moduleDirname, $tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The method getXoopsCodeImageListSetVar() does not seem to exist on object<TDMCreateXoopsCode>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
956
                        break;
957
                    case 12:
958
                        $ret .= $this->getXoopsCodeFileSetVar($moduleDirname, $tableName, $fieldName, true);
0 ignored issues
show
Bug introduced by
The method getXoopsCodeFileSetVar() does not exist on TDMCreateXoopsCode. Did you maybe mean getXoopsCodeSetVar()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
959
                        break;
960
                    case 13:
961
                        $ret .= $this->getXoopsCodeUploadImageSetVar($moduleDirname, $tableName, $fieldName, $fieldMain);
0 ignored issues
show
Bug introduced by
The variable $fieldMain 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 method getXoopsCodeUploadImageSetVar() does not exist on TDMCreateXoopsCode. Did you maybe mean getXoopsCodeUploadImageGetVar()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
962
                        break;
963
                    case 14:
964
                        $ret .= $this->getXoopsCodeFileSetVar($moduleDirname, $tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The method getXoopsCodeFileSetVar() does not exist on TDMCreateXoopsCode. Did you maybe mean getXoopsCodeSetVar()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
965
                        break;
966
                    case 15:
967
                        $ret .= $this->getXoopsCodeTextDateSelectSetVar($tableName, $fieldName);
968
                        break;
969
                    default:
970
                        $ret .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
971
                        break;
972
                }
973
            }
974
        }
975
976
        return $ret;
977
    }
978
979
    /**
980
     *  @public function getXoopsCodeSecurity
981
     *
982
     *  @param $tableName
983
     *
984
     *  @return string
985
     */
986
    public function getXoopsCodeSecurity($tableName, $t = '')
987
    {
988
        $securityError = $this->getXoopsCodeSecurityGetError();
0 ignored issues
show
Bug introduced by
The method getXoopsCodeSecurityGetError() does not exist on TDMCreateXoopsCode. Did you maybe mean getXoopsCodeSecurity()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
989
        $implode = $this->phpcode->getPhpCodeImplode(',', $securityError);
990
        $content = "{$t}\t".$this->getXoopsCodeRedirectHeader($tableName.'.php', '', 3, $implode, $t);
0 ignored issues
show
Documentation introduced by
$t is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
991
        $securityCheck = $this->getXoopsCodeSecurityCheck();
992
993
        return $this->phpcode->getPhpCodeConditions('!'.$securityCheck, '', '', $content, $t);
994
    }
995
996
    /*
997
    *  @public function getXoopsCodeInsertData
998
    *  @param $tableName
999
    *  @param $language
1000
    *  @return string
1001
    */
1002
    public function getXoopsCodeInsertData($tableName, $language, $t = '')
1003
    {
1004
        $content = "{$t}\t".$this->getXoopsCodeRedirectHeader($tableName.'.php', '?op=list', 2, "{$language}FORM_OK");
1005
        $handlerInsert = $this->getXoopsCodeHandler($tableName, $tableName, false, true, false, 'Obj');
1006
1007
        return $this->phpcode->getPhpCodeConditions($handlerInsert, '', '', $content, $t);
1008
    }
1009
1010
    /*
1011
    *  @public function getXoopsCodeRedirectHeader
1012
    *  @param $tableName
1013
    *  @param $options
1014
    *  @param $numb
1015
    *  @param $var
1016
    *  @param $isString
1017
    *
1018
    *  @return string
1019
    */
1020
    public function getXoopsCodeRedirectHeader($tableName, $options = '', $numb = '2', $var, $isString = true, $t = '')
1021
    {
1022
        if (!$isString) {
1023
            $ret = "{$t}redirect_header({$tableName}, {$numb}, {$var});\n";
1024
        } else {
1025
            $ret = "{$t}redirect_header('{$tableName}{$options}', {$numb}, {$var});\n";
1026
        }
1027
1028
        return $ret;
1029
    }
1030
1031
    /*
1032
    *  @public function getXoopsCodeXoopsConfirm
1033
    *  @param $tableName
1034
    *  @param $language
1035
    *  @param $fieldId
1036
    *  @param $fieldMain    
1037
    *  @param $options
1038
    *
1039
    *  @return string
1040
    */
1041
    public function getXoopsCodeXoopsConfirm($tableName, $language, $fieldId, $fieldMain, $options = 'delete', $t = '')
1042
    {
1043
        $stuOptions = strtoupper($options);
1044
        $ccFieldId = $this->tdmcfile->getCamelCase($fieldId, false, true);
1045
        $array = "array('ok' => 1, '{$fieldId}' => \${$ccFieldId}, 'op' => '{$options}')";
1046
        $ret = "{$t}xoops_confirm({$array}, \$_SERVER['REQUEST_URI'], sprintf({$language}FORM_SURE_{$stuOptions}, \${$tableName}Obj->getVar('{$fieldMain}')));\n";
1047
1048
        return $ret;
1049
    }
1050
1051
    /*
1052
    *  @public function getXoopsCodeAddStylesheet
1053
    *  @param $style
1054
    *  
1055
    *  @return string
1056
    */
1057
    public function getXoopsCodeAddStylesheet($style = 'style', $t = '')
1058
    {
1059
        return "{$t}\$GLOBALS['xoTheme']->addStylesheet( \${$style}, null );\n";
1060
    }
1061
1062
    /*
1063
    *  @public function getXoopsCodeSecurityCheck
1064
    *  @param $denial
1065
    *  @return boolean
1066
    */
1067
    public function getXoopsCodeSecurityCheck($denial = '')
1068
    {
1069
        return "{$denial}\$GLOBALS['xoopsSecurity']->check()";
1070
    }
1071
1072
    /*
1073
    *  @public function getXoopsCodeSecurityErrors
1074
    *  @param null
1075
    *  @return string
1076
    */
1077
    public function getXoopsCodeSecurityErrors()
1078
    {
1079
        return "\$GLOBALS['xoopsSecurity']->getErrors()";
1080
    }
1081
1082
    /**
1083
     *  @public function getXoopsCodeHtmlErrors
1084
     *
1085
     *  @param $tableName
1086
     *  @param $isParam
1087
     *  @param $obj
1088
     *
1089
     *  @return string
1090
     */
1091
    public function getXoopsCodeHtmlErrors($tableName, $isParam = false, $obj = 'Obj', $t = '')
1092
    {
1093
        $ret = '';
0 ignored issues
show
Unused Code introduced by
$ret 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...
1094
        if ($isParam) {
1095
            $ret = "\${$tableName}{$obj}->getHtmlErrors()";
1096
        } else {
1097
            $ret = "{$t}\${$tableName}{$obj} =& \${$tableName}->getHtmlErrors();";
1098
        }
1099
1100
        return $ret;
1101
    }
1102
1103
    /**
1104
     *  @public function getXoopsCodeObjHandlerCount
1105
     *
1106
     *  @param $left
1107
     *  @param $tableName
1108
     *  @param $obj
1109
     *
1110
     *  @return string
1111
     */
1112
    public function getXoopsCodeGetForm($left, $tableName, $obj = '', $t = '')
1113
    {
1114
        $ucfTableName = ucfirst($tableName);
1115
1116
        return "{$t}\${$left} =& \${$tableName}{$obj}->getForm{$ucfTableName}();\n";
1117
    }
1118
1119
    /**
1120
     *  @public function getXoopsCodeGet
1121
     *
1122
     *  @param $tableName
1123
     *  @param $var
1124
     *  @param $obj
1125
     *  @param $isHandler
1126
     *  @param $isParam
1127
     *
1128
     *  @return string
1129
     */
1130
    public function getXoopsCodeGet($tableName, $var, $obj = '', $isHandler = false, $isParam = false, $t = '')
1131
    {
1132
        $handler = $isHandler === false ? '' : 'Handler';
1133
        if ($isParam) {
1134
            $ret = "\${$tableName}{$handler}->get(\${$var})";
1135
        } else {
1136
            $ret = "{$t}\${$tableName}{$obj} =& \${$tableName}{$handler}->get(\${$var});\n";
1137
        }
1138
1139
        return $ret;
1140
    }
1141
1142
    /**
1143
     *  @public function getXoopsCodeHandler
1144
     *
1145
     *  @param $tableName
1146
     *  @param $var
1147
     *  @param $obj
1148
     *  @param $isHandler
1149
     *
1150
     *  @return string
1151
     */
1152
    public function getXoopsCodeInsert($tableName, $var, $obj = '', $isHandler = false)
1153
    {
1154
        $handler = ($isHandler === false) ? '' : 'Handler';
1155
        if ($obj != '') {
1156
            $ret = "\${$tableName}{$handler}->insert(\${$var}{$obj})";
1157
        } else {
1158
            $ret = "\${$tableName}{$handler}->insert(\${$var})";
1159
        }
1160
1161
        return $ret;
1162
    }
1163
1164
    /**
1165
     *  @public function getXoopsCodeDelete
1166
     *
1167
     *  @param $tableName
1168
     *  @param $var
1169
     *  @param $obj
1170
     *  @param $isHandler
1171
     *
1172
     *  @return string
1173
     */
1174
    public function getXoopsCodeDelete($tableName, $var, $obj = '', $isHandler = false)
1175
    {
1176
        $handler = $isHandler === false ? '' : 'Handler';
1177
        if ($obj != '') {
1178
            $ret = "\${$tableName}{$handler}->delete(\${$var}{$obj})";
1179
        } else {
1180
            $ret = "\${$tableName}{$handler}->delete(\${$var})";
1181
        }
1182
1183
        return $ret;
1184
    }
1185
1186
    /**
1187
     *  @public function getXoopsCodeHandler
1188
     *
1189
     *  @param $tableName
1190
     *  @param $var
1191
     *
1192
     *  @return string
1193
     */
1194
    public function getXoopsCodeHandler($tableName, $var, $get = false, $insert = false, $delete = false, $obj = '', $t = '')
1195
    {
1196
        if ($get) {
1197
            $ret = "{$t}\${$tableName}Handler->get(\${$var});";
1198
        } elseif ($insert && ($obj != '')) {
1199
            $ret = "{$t}\${$tableName}Handler->insert(\${$var}{$obj});";
1200
        } elseif ($delete && ($obj != '')) {
1201
            $ret = "{$t}\${$tableName}Handler->delete(\${$var}{$obj});";
1202
        }
1203
1204
        return $ret;
0 ignored issues
show
Bug introduced by
The variable $ret 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...
1205
    }
1206
    
1207
    /*
1208
    *  @public function getTopicGetVar
1209
    *  @param $lpFieldName
1210
    *  @param $rpFieldName
1211
    *  @param $tableName
1212
    *  @param $tableNameTopic
1213
    *  @param $fieldNameParent
1214
    *  @param $fieldNameTopic
1215
    *  @return string
1216
    */
1217
    public function getTopicGetVar($lpFieldName, $rpFieldName, $tableName, $tableNameTopic, $fieldNameParent, $fieldNameTopic, $t = '')
0 ignored issues
show
Unused Code introduced by
The parameter $t 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...
1218
    {
1219
        $ret = <<<EOT
1220
\t\t// Get Var {$fieldNameParent}
1221
\t\t\${$rpFieldName} =& \${$tableNameTopic}Handler->get(\${$tableName}All[\$i]->getVar('{$fieldNameParent}'));
1222
\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$rpFieldName}->getVar('{$fieldNameTopic}');\n
1223
EOT;
1224
1225
        return $ret;
1226
    }
1227
1228
    /*
1229
    *  @public function getUploadImageGetVar
1230
    *  @param $lpFieldName
1231
    *  @param $rpFieldName
1232
    *  @param $tableName
1233
    *  @param $fieldName
1234
    *  @return string
1235
    */
1236
    public function getUploadImageGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '')
0 ignored issues
show
Unused Code introduced by
The parameter $t 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...
1237
    {
1238
        $ret = <<<EOT
1239
\t\t// Get Var {$fieldName}
1240
\t\t\${$fieldName} = \${$tableName}All[\$i]->getVar('{$fieldName}');
1241
\t\t\$upload_image = \${$fieldName} ? \${$fieldName} : 'blank.gif';
1242
\t\t\${$lpFieldName}['{$rpFieldName}'] = \$upload_image;\n
1243
EOT;
1244
1245
        return $ret;
1246
    }
1247
    
1248
    /**
1249
     *  @public function getXoopsCodeSaveFieldId
1250
     *
1251
     *  @param $fields
1252
     *
1253
     *  @return string
1254
     */
1255
    public function getXoopsCodeSaveFieldId($fields)
1256
    {
1257
        foreach (array_keys($fields) as $f) {
1258
            if (0 == $f) {
1259
                $fieldId = $fields[$f]->getVar('field_name');
1260
            }
1261
        }
1262
1263
        return $fieldId;
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...
1264
    }
1265
1266
    /**
1267
     *  @public function getXoopsCodeSaveFieldMain
1268
     *
1269
     *  @param $fields
1270
     *
1271
     *  @return string
1272
     */
1273
    public function getXoopsCodeSaveFieldMain($fields)
1274
    {
1275
        foreach (array_keys($fields) as $f) {
1276
            if (1 == $fields[$f]->getVar('field_main')) {
1277
                $fieldMain = $fields[$f]->getVar('field_name');
1278
            }
1279
        }
1280
1281
        return $fieldMain;
0 ignored issues
show
Bug introduced by
The variable $fieldMain 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...
1282
    }
1283
1284
    /**
1285
     *  @public function getXoopsCodeSaveElements
1286
     *
1287
     *  @param $moduleDirname
1288
     *  @param $tableName
1289
     *  @param $fields
1290
     *
1291
     *  @return string
1292
     */
1293
    public function getXoopsCodeSaveElements($moduleDirname, $tableName, $fields)
1294
    {
1295
        $ret = '';
1296
        foreach (array_keys($fields) as $f) {
1297
            $fieldName = $fields[$f]->getVar('field_name');
1298
            $fieldElement = $fields[$f]->getVar('field_element');
1299
            if (1 == $fields[$f]->getVar('field_main')) {
1300
                $fieldMain = $fieldName;
1301
            }
1302
            if ((5 == $fieldElement) || (6 == $fieldElement)) {
1303
                $ret .= $this->getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName);
1304
            } elseif (13 == $fieldElement) {
1305
                $ret .= $this->getXoopsCodeUploadImageSetVar($moduleDirname, $tableName, $fieldName, $fieldMain);
0 ignored issues
show
Bug introduced by
The variable $fieldMain 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 method getXoopsCodeUploadImageSetVar() does not exist on TDMCreateXoopsCode. Did you maybe mean getXoopsCodeUploadImageGetVar()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1306
            } elseif (14 == $fieldElement) {
1307
                $ret .= $this->getXoopsCodeUploadFileSetVar($moduleDirname, $tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The method getXoopsCodeUploadFileSetVar() does not seem to exist on object<TDMCreateXoopsCode>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1308
            } elseif (15 == $fieldElement) {
1309
                $ret .= $this->getXoopsCodeTextDateSelectSetVar($tableName, $fieldName);
1310
            } else {
1311
                $ret .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
1312
            }
1313
        }
1314
1315
        return $ret;
1316
    }
1317
1318
    /*
1319
    *  @public function getXoopsCodePageNav
1320
    *  @param $tableName
1321
    *
1322
    *  @return string
1323
    */
1324
    public function getXoopsCodePageNav($tableName, $t = '')
1325
    {
1326
        $condition = "{$t}\t".$this->phpcode->getPhpCodeCommentLine('Display Navigation');
1327
        $condition .= "{$t}\t".$this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/pagenav', true);
1328
        $condition .= "{$t}\t\$pagenav = new XoopsPageNav(\${$tableName}Count, \$limit, \$start, 'start', 'op=list&limit=' . \$limit);\n";
1329
        $condition .= "{$t}\t".$this->getXoopsCodeTplAssign('pagenav', '$pagenav->renderNav(4)');
1330
        $ret = $this->phpcode->getPhpCodeConditions("\${$tableName}Count", ' > ', '$limit', $condition, false, $t);
1331
1332
        return $ret;
1333
    }
1334
}
1335