Completed
Pull Request — master (#91)
by Gino
03:29
created

TDMCreateXoopsCode::getXoopsCodeSaveFieldMain()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 3
eloc 5
nc 3
nop 1
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 $tf = null;
34
35
    /*
36
    * @var mixed
37
    */
38
    private $pc = 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->tf = TDMCreateFile::getInstance();
55
        $this->pc = 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->pc->getPhpCodeCaseSwitch($cases, $defaultAfterCase, $default, $t);
88
89
        return $this->pc->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
    *  @param $close
163
    *
164
    *  @return string
165
    */
166
    public function getXoopsCodeAnchorFunction($anchor, $name, $vars, $close = false)
167
    {
168
        $semicolon = $close !== false ? ';' : '';
169
170
        return "\${$anchor}->{$name}({$vars}){$semicolon}";
171
    }
172
173
    /*
174
    *  @public function getXoopsCodeSetVar
175
    *  @param $tableName
176
    *  @param $fieldName
177
    *  @param $var
178
    *  @return string
179
    */
180
    public function getXoopsCodeSetVar($tableName, $fieldName, $var, $t = '')
181
    {
182
        return "{$t}\${$tableName}Obj->setVar('{$fieldName}', {$var});\n";
183
    }
184
185
    /*
186
    *  @public function getXoopsCodeGetVar
187
    *  @param $varLeft
188
    *  @param $handle
189
    *  @param $var
190
    *  @param $isParam
191
    *
192
    *  @return string
193
    */
194
    public function getXoopsCodeGetVar($varLeft = '', $handle = '', $var = '', $isParam = false, $t = '')
195
    {
196
        if (!$isParam) {
197
            $ret = "{$t}\${$varLeft} = \${$handle}->getVar('{$var}');\n";
198
        } else {
199
            $ret = "\${$handle}->getVar('{$var}')";
200
        }
201
202
        return $ret;
203
    }
204
205
    /*
206
    *  @public function getXoopsCodeGroupPermForm
207
    *  @param $varLeft
208
    *  @param $formTitle
209
    *  @param $moduleId
210
    *  @param $permName
211
    *  @param $permDesc
212
    *  @param $filename
213
    *
214
    *  @return string
215
    */
216
    public function getXoopsCodeGroupPermForm($varLeft = '', $formTitle = '', $moduleId = '', $permName = '', $permDesc = '', $filename = '', $t = '')
217
    {
218
        return "{$t}\${$varLeft} = new XoopsGroupPermForm({$formTitle}, {$moduleId}, {$permName}, {$permDesc}, {$filename});\n";
219
    }
220
221
    /*
222
    *  @public function getXoopsCodeAddItem
223
    *  @param $varLeft
224
    *  @param $paramLeft
225
    *  @param $paramRight
226
    *
227
    *  @return string
228
    */
229
    public function getXoopsCodeAddItem($varLeft = '', $paramLeft = '', $paramRight = '', $t = '')
230
    {
231
        return "{$t}\${$varLeft}->addItem({$paramLeft}, {$paramRight});\n";
232
    }
233
234
    /*
235
    *  @public function getXoopsCodeGetGroupIds
236
    *  @param $var
237
    *  @param $param1
238
    *  @param $param2
239
    *  @param $param3
240
    *
241
    *  @return string
242
    */
243
    public function getXoopsCodeGetGroupIds($var = '', $anchor = '', $param1 = null, $param2 = null, $param3 = null, $t = '')
244
    {
245
        return "{$t}\${$var} = \${$anchor}->getGroupIds({$param1}, {$param2}, {$param3});\n";
246
    }
247
248
    /*
249
    *  @public function getXoopsCodeGetItemIds
250
    *  @param $var
251
    *  @param $param1
252
    *  @param $param2
253
    *  @param $param3
254
    *
255
    *  @return string
256
    */
257
    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...
258
    {
259
        return "{$t}\${$var} = \${$anchor}->getItemIds({$param1}, {$param2}, {$param2});\n";
260
    }
261
262
    /*
263
    *  @public function getXoopsCodeTextDateSelectSetVar
264
    *  @param $tableName
265
    *  @param $fieldName
266
    *  @return string
267
    */
268
    public function getXoopsCodeTextDateSelectSetVar($tableName, $fieldName)
269
    {
270
        return $this->getXoopsCodeSetVar($tableName, $fieldName, "strtotime(\$_POST['{$fieldName}'])");
271
    }
272
273
    /*
274
    *  @public function getXoopsCodeCheckBoxOrRadioYNSetVar
275
    *  @param $tableName
276
    *  @param $fieldName
277
    *  @return string
278
    */
279
    public function getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName)
280
    {
281
        return $this->getXoopsCodeSetVar($tableName, $fieldName, "((1 == \$_REQUEST['{$fieldName}']) ? '1' : '0')");
282
    }
283
284
    /*
285
    *  @public function getXoopsCodeXoopsMediaUploader
286
    *  @param $var
287
    *  @param $dirPath
288
    *  @param $tableName
289
    *  @param $moduleDirname
290
    *  @return string
291
    */
292
    public function getXoopsCodeXoopsMediaUploader($var = '', $dirPath, $tableName, $moduleDirname, $t = '')
293
    {
294
        $mimetypes = $this->getXoopsCodeGetConfig($moduleDirname, 'mimetypes');
295
        $maxsize = $this->getXoopsCodeGetConfig($moduleDirname, 'maxsize');
296
297
        return "{$t}\${$var} = new XoopsMediaUploader({$dirPath} . '/{$tableName}', {$mimetypes}, {$maxsize}, null, null);\n";
298
    }
299
300
    /*
301
    *  @public function getXoopsCodeXoopsCaptcha
302
    *  @param $var
303
    *  @param $instance
304
    *
305
    *  @return string
306
    */
307
    public function getXoopsCodeGetInstance($var = '', $instance = '', $t = '')
308
    {
309
        return "{$t}\${$var} = {$instance}::getInstance();\n";
310
    }
311
312
    /*
313
    *  @public function getXoopsCodeXoopsCaptcha
314
    *  @param null
315
    *  @return string
316
    */
317
    public function getXoopsCodeXoopsCaptcha($t = '')
318
    {
319
        return "{$t}\$xoopsCaptcha = XoopsCaptcha::getInstance();\n";
320
    }
321
322
    /*
323
    *  @public function getXoopsCodeXoopsImgListArray
324
    *  @param $return
325
    *  @param $var
326
    *  @param $t
327
    *
328
    *  @return string
329
    */
330
    public function getXoopsCodeXoopsImgListArray($return, $var, $t = '')
331
    {
332
        return "{$t}\${$return} = XoopsLists::getImgListAsArray( {$var} );\n";
333
    }
334
335
    /*
336
    *  @public function getXoopsCodeGetConfig
337
    *  @param $moduleDirname
338
    *  @param $name
339
    *  @return string
340
    */
341
    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...
342
    {
343
        return "\${$moduleDirname}->getConfig('{$name}')";
344
    }
345
346
    /*
347
    *  @public function getXoopsCodeIdGetVar
348
    *  @param $lpFieldName
349
    *  @return string
350
    */
351
    public function getXoopsCodeIdGetVar($lpFieldName, $t = '')
352
    {
353
        return "{$t}\${$lpFieldName}['id'] = \$i;\n";
354
    }
355
356
    /*
357
    *  @public function getXoopsCodeGetVarAll
358
    *  @param $lpFieldName
359
    *  @param $rpFieldName
360
    *  @param $tableName
361
    *  @param $fieldName
362
    *  @return string
363
    */
364
    public function getXoopsCodeGetVarAll($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '')
365
    {
366
        return "{$t}\${$lpFieldName}['{$rpFieldName}'] = \${$tableName}All[\$i]->getVar('{$fieldName}');\n";
367
    }
368
369
    /*
370
    *  @public function getXoopsHandlerInstance
371
    *  @param $moduleDirname
372
    *  
373
    *  @return string
374
    */
375
    public function getXoopsHandlerInstance($moduleDirname, $t = '')
376
    {
377
        $ucfModuleDirname = ucfirst($moduleDirname);
378
        $ret = "{$t}// Get instance of module\n";
379
        $ret .= "{$t}\${$moduleDirname} = {$ucfModuleDirname}Helper::getInstance();\n";
380
381
        return $ret;
382
    }
383
384
    /*
385
    *  @public function getXoopsHandlerLine
386
    *  @param $moduleDirname
387
    *  @param $tableName
388
    *  @return string
389
    */
390
    public function getXoopsHandlerLine($moduleDirname, $tableName, $t = '')
391
    {
392
        return "{$t}\${$tableName}Handler =& \${$moduleDirname}->getHandler('{$tableName}');\n";
393
    }
394
395
    /*
396
    *  @public function getXoopsClearHandler
397
    *  @param $left
398
    *  @param $ref
399
    *  @param $anchor
400
    *  @param $var
401
    *
402
    *  @return string
403
    */
404
    public function getXoopsClearHandler($left, $ref = '&', $anchor, $var, $t = '')
405
    {
406
        return "{$t}\${$left}Handler ={$ref} \${$anchor}->getHandler('{$var}');\n";
407
    }
408
409
    /*
410
    *  @public function getXoopsFormSelectExtraOptions
411
    *  @param $varSelect
412
    *  @param $caption
413
    *  @param $var
414
    *  @param $options
415
    *  @param $setExtra
416
    *  
417
    *  @return string
418
    */
419
    public function getXoopsFormSelectExtraOptions($varSelect = '', $caption = '', $var = '', $options = array(), $setExtra = true, $t = '')
420
    {
421
        $ret = "{$t}\${$varSelect} = new XoopsFormSelect({$caption}, '{$var}', \${$var});\n";
422
        if (false !== $setExtra) {
423
            $ret .= "{$t}\${$varSelect}->setExtra('{$setExtra}');\n";
424
        }
425
        foreach ($options as $key => $value) {
426
            $ret .= "{$t}\${$varSelect}->addOption('{$key}', {$value});\n";
427
        }
428
429
        return $ret;
430
    }
431
432
    /*
433
     *  @public function getXoopsCodeUnameFromId
434
     *  @param $left
435
     *  @param $tableName
436
     *
437
     * @return string
438
     */
439
    public function getXoopsCodeUnameFromId($left, $value, $t = '')
440
    {
441
        return "{$t}\${$left} = XoopsUser::getUnameFromId({$value});\n";
442
    }
443
444
    /*
445
    *  @public function getXoopsCodeFormatTimeStamp
446
    *  @param $lpFieldName
447
    *  @param $rpFieldName
448
    *  @param $tableName
449
    *  @param $fieldName
450
    *  @return string
451
    */
452
    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...
453
    {
454
        return "\${$left} = formatTimeStamp({$value}, '{$format}');\n";
455
    }
456
457
    /*
458
    *  @public function getXoopsCodeTopicGetVar
459
    *  @param $lpFieldName
460
    *  @param $rpFieldName
461
    *  @param $tableName
462
    *  @param $tableNameTopic
463
    *  @param $fieldNameParent
464
    *  @param $fieldNameTopic
465
    *  @return string
466
    */
467
    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...
468
    {
469
        $ret = <<<EOT
470
\t\t\t\t// Get Var {$fieldNameParent}
471
\t\t\t\t\${$rpFieldName} =& \${$tableNameTopic}Handler->get(\${$tableName}All[\$i]->getVar('{$fieldNameParent}'));
472
\t\t\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$rpFieldName}->getVar('{$fieldNameTopic}');\n
473
EOT;
474
475
        return $ret;
476
    }
477
478
    /*
479
    *  @public function getXoopsCodeParentTopicGetVar
480
    *  @param $moduleDirname
481
    *  @param $lpFieldName
482
    *  @param $rpFieldName
483
    *  @param $tableName
484
    *  @param $tableSoleNameTopic
485
    *  @param $tableNameTopic
486
    *  @param $fieldNameParent
487
    *  @return string
488
    */
489
    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...
490
    {
491
        $ret = <<<EOT
492
\t\t\t\tif(!isset(\${$tableNameTopic}Handler)) {
493
\t\t\t\t\t// Get {$tableNameTopic} Handler
494
\t\t\t\t\t\${$tableNameTopic}Handler =& \${$moduleDirname}->getHandler('{$tableNameTopic}');
495
\t\t\t\t}
496
\t\t\t\t// Get Var {$fieldNameParent}
497
\t\t\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$tableNameTopic}Handler->get{$tableSoleNameTopic}FromId(\${$tableName}All[\$i]->getVar('{$fieldNameParent}'));\n
498
EOT;
499
500
        return $ret;
501
    }
502
503
    /*
504
    *  @public function getXoopsCodeUploadImageGetVar
505
    *  @param $lpFieldName
506
    *  @param $rpFieldName
507
    *  @param $tableName
508
    *  @param $fieldName
509
    *  @return string
510
    */
511
    public function getXoopsCodeUploadImageGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
512
    {
513
        $ret = <<<EOT
514
\t\t\t\t// Get Var {$fieldName}
515
\t\t\t\t\${$fieldName} = \${$tableName}All[\$i]->getVar('{$fieldName}');
516
\t\t\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$fieldName} ? \${$fieldName} : 'blank.gif';\n
517
EOT;
518
519
        return $ret;
520
    }
521
    /*
522
    *  @public function getXoopsCodeUrlFileGetVar
523
    *  @param $lpFieldName
524
    *  @param $rpFieldName
525
    *  @param $tableName
526
    *  @param $fieldName
527
    *  @return string
528
    */
529
    public function getXoopsCodeUrlFileGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
530
    {
531
        return $this->getXoopsCodeGetVarAll($lpFieldName, $rpFieldName, $tableName, $fieldName);
532
    }
533
    /*
534
    *  @public function getXoopsCodeTextAreaGetVar
535
    *  @param $lpFieldName
536
    *  @param $rpFieldName
537
    *  @param $tableName
538
    *  @param $fieldName
539
    *  @return string
540
    */
541
    public function getXoopsCodeTextAreaGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '')
542
    {
543
        return "{$t}\${$lpFieldName}['{$rpFieldName}'] = strip_tags(\${$tableName}All[\$i]->getVar('{$fieldName}'));\n";
544
    }
545
546
    /*
547
    *  @public function getXoopsCodeSelectUserGetVar
548
    *  @param $lpFieldName
549
    *  @param $rpFieldName
550
    *  @param $tableName
551
    *  @param $fieldName
552
    * @return string
553
    */
554
    public function getXoopsCodeSelectUserGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '')
555
    {
556
        return "{$t}\${$lpFieldName}['{$rpFieldName}'] = XoopsUser::getUnameFromId(\${$tableName}All[\$i]->getVar('{$fieldName}'), 's');\n";
557
    }
558
559
    /*
560
    *  @public function getXoopsCodeTextDateSelectGetVar
561
    *  @param $lpFieldName
562
    *  @param $rpFieldName
563
    *  @param $tableName
564
    *  @param $fieldName
565
    *  @return string
566
    */
567
    public function getXoopsCodeTextDateSelectGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '')
568
    {
569
        return "{$t}\${$lpFieldName}['{$rpFieldName}'] = formatTimeStamp(\${$tableName}All[\$i]->getVar('{$fieldName}'), 's');\n";
570
    }
571
572
    /*
573
    *  @public function getXoopsCodeUserHeader
574
    *  @param $moduleDirname
575
    *  @param $tableName
576
    *  @return string
577
    */
578
    public function getXoopsCodeXoopsOptionTemplateMain($moduleDirname, $tableName, $t = '')
579
    {
580
        return "{$t}\$GLOBALS['xoopsOption']['template_main'] = '{$moduleDirname}_{$tableName}.tpl';\n";
581
    }
582
583
    /*
584
    *  @public function getXoopsCodeUserHeader
585
    *  @param $moduleDirname
586
    *  @param $tableName
587
    *  @return string
588
    */
589
    public function getXoopsCodeUserHeader($moduleDirname, $tableName)
590
    {
591
        $ret = $this->pc->getPhpCodeIncludeDir('__DIR__', 'header');
592
        $ret .= $this->getXoopsCodeXoopsOptionTemplateMain($moduleDirname, $tableName);
593
        $ret .= $this->pc->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'header', true);
594
595
        return $ret;
596
    }
597
598
    /*
599
    *  @public function getXoopsCodePermissionsHeader
600
    *  @param null
601
    */
602
    /**
603
     * @return string
604
     */
605
    public function getXoopsCodePermissionsHeader()
606
    {
607
        $ret = $this->pc->getPhpCodeCommentLine('Permission');
608
        $ret .= $this->pc->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/xoopsform/grouppermform', true);
609
        $ret .= $this->getXoopsCodeEqualsOperator('$gpermHandler', "xoops_gethandler('groupperm')", true);
610
        $groups = $this->getXoopsCodeEqualsOperator('$groups', '$xoopsUser->getGroups()');
611
        $elseGroups = $this->getXoopsCodeEqualsOperator('$groups', 'XOOPS_GROUP_ANONYMOUS');
612
        $ret .= $this->pc->getPhpCodeConditions('is_object($xoopsUser)', '', $type = '', $groups, $elseGroups);
613
614
        return $ret;
615
    }
616
617
    /**
618
     *  @public function getXoopsCodeGetFieldId
619
     *
620
     *  @param $fields
621
     *
622
     *  @return string
623
     */
624
    public function getXoopsCodeGetFieldId($fields)
625
    {
626
        $fieldId = 'id';
627
        foreach (array_keys($fields) as $f) {
628
            $fieldName = $fields[$f]->getVar('field_name');
629
            if (0 == $f) {
630
                $fieldId = $fieldName;
631
            }
632
        }
633
634
        return $fieldId;
635
    }
636
637
    /**
638
     *  @public function getXoopsCodeGetFieldName
639
     *
640
     *  @param $fields
641
     *
642
     *  @return string
643
     */
644
    public function getXoopsCodeGetFieldName($fields)
645
    {
646
        foreach (array_keys($fields) as $f) {
647
            $fieldName = $fields[$f]->getVar('field_name');
648
        }
649
650
        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...
651
    }
652
653
    /**
654
     *  @public function getXoopsCodeGetFieldParentId
655
     *
656
     *  @param $fields
657
     *
658
     *  @return string
659
     */
660
    public function getXoopsCodeGetFieldParentId($fields)
661
    {
662
        $fieldPid = 'pid';
663
        foreach (array_keys($fields) as $f) {
664
            $fieldName = $fields[$f]->getVar('field_name');
665
            if (1 == $fields[$f]->getVar('field_parent')) {
666
                $fieldPid = $fieldName;
667
            }
668
        }
669
670
        return $fieldPid;
671
    }
672
673
    /**
674
     *  @public function getXoopsCodeUserSaveElements
675
     *
676
     *  @param $moduleDirname
677
     *  @param $tableName
678
     *  @param $fields
679
     *
680
     *  @return string
681
     */
682
    public function getXoopsCodeUserSaveElements($moduleDirname, $tableName, $fields)
683
    {
684
        $ret = '';
685
        foreach (array_keys($fields) as $f) {
686
            $fieldName = $fields[$f]->getVar('field_name');
687
            $fieldElement = $fields[$f]->getVar('field_element');
688
            if (1 == $fields[$f]->getVar('field_main')) {
689
                $fieldMain = $fieldName;
690
            }
691
            if ((5 == $fieldElement) || (6 == $fieldElement)) {
692
                $ret .= $this->getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName);
693
            } elseif (13 == $fieldElement) {
694
                $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...
695
            } elseif (14 == $fieldElement) {
696
                $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...
697
            } elseif (15 == $fieldElement) {
698
                $ret .= $this->getXoopsCodeTextDateSelectSetVar($tableName, $fieldName);
699
            } else {
700
                $ret .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
701
            }
702
        }
703
704
        return $ret;
705
    }
706
707
    /*
708
    *  @public function getXoopsCodeXoopsRequest
709
    *  @param $left
710
    *  @param $var1
711
    *  @param $var2
712
    *  @param $type
713
    *  @param $metod
714
    *  @return string
715
    */
716
    public function getXoopsCodeXoopsRequest($left = '', $var1 = '', $var2 = '', $type = 'String', $metod = false, $t = '')
717
    {
718
        $ret = '';
719
        $intVars = ($var2 != '') ? "'{$var1}', {$var2}" : "'{$var1}'";
720
        if ($type == 'String') {
721
            $ret .= "{$t}\${$left} = XoopsRequest::getString('{$var1}', '{$var2}');\n";
722
        } elseif ($type == 'Int') {
723
            $ret .= "{$t}\${$left} = XoopsRequest::getInt({$intVars});\n";
724
        } elseif ($type == 'Int' && $metod !== false) {
725
            $ret .= "{$t}\${$left} = XoopsRequest::getInt({$intVars}, '{$metod}');\n";
726
        }
727
728
        return $ret;
729
    }
730
731
    /**
732
     *  @public function getXoopsCodeTplAssign     
733
     *
734
     *  @param $tplString
735
     *  @param $phpRender
736
     *  @param $leftIsString 
737
     *
738
     *  @return string
739
     */
740
    public function getXoopsCodeTplAssign($tplString, $phpRender, $leftIsString = true, $t = '')
741
    {
742
        $assign = "{$t}\$GLOBALS['xoopsTpl']->assign(";
743
        if ($leftIsString === false) {
744
            $ret = $assign."{$tplString}, {$phpRender});\n";
745
        } else {
746
            $ret = $assign."'{$tplString}', {$phpRender});\n";
747
        }
748
749
        return $ret;
750
    }
751
752
    /**
753
     *  @public function getXoopsCodeXoopsTplAppend
754
     *
755
     *  @param $tplString
756
     *  @param $phpRender
757
     *
758
     *  @return string
759
     */
760
    public function getXoopsCodeXoopsTplAppend($tplString, $phpRender, $t = '')
761
    {
762
        return "{$t}\$GLOBALS['xoopsTpl']->append('{$tplString}', {$phpRender});\n";
763
    }
764
765
    /**
766
     *  @public function getXoopsCodeXoopsTplAppendByRef
767
     *
768
     *  @param $tplString
769
     *  @param $phpRender
770
     *
771
     *  @return string
772
     */
773
    public function getXoopsCodeXoopsTplAppendByRef($tplString, $phpRender, $t = '')
774
    {
775
        return "{$t}\$GLOBALS['xoopsTpl']->appendByRef('{$tplString}', {$phpRender});\n";
776
    }
777
778
    /**
779
     *  @public function getXoopsCodePath
780
     *
781
     *  @param $directory
782
     *  @param $filename
783
     *  @param $isParam
784
     *
785
     *  @return string
786
     */
787
    public function getXoopsCodePath($directory, $filename, $isParam = false, $t = '')
788
    {
789
        if (!$isParam) {
790
            $ret = "{$t}\$GLOBALS['xoops']->path({$directory}.'/{$filename}.php');\n";
791
        } else {
792
            $ret = "\$GLOBALS['xoops']->path({$directory}.'/{$filename}.php')";
793
        }
794
795
        return $ret;
796
    }
797
798
    /**
799
     *  @public function getXoopsCodeTplDisplay
800
     *
801
     *  @param $displayTpl
802
     *
803
     *  @return string
804
     */
805
    public function getXoopsCodeTplDisplay($displayTpl = '{$templateMain}', $t = '')
806
    {
807
        return "{$t}\$GLOBALS['xoopsTpl']->display(\"db:{$displayTpl}\");\n";
808
    }
809
810
    /**
811
     *  @public function getXoopsCodeGetInfo
812
     *
813
     *  @param $left
814
     *  @param $string
815
     *  @param $isParam
816
     *
817
     *  @return string
818
     */
819
    public function getXoopsCodeGetInfo($left = '', $string, $isParam = false, $t = '')
820
    {
821
        if (!$isParam) {
822
            $ret = "{$t}\${$left} = \$GLOBALS['xoopsModule']->getInfo('{$string}');\n";
823
        } else {
824
            $ret = "\$GLOBALS['xoopsModule']->getInfo('{$string}')";
825
        }
826
827
        return $ret;
828
    }
829
830
    /**
831
     *  @public function getXoopsCodeAddRight
832
     *
833
     *  @param $anchor
834
     *  @param $permString
835
     *  @param $var
836
     *  @param $groups
837
     *  @param $mid
838
     *  @param $isParam
839
     *
840
     *  @return string
841
     */
842
    public function getXoopsCodeAddRight($anchor, $permString = '', $var = '', $groups = '', $mid = '', $isParam = false, $t = '')
843
    {
844
        if (!$isParam) {
845
            $ret = "{$t}\${$anchor}->addRight('{$permString}', {$var}, {$groups}, {$mid});\n";
846
        } else {
847
            $ret = "\${$anchor}->addRight('{$permString}', {$var}, {$groups}, {$mid})";
848
        }
849
850
        return $ret;
851
    }
852
853
    /**
854
     *  @public function getXoopsCodeCheckRight
855
     *
856
     *  @param $anchor
857
     *  @param $permString
858
     *  @param $var
859
     *  @param $groups
860
     *  @param $mid
861
     *  @param $isParam
862
     *
863
     *  @return string
864
     */
865
    public function getXoopsCodeCheckRight($anchor, $permString = '', $var = '', $groups = '', $mid = '', $isParam = false, $t = '')
866
    {
867
        if (!$isParam) {
868
            $ret = "{$t}{$anchor}->checkRight('{$permString}', {$var}, {$groups}, {$mid});\n";
869
        } else {
870
            $ret = "{$anchor}->checkRight('{$permString}', {$var}, {$groups}, {$mid})";
871
        }
872
873
        return $ret;
874
    }
875
876
    /**
877
     *  @public function getXoopsCodeObjHandlerCreate
878
     *
879
     *  @param $tableName
880
     *
881
     *  @return string
882
     */
883
    public function getXoopsCodeObjHandlerCreate($tableName, $t = '')
884
    {
885
        return "{$t}\${$tableName}Obj =& \${$tableName}Handler->create();\n";
886
    }
887
888
    /**
889
     *  @public function getXoopsCodeObjHandlerCount
890
     *
891
     *  @param $tableName
892
     *
893
     *  @return string
894
     */
895
    public function getXoopsCodeObjHandlerCount($tableName, $t = '')
896
    {
897
        $ucfTableName = ucfirst($tableName);
898
        $ret = "{$t}\${$tableName}Count = \${$tableName}Handler->getCount{$ucfTableName}();\n";
899
900
        return $ret;
901
    }
902
903
    /**
904
     *  @public function getXoopsCodeClearCount
905
     *
906
     *  @param $tableName
907
     *
908
     *  @return string
909
     */
910
    public function getXoopsCodeClearHandlerCount($left, $anchor = '', $params = '', $t = '')
911
    {
912
        $ret = "{$t}\${$left} = \${$anchor}Handler->getCount({$params});\n";
913
914
        return $ret;
915
    }
916
917
    /**
918
     *  @public function getXoopsCodeObjHandlerAll
919
     *
920
     *  @param $tableName
921
     *  @param $fieldMain
922
     *  @param $start
923
     *  @param $limit
924
     *
925
     *  @return string
926
     */
927
    public function getXoopsCodeObjHandlerAll($tableName, $fieldMain = '', $start = '0', $limit = '0', $t = '')
928
    {
929
        $ucfTableName = ucfirst($tableName);
930
        $startLimit = ($limit != '0') ? "{$start}, {$limit}" : '0';
931
        $params = ($fieldMain != '') ? "{$startLimit}, '{$fieldMain}'" : $startLimit;
932
        $ret = "{$t}\${$tableName}All = \${$tableName}Handler->getAll{$ucfTableName}({$params});\n";
933
934
        return $ret;
935
    }
936
937
    /**
938
     *  @public function getXoopsCodeClearHandlerAll
939
     *
940
     *  @param $tableName
941
     *  @param $fieldMain
942
     *  @param $start
943
     *  @param $limit
944
     *
945
     *  @return string
946
     */
947
    public function getXoopsCodeClearHandlerAll($left, $anchor = '', $params = '', $t = '')
948
    {
949
        $ret = "{$t}\${$left} = \${$anchor}Handler->getAll({$params});\n";
950
951
        return $ret;
952
    }
953
954
    /**
955
     *  @public function getXoopsCodeGetValues
956
     *
957
     *  @param $tableName
958
     *  @param $tableSoleName
959
     *
960
     *  @return string
961
     */
962
    public function getXoopsCodeGetValues($tableName, $tableSoleName, $index = 'i', $noArray = false, $t = '')
963
    {
964
        $ucfTableName = ucfirst($tableName);
965
        if (!$noArray) {
966
            $ret = "{$t}\${$tableSoleName} = \${$tableName}All[\${$index}]->getValues{$ucfTableName}();\n";
967
        } else {
968
            $ret = "{$t}\${$tableSoleName} = \${$tableName}->getValues{$ucfTableName}();\n";
969
        }
970
971
        return $ret;
972
    }
973
974
    /**
975
     *  @public function getXoopsCodeSetVarsObjects
976
     *
977
     *  @param $moduleDirname
978
     *  @param $tableName
979
     *  @param $fields
980
     *
981
     *  @return string
982
     */
983
    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...
984
    {
985
        $ret = '';
986
        foreach (array_keys($fields) as $f) {
987
            $fieldName = $fields[$f]->getVar('field_name');
988
            $fieldElement = $fields[$f]->getVar('field_element');
989
            if (1 == $fields[$f]->getVar('field_main')) {
990
                $fieldMain = $fieldName;
991
            }
992
            if ($f > 0) { // If we want to hide field id
993
                switch ($fieldElement) {
994
                    case 5:
995
                    case 6:
996
                        $ret .= $this->getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName);
997
                        break;
998
                    case 11:
999
                        $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...
1000
                        break;
1001
                    case 12:
1002
                        $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...
1003
                        break;
1004
                    case 13:
1005
                        $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...
1006
                        break;
1007
                    case 14:
1008
                        $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...
1009
                        break;
1010
                    case 15:
1011
                        $ret .= $this->getXoopsCodeTextDateSelectSetVar($tableName, $fieldName);
1012
                        break;
1013
                    default:
1014
                        $ret .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
1015
                        break;
1016
                }
1017
            }
1018
        }
1019
1020
        return $ret;
1021
    }
1022
1023
    /**
1024
     *  @public function getXoopsCodeSecurity
1025
     *
1026
     *  @param $tableName
1027
     *
1028
     *  @return string
1029
     */
1030
    public function getXoopsCodeSecurity($tableName, $t = '')
1031
    {
1032
        $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...
1033
        $implode = $this->pc->getPhpCodeImplode(',', $securityError);
1034
        $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...
1035
        $securityCheck = $this->getXoopsCodeSecurityCheck();
1036
1037
        return $this->pc->getPhpCodeConditions('!'.$securityCheck, '', '', $content, $t);
1038
    }
1039
1040
    /*
1041
    *  @public function getXoopsCodeInsertData
1042
    *  @param $tableName
1043
    *  @param $language
1044
    *  @return string
1045
    */
1046
    public function getXoopsCodeInsertData($tableName, $language, $t = '')
1047
    {
1048
        $content = "{$t}\t".$this->getXoopsCodeRedirectHeader($tableName.'.php', '?op=list', 2, "{$language}FORM_OK");
1049
        $handlerInsert = $this->getXoopsCodeHandler($tableName, $tableName, false, true, false, 'Obj');
1050
1051
        return $this->pc->getPhpCodeConditions($handlerInsert, '', '', $content, $t);
1052
    }
1053
1054
    /*
1055
    *  @public function getXoopsCodeRedirectHeader
1056
    *  @param $directory
1057
    *  @param $options
1058
    *  @param $numb
1059
    *  @param $var
1060
    *  @param $isString
1061
    *
1062
    *  @return string
1063
    */
1064
    public function getXoopsCodeRedirectHeader($directory, $options = '', $numb = '2', $var, $isString = true, $t = '')
1065
    {
1066
        if (!$isString) {
1067
            $ret = "{$t}redirect_header({$directory}, {$numb}, {$var});\n";
1068
        } else {
1069
            $ret = "{$t}redirect_header('{$directory}{$options}', {$numb}, {$var});\n";
1070
        }
1071
1072
        return $ret;
1073
    }
1074
1075
    /*
1076
    *  @public function getXoopsCodeXoopsConfirm
1077
    *  @param $tableName
1078
    *  @param $language
1079
    *  @param $fieldId
1080
    *  @param $fieldMain    
1081
    *  @param $options
1082
    *
1083
    *  @return string
1084
    */
1085
    public function getXoopsCodeXoopsConfirm($tableName, $language, $fieldId, $fieldMain, $options = 'delete', $t = '')
1086
    {
1087
        $stuOptions = strtoupper($options);
1088
        $ccFieldId = $this->tf->getCamelCase($fieldId, false, true);
1089
        $array = "array('ok' => 1, '{$fieldId}' => \${$ccFieldId}, 'op' => '{$options}')";
1090
        $ret = "{$t}xoops_confirm({$array}, \$_SERVER['REQUEST_URI'], sprintf({$language}FORM_SURE_{$stuOptions}, \${$tableName}Obj->getVar('{$fieldMain}')));\n";
1091
1092
        return $ret;
1093
    }
1094
1095
    /*
1096
    *  @public function getXoopsCodeAddStylesheet
1097
    *  @param $style
1098
    *  
1099
    *  @return string
1100
    */
1101
    public function getXoopsCodeAddStylesheet($style = 'style', $t = '')
1102
    {
1103
        return "{$t}\$GLOBALS['xoTheme']->addStylesheet( \${$style}, null );\n";
1104
    }
1105
1106
    /*
1107
    *  @public function getXoopsCodeSecurityCheck
1108
    *  @param $denial
1109
    *  @return boolean
1110
    */
1111
    public function getXoopsCodeSecurityCheck($denial = '')
1112
    {
1113
        return "{$denial}\$GLOBALS['xoopsSecurity']->check()";
1114
    }
1115
1116
    /*
1117
    *  @public function getXoopsCodeSecurityErrors
1118
    *  @param null
1119
    *  @return string
1120
    */
1121
    public function getXoopsCodeSecurityErrors()
1122
    {
1123
        return "\$GLOBALS['xoopsSecurity']->getErrors()";
1124
    }
1125
1126
    /**
1127
     *  @public function getXoopsCodeHtmlErrors
1128
     *
1129
     *  @param $tableName
1130
     *  @param $isParam
1131
     *  @param $obj
1132
     *
1133
     *  @return string
1134
     */
1135
    public function getXoopsCodeHtmlErrors($tableName, $isParam = false, $obj = 'Obj', $t = '')
1136
    {
1137
        $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...
1138
        if ($isParam) {
1139
            $ret = "\${$tableName}{$obj}->getHtmlErrors()";
1140
        } else {
1141
            $ret = "{$t}\${$tableName}{$obj} =& \${$tableName}->getHtmlErrors();";
1142
        }
1143
1144
        return $ret;
1145
    }
1146
1147
    /**
1148
     *  @public function getXoopsCodeObjHandlerCount
1149
     *
1150
     *  @param $left
1151
     *  @param $tableName
1152
     *  @param $obj
1153
     *
1154
     *  @return string
1155
     */
1156
    public function getXoopsCodeGetForm($left, $tableName, $obj = '', $t = '')
1157
    {
1158
        $ucfTableName = ucfirst($tableName);
1159
1160
        return "{$t}\${$left} =& \${$tableName}{$obj}->getForm{$ucfTableName}();\n";
1161
    }
1162
1163
    /**
1164
     *  @public function getXoopsCodeGet
1165
     *
1166
     *  @param $left
1167
     *  @param $var
1168
     *  @param $obj
1169
     *  @param $handler
1170
     *  @param $isParam
1171
     *
1172
     *  @return string
1173
     */
1174
    public function getXoopsCodeGet($left, $var, $obj = '', $handler = 'Handler', $isParam = false, $t = '')
1175
    {
1176
        if ($isParam) {
1177
            $ret = "\${$left}{$handler}->get(\${$var})";
1178
        } else {
1179
            $ret = "{$t}\${$left}{$obj} =& \${$handler}->get(\${$var});\n";
1180
        }
1181
1182
        return $ret;
1183
    }
1184
1185
    /**
1186
     *  @public function getXoopsCodeHandler
1187
     *
1188
     *  @param $left
1189
     *  @param $var
1190
     *  @param $obj
1191
     *  @param $isHandler
1192
     *
1193
     *  @return string
1194
     */
1195
    public function getXoopsCodeInsert($left, $var, $obj = '', $isHandler = false)
1196
    {
1197
        $handler = ($isHandler === false) ? '' : 'Handler';
1198
        if ($obj != '') {
1199
            $ret = "\${$left}{$handler}->insert(\${$var}{$obj})";
1200
        } else {
1201
            $ret = "\${$left}{$handler}->insert(\${$var})";
1202
        }
1203
1204
        return $ret;
1205
    }
1206
1207
    /**
1208
     *  @public function getXoopsCodeDelete
1209
     *
1210
     *  @param $tableName
1211
     *  @param $var
1212
     *  @param $obj
1213
     *  @param $isHandler
1214
     *
1215
     *  @return string
1216
     */
1217
    public function getXoopsCodeDelete($left, $var, $obj = '', $isHandler = false)
1218
    {
1219
        $handler = $isHandler === false ? '' : 'Handler';
1220
        if ($obj != '') {
1221
            $ret = "\${$left}{$handler}->delete(\${$var}{$obj})";
1222
        } else {
1223
            $ret = "\${$left}{$handler}->delete(\${$var})";
1224
        }
1225
1226
        return $ret;
1227
    }
1228
1229
    /**
1230
     *  @public function getXoopsCodeHandler
1231
     *
1232
     *  @param $left
1233
     *  @param $var
1234
     *
1235
     *  @return string
1236
     */
1237
    public function getXoopsCodeHandler($left, $var, $get = false, $insert = false, $delete = false, $obj = '', $t = '')
1238
    {
1239
        if ($get) {
1240
            $ret = "{$t}\${$left}Handler->get(\${$var});";
1241
        } elseif ($insert && ($obj != '')) {
1242
            $ret = "{$t}\${$left}Handler->insert(\${$var}{$obj});";
1243
        } elseif ($delete && ($obj != '')) {
1244
            $ret = "{$t}\${$left}Handler->delete(\${$var}{$obj});";
1245
        }
1246
1247
        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...
1248
    }
1249
1250
    /*
1251
    *  @public function getTopicGetVar
1252
    *  @param $lpFieldName
1253
    *  @param $rpFieldName
1254
    *  @param $tableName
1255
    *  @param $tableNameTopic
1256
    *  @param $fieldNameParent
1257
    *  @param $fieldNameTopic
1258
    *  @return string
1259
    */
1260
    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...
1261
    {
1262
        $t = "\t\t";
1263
        $ret = $this->pc->getPhpCodeCommentLine('Get Var', $fieldNameParent, $t);
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...
1264
        $paramGet = $this->getXoopsCodeGetVar('', "\${$tableName}All[\$i]", $fieldNameParent = '', true, '');
0 ignored issues
show
Unused Code introduced by
$paramGet 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...
1265
        $ret = $this->getXoopsCodeGet($rpFieldName, $tableNameTopic, '', true, false, $t);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a string.

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...
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...
1266
        $ret = <<<EOT
1267
\t\t// Get Var {$fieldNameParent}
1268
\t\t\${$rpFieldName} =& \${$tableNameTopic}Handler->get(\${$tableName}All[\$i]->getVar('{$fieldNameParent}'));
1269
\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$rpFieldName}->getVar('{$fieldNameTopic}');\n
1270
EOT;
1271
1272
        return $ret;
1273
    }
1274
1275
    /*
1276
    *  @public function getUploadImageGetVar
1277
    *  @param $lpFieldName
1278
    *  @param $rpFieldName
1279
    *  @param $tableName
1280
    *  @param $fieldName
1281
    *  @return string
1282
    */
1283
    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...
1284
    {
1285
        $t = "\t\t";
1286
        $ret = $this->pc->getPhpCodeCommentLine('Get Var', $fieldNameParent, $t);
0 ignored issues
show
Bug introduced by
The variable $fieldNameParent does not exist. Did you mean $fieldName?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
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...
1287
        $ret = <<<EOT
1288
\t\t// Get Var {$fieldName}
1289
\t\t\${$fieldName} = \${$tableName}All[\$i]->getVar('{$fieldName}');
1290
\t\t\$upload_image = \${$fieldName} ? \${$fieldName} : 'blank.gif';
1291
\t\t\${$lpFieldName}['{$rpFieldName}'] = \$upload_image;\n
1292
EOT;
1293
1294
        return $ret;
1295
    }
1296
1297
    /**
1298
     *  @public function getXoopsCodeSaveFieldId
1299
     *
1300
     *  @param $fields
1301
     *
1302
     *  @return string
1303
     */
1304
    public function getXoopsCodeSaveFieldId($fields)
1305
    {
1306
        foreach (array_keys($fields) as $f) {
1307
            if (0 == $f) {
1308
                $fieldId = $fields[$f]->getVar('field_name');
1309
            }
1310
        }
1311
1312
        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...
1313
    }
1314
1315
    /**
1316
     *  @public function getXoopsCodeSaveFieldMain
1317
     *
1318
     *  @param $fields
1319
     *
1320
     *  @return string
1321
     */
1322
    public function getXoopsCodeSaveFieldMain($fields)
1323
    {
1324
        foreach (array_keys($fields) as $f) {
1325
            if (1 == $fields[$f]->getVar('field_main')) {
1326
                $fieldMain = $fields[$f]->getVar('field_name');
1327
            }
1328
        }
1329
1330
        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...
1331
    }
1332
1333
    /**
1334
     *  @public function getXoopsCodeSaveElements
1335
     *
1336
     *  @param $moduleDirname
1337
     *  @param $tableName
1338
     *  @param $fields
1339
     *
1340
     *  @return string
1341
     */
1342
    public function getXoopsCodeSaveElements($moduleDirname, $tableName, $fields)
1343
    {
1344
        $ret = '';
1345
        foreach (array_keys($fields) as $f) {
1346
            $fieldName = $fields[$f]->getVar('field_name');
1347
            $fieldElement = $fields[$f]->getVar('field_element');
1348
            if (1 == $fields[$f]->getVar('field_main')) {
1349
                $fieldMain = $fieldName;
1350
            }
1351
            if ((5 == $fieldElement) || (6 == $fieldElement)) {
1352
                $ret .= $this->getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName);
1353
            } elseif (13 == $fieldElement) {
1354
                $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...
1355
            } elseif (14 == $fieldElement) {
1356
                $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...
1357
            } elseif (15 == $fieldElement) {
1358
                $ret .= $this->getXoopsCodeTextDateSelectSetVar($tableName, $fieldName);
1359
            } else {
1360
                $ret .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
1361
            }
1362
        }
1363
1364
        return $ret;
1365
    }
1366
1367
    /*
1368
    *  @public function getXoopsCodePageNav
1369
    *  @param $tableName
1370
    *
1371
    *  @return string
1372
    */
1373
    public function getXoopsCodePageNav($tableName, $t = '')
1374
    {
1375
        $ret = $this->pc->getPhpCodeCommentLine('Display Navigation', null, $t);
1376
        $condition = "{$t}\t".$this->pc->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/pagenav', true);
1377
        $condition .= "{$t}\t\$pagenav = new XoopsPageNav(\${$tableName}Count, \$limit, \$start, 'start', 'op=list&limit=' . \$limit);\n";
1378
        $condition .= "{$t}\t".$this->getXoopsCodeTplAssign('pagenav', '$pagenav->renderNav(4)');
1379
        $ret .= $this->pc->getPhpCodeConditions("\${$tableName}Count", ' > ', '$limit', $condition, false, $t);
1380
1381
        return $ret;
1382
    }
1383
}
1384