Completed
Push — master ( 1a43b9...76063f )
by Gino
07:55 queued 03:52
created

TDMCreateXoopsCode::getXoopsCodeGet()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 7

Duplication

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

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

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

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

Loading history...
2
3
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
8
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
/**
13
 * tdmcreate module.
14
 *
15
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 *
18
 * @since           2.5.0
19
 *
20
 * @author          Txmod Xoops http://www.txmodxoops.org
21
 *
22
 * @version         $Id: TDMCreateXoopsCode.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
defined('XOOPS_ROOT_PATH') || die('Restricted access');
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
    *  @public function constructor
42
    *  @param null
43
    */
44
    /**
45
     *
46
     */
47
    public function __construct()
48
    {
49
        $this->tdmcfile = TDMCreateFile::getInstance();
50
		$this->phpcode = TDMCreatePhpCode::getInstance();
51
    }
52
53
    /*
54
    *  @static function &getInstance
55
    *  @param null
56
    */
57
    /**
58
     * @return TDMCreateXoopsCode
59
     */
60
    public static function &getInstance()
61
    {
62
        static $instance = false;
63
        if (!$instance) {
64
            $instance = new self();
65
        }
66
67
        return $instance;
68
    }
69
70
    /*
71
    *  @public function getXoopsCodeEqualsOperator
72
    *  @param $left
73
    *  @param $right
74
    *  @param boolean $ref
75
    *  @return string
76
    */
77
    public function getXoopsCodeEqualsOperator($left, $right, $ref = false)
78
    {
79
        if (false === $ref) {
80
            $ret = "{$left} = {$right};\n";
81
        } else {
82
            $ret = "{$left} =& {$right};\n";
83
        }
84
85
        return $ret;
86
    }
87
88
    /*
89
     *  @private function getXoopsCodeSwitch
90
     *  @param $op
91
     *  @param $listCases
92
     *  @param $defaultList
93
     *
94
     * @return string
95
     */
96
    private function getXoopsCodeSwitch($op = 'op', $listCases = array(), $defaultList = false)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
97
    {
98
        $switch = $this->phpcode->getPhpCodeCaseSwitch(array($listCases), $defaultList);
99
100
        return $this->phpcode->getPhpCodeSwitch($op, $switch);
101
    }
102
103
    /*
104
    *  @public function getXoopsCodeCPHeader
105
    *  @param null
106
    *  @return string
107
    */
108
    public function getXoopsCodeCPHeader()
109
    {
110
        return "xoops_cp_header();\n";
111
    }
112
113
    /*
114
    *  @public function getXoopsCodeCPFooter
115
    *  @param null
116
    *  @return string
117
    */
118
    public function getXoopsCodeCPFooter()
119
    {
120
        return "xoops_cp_footer();\n";
121
    }
122
123
    /**
124
     *  @public function getXoopsCodeLoad
125
     *
126
     *  @param $var
127
     *
128
     *  @return string
129
     */
130
    public function getXoopsCodeLoad($var = '')
131
    {
132
        return "xoops_load('{$var}');\n";
133
    }
134
135
    /**
136
     *  @public function getXoopsCodeLoadLanguage
137
     *
138
     *  @param $lang
139
     *
140
     *  @return string
141
     */
142
    public function getXoopsCodeLoadLanguage($lang)
143
    {
144
        return "xoops_loadLanguage('{$lang}');\n";
145
    }
146
147
    /*
148
    *  @public function getXoopsCodeSetVar
149
    *  @param $tableName
150
    *  @param $fieldName
151
    *  @param $var
152
    *  @return string
153
    */
154
    public function getXoopsCodeSetVar($tableName, $fieldName, $var)
155
    {
156
        return "\${$tableName}Obj->setVar('{$fieldName}', {$var});\n";
157
    }
158
159
    /*
160
    *  @public function getXoopsCodeGetVar
161
    *  @param $varLeft
162
    *  @param $handle
163
    *  @param $var
164
    *  @param $isParam
165
    *
166
    *  @return string
167
    */
168
    public function getXoopsCodeGetVar($varLeft = '', $handle = '', $var = '', $isParam = false)
169
    {
170
        if ($isParam === false) {
171
            $ret = "\${$varLeft} = \${$handle}->getVar('{$var}');\n";
172
        } else {
173
            $ret = "\${$handle}->getVar('{$var}')";
174
        }
175
176
        return $ret;
177
    }
178
179
    /*
180
    *  @public function getXoopsCodeGroupPermForm
181
    *  @param $varLeft
182
    *  @param $formTitle
183
    *  @param $moduleId
184
    *  @param $permName
185
    *  @param $permDesc
186
    *  @param $filename
187
    *
188
    *  @return string
189
    */
190
    public function getXoopsCodeGroupPermForm($varLeft = '', $formTitle = '', $moduleId = '', $permName = '', $permDesc = '', $filename = '')
191
    {
192
        return "\${$varLeft} = new XoopsGroupPermForm({$formTitle}, {$moduleId}, {$permName}, {$permDesc}, {$filename});\n";
193
    }
194
195
    /*
196
    *  @public function getXoopsCodeAddItem
197
    *  @param $varLeft
198
    *  @param $paramLeft
199
    *  @param $paramRight
200
    *
201
    *  @return string
202
    */
203
    public function getXoopsCodeAddItem($varLeft = '', $paramLeft = '', $paramRight = '')
204
    {
205
        return "\${$varLeft}->addItem({$paramLeft}, {$paramRight});\n";
206
    }
207
208
    /*
209
    *  @public function getXoopsCodeTextDateSelectSetVar
210
    *  @param $tableName
211
    *  @param $fieldName
212
    *  @return string
213
    */
214
    public function getXoopsCodeTextDateSelectSetVar($tableName, $fieldName)
215
    {
216
        return $this->getXoopsCodeSetVar($tableName, $fieldName, "strtotime(\$_POST['{$fieldName}'])");
217
    }
218
219
    /*
220
    *  @public function getXoopsCodeCheckBoxOrRadioYNSetVar
221
    *  @param $tableName
222
    *  @param $fieldName
223
    *  @return string
224
    */
225
    public function getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName)
226
    {
227
        return $this->getXoopsCodeSetVar($tableName, $fieldName, "((1 == \$_REQUEST['{$fieldName}']) ? '1' : '0')");
228
    }
229
230
    /*
231
    *  @public function getXoopsCodeXoopsMediaUploader
232
    *  @param $var
233
    *  @param $dirPath
234
    *  @param $tableName
235
    *  @param $moduleDirname
236
    *  @return string
237
    */
238
    public function getXoopsCodeXoopsMediaUploader($var = '', $dirPath, $tableName, $moduleDirname)
239
    {
240
        $mimetypes = $this->getXoopsCodeGetConfig($moduleDirname, 'mimetypes');
241
        $maxsize = $this->getXoopsCodeGetConfig($moduleDirname, 'maxsize');
242
243
        return "\${$var} = new XoopsMediaUploader({$dirPath} . '/{$tableName}', {$mimetypes}, {$maxsize}, null, null);\n";
244
    }
245
246
    /*
247
    *  @public function getXoopsCodeGetConfig
248
    *  @param $moduleDirname
249
    *  @param $name
250
    *  @return string
251
    */
252
    public function getXoopsCodeGetConfig($moduleDirname, $name)
253
    {
254
        return "\${$moduleDirname}->getConfig('{$name}')";
255
    }
256
257
    /*
258
    *  @public function getXoopsCodeIdGetVar
259
    *  @param $lpFieldName
260
    *  @return string
261
    */
262
    public function getXoopsCodeIdGetVar($lpFieldName)
263
    {
264
        return "\${$lpFieldName}['id'] = \$i;\n";
265
    }
266
267
    /*
268
    *  @public function getXoopsCodeGetVarAll
269
    *  @param $lpFieldName
270
    *  @param $rpFieldName
271
    *  @param $tableName
272
    *  @param $fieldName
273
    *  @return string
274
    */
275
    public function getXoopsCodeGetVarAll($lpFieldName, $rpFieldName, $tableName, $fieldName)
276
    {
277
        return "\${$lpFieldName}['{$rpFieldName}'] = \${$tableName}All[\$i]->getVar('{$fieldName}');\n";
278
    }
279
280
    /*
281
    *  @public function getXoopsHandlerLine
282
    *  @param $moduleDirname
283
    *  @param $tableName
284
    *  @return string
285
    */
286
    public function getXoopsHandlerLine($moduleDirname, $tableName)
287
    {
288
        return "\${$tableName}Handler =& \${$moduleDirname}->getHandler('{$tableName}');\n";
289
    }
290
291
    /*
292
    *  @public function getXoopsSimpleForm
293
    *  @param $left
294
    *  @param $element
295
    *  @param $elementsContent
296
    *  @param $caption
297
    *  @param $var
298
    *  @param $filename
299
    *  @param $type
300
    *  
301
    *  @return string
302
    */
303
    public function getXoopsSimpleForm($left = '', $element = '', $elementsContent = '', $caption = '', $var = '', $filename = '', $type = 'post')
304
    {
305
        $ret = "\${$left} = new XoopsSimpleForm({$caption}, '{$var}', '{$filename}.php', '{$type}');\n";
306
        if (!empty($elementsContent)) {
307
            $ret .= "{$elementsContent}";
308
        }
309
        $ret .= "\${$left}->addElement(\${$element});\n";
310
        $ret .= "\${$left}->display();\n";
311
312
        return $ret;
313
    }
314
315
    /*
316
    *  @public function getXoopsFormSelect
317
    *  @param $varSelect
318
    *  @param $caption
319
    *  @param $var
320
    *  @param $options
321
    *  @param $setExtra
322
    *  
323
    *  @return string
324
    */
325
    public function getXoopsFormSelect($varSelect = '', $caption = '', $var = '', $options = array(), $setExtra = true)
326
    {
327
        $ret = "\${$varSelect} = new XoopsFormSelect({$caption}, '{$var}', \${$var});\n";
328
        if (false !== $setExtra) {
329
            $ret .= "\${$varSelect}->setExtra('{$setExtra}');\n";
330
        }
331
        foreach ($options as $key => $value) {
332
            $ret .= "\${$varSelect}->addOption('{$key}', {$value});\n";
333
        }
334
335
        return $ret;
336
    }
337
338
    /*
339
    *  @public function getXoopsCodeTopicGetVar
340
    *  @param $lpFieldName
341
    *  @param $rpFieldName
342
    *  @param $tableName
343
    *  @param $tableNameTopic
344
    *  @param $fieldNameParent
345
    *  @param $fieldNameTopic
346
    *  @return string
347
    */
348
    public function getXoopsCodeTopicGetVar($lpFieldName, $rpFieldName, $tableName, $tableNameTopic, $fieldNameParent, $fieldNameTopic)
349
    {
350
        $ret = <<<EOT
351
\t\t\t\t// Get Var {$fieldNameParent}
352
\t\t\t\t\${$rpFieldName} =& \${$tableNameTopic}Handler->get(\${$tableName}All[\$i]->getVar('{$fieldNameParent}'));
353
\t\t\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$rpFieldName}->getVar('{$fieldNameTopic}');\n
354
EOT;
355
356
        return $ret;
357
    }
358
359
    /*
360
    *  @public function getXoopsCodeParentTopicGetVar
361
    *  @param $moduleDirname
362
    *  @param $lpFieldName
363
    *  @param $rpFieldName
364
    *  @param $tableName
365
    *  @param $tableSoleNameTopic
366
    *  @param $tableNameTopic
367
    *  @param $fieldNameParent
368
    *  @return string
369
    */
370 View Code Duplication
    public function getXoopsCodeParentTopicGetVar($moduleDirname, $lpFieldName, $rpFieldName, $tableName, $tableSoleNameTopic, $tableNameTopic, $fieldNameParent)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
371
    {
372
        $ret = <<<EOT
373
\t\t\t\tif(!isset(\${$tableNameTopic}Handler)) {
374
\t\t\t\t\t// Get {$tableNameTopic} Handler
375
\t\t\t\t\t\${$tableNameTopic}Handler =& \${$moduleDirname}->getHandler('{$tableNameTopic}');
376
\t\t\t\t}
377
\t\t\t\t// Get Var {$fieldNameParent}
378
\t\t\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$tableNameTopic}Handler->get{$tableSoleNameTopic}FromId(\${$tableName}All[\$i]->getVar('{$fieldNameParent}'));\n
379
EOT;
380
381
        return $ret;
382
    }
383
384
    /*
385
    *  @public function getXoopsCodeUploadImageGetVar
386
    *  @param $lpFieldName
387
    *  @param $rpFieldName
388
    *  @param $tableName
389
    *  @param $fieldName
390
    *  @return string
391
    */
392
    public function getXoopsCodeUploadImageGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
393
    {
394
        $ret = <<<EOT
395
\t\t\t\t// Get Var {$fieldName}
396
\t\t\t\t\${$fieldName} = \${$tableName}All[\$i]->getVar('{$fieldName}');
397
\t\t\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$fieldName} ? \${$fieldName} : 'blank.gif';\n
398
EOT;
399
400
        return $ret;
401
    }
402
    /*
403
    *  @public function getXoopsCodeUrlFileGetVar
404
    *  @param $lpFieldName
405
    *  @param $rpFieldName
406
    *  @param $tableName
407
    *  @param $fieldName
408
    *  @return string
409
    */
410
    public function getXoopsCodeUrlFileGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
411
    {
412
        return $this->getXoopsCodeGetVarAll($lpFieldName, $rpFieldName, $tableName, $fieldName);
413
    }
414
    /*
415
    *  @public function getXoopsCodeTextAreaGetVar
416
    *  @param $lpFieldName
417
    *  @param $rpFieldName
418
    *  @param $tableName
419
    *  @param $fieldName
420
    *  @return string
421
    */
422
    public function getXoopsCodeTextAreaGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
423
    {
424
        return "\${$lpFieldName}['{$rpFieldName}'] = strip_tags(\${$tableName}All[\$i]->getVar('{$fieldName}'));\n";
425
    }
426
427
    /*
428
    *  @public function getXoopsCodeSelectUserGetVar
429
    *  @param $lpFieldName
430
    *  @param $rpFieldName
431
    *  @param $tableName
432
    *  @param $fieldName
433
    * @return string
434
    */
435
    public function getXoopsCodeSelectUserGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
436
    {
437
        return "\${$lpFieldName}['{$rpFieldName}'] = XoopsUser::getUnameFromId(\${$tableName}All[\$i]->getVar('{$fieldName}'), 's');\n";
438
    }
439
440
    /*
441
    *  @public function getXoopsCodeTextDateSelectGetVar
442
    *  @param $lpFieldName
443
    *  @param $rpFieldName
444
    *  @param $tableName
445
    *  @param $fieldName
446
    *  @return string
447
    */
448
    public function getXoopsCodeTextDateSelectGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
449
    {
450
        return "\${$lpFieldName}['{$rpFieldName}'] = formatTimeStamp(\${$tableName}All[\$i]->getVar('{$fieldName}'), 's');\n";
451
    }
452
453
    /*
454
    *  @public function getXoopsCodeUserHeader
455
    *  @param $moduleDirname
456
    *  @param $tableName
457
    *  @return string
458
    */
459
    public function getXoopsCodeXoopsOptionTemplateMain($moduleDirname, $tableName)
460
    {
461
        return "\$GLOBALS['xoopsOption']['template_main'] = '{$moduleDirname}_{$tableName}.tpl';\n";
462
    }
463
464
    /*
465
    *  @public function getXoopsCodeUserHeader
466
    *  @param $moduleDirname
467
    *  @param $tableName
468
    *  @return string
469
    */
470
    public function getXoopsCodeUserHeader($moduleDirname, $tableName)
471
    {
472
        $ret = $this->phpcode->getPhpCodeIncludeDir('__DIR__', 'header');
473
        $ret .= $this->getXoopsCodeXoopsOptionTemplateMain($moduleDirname, $tableName);
474
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'header', true);
475
476
        return $ret;
477
    }
478
479
    /*
480
    *  @public function getXoopsCodePermissionsHeader
481
    *  @param null
482
    */
483
    /**
484
     * @return string
485
     */
486
    public function getXoopsCodePermissionsHeader()
487
    {
488
        $ret = $this->phpcode->getPhpCodeCommentLine('Permission');
489
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/xoopsform/grouppermform', true);
490
        $ret .= $this->getXoopsCodeEqualsOperator('$gperm_handler', "xoops_gethandler('groupperm')", true);
491
        $groups = $this->getXoopsCodeEqualsOperator('$groups', '$xoopsUser->getGroups()');
492
        $elseGroups = $this->getXoopsCodeEqualsOperator('$groups', 'XOOPS_GROUP_ANONYMOUS');
493
        $ret .= $this->phpcode->getPhpCodeConditions('is_object($xoopsUser)', '', $type = '', $groups, $elseGroups);
494
495
        return $ret;
496
    }
497
498
    /**
499
     *  @public function getXoopsCodeGetFieldId
500
     *
501
     *  @param $fields
502
     *
503
     *  @return string
504
     */
505 View Code Duplication
    public function getXoopsCodeGetFieldId($fields)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
506
    {
507
        $fieldId = 'id';
508
        foreach (array_keys($fields) as $f) {
509
            $fieldName = $fields[$f]->getVar('field_name');
510
            if (0 == $f) {
511
                $fieldId = $fieldName;
512
            }
513
        }
514
515
        return $fieldId;
516
    }
517
518
    /**
519
     *  @public function getXoopsCodeGetFieldName
520
     *
521
     *  @param $fields
522
     *
523
     *  @return string
524
     */
525
    public function getXoopsCodeGetFieldName($fields)
526
    {
527
        foreach (array_keys($fields) as $f) {
528
            $fieldName = $fields[$f]->getVar('field_name');
529
        }
530
531
        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...
532
    }
533
534
    /**
535
     *  @public function getXoopsCodeGetFieldParentId
536
     *
537
     *  @param $fields
538
     *
539
     *  @return string
540
     */
541 View Code Duplication
    public function getXoopsCodeGetFieldParentId($fields)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
542
    {
543
        $fieldPid = 'pid';
544
        foreach (array_keys($fields) as $f) {
545
            $fieldName = $fields[$f]->getVar('field_name');
546
            if (1 == $fields[$f]->getVar('field_parent')) {
547
                $fieldPid = $fieldName;
548
            }
549
        }
550
551
        return $fieldPid;
552
    }
553
554
    /**
555
     *  @public function getXoopsCodeUserSaveElements
556
     *
557
     *  @param $moduleDirname
558
     *  @param $tableName
559
     *  @param $fields
560
     *
561
     *  @return string
562
     */
563 View Code Duplication
    public function getXoopsCodeUserSaveElements($moduleDirname, $tableName, $fields)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
564
    {
565
        $ret = '';
566
        foreach (array_keys($fields) as $f) {
567
            $fieldName = $fields[$f]->getVar('field_name');
568
            $fieldElement = $fields[$f]->getVar('field_element');
569
            if (1 == $fields[$f]->getVar('field_main')) {
570
                $fieldMain = $fieldName;
571
            }
572
            if ((5 == $fieldElement) || (6 == $fieldElement)) {
573
                $ret .= $this->getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName);
574
            } elseif (13 == $fieldElement) {
575
                $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...
576
            } elseif (14 == $fieldElement) {
577
                $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...
578
            } elseif (15 == $fieldElement) {
579
                $ret .= $this->getXoopsCodeTextDateSelectSetVar($tableName, $fieldName);
580
            } else {
581
                $ret .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
582
            }
583
        }
584
585
        return $ret;
586
    }
587
588
    /*
589
    *  @public function getXoopsCodeXoopsRequest
590
    *  @param $left
591
    *  @param $var1
592
    *  @param $var2
593
    *  @param $type
594
    *  @param $metod
595
    *  @return string
596
    */
597
    public function getXoopsCodeXoopsRequest($left = '', $var1 = '', $var2 = '', $type = 'String', $metod = false)
598
    {
599
        $ret = '';
600
        $intVars = ($var2 != '') ? "'{$var1}', {$var2}" : "'{$var1}'";
601
        if ($type == 'String') {
602
            $ret .= "\${$left} = XoopsRequest::getString('{$var1}', '{$var2}');\n";
603
        } elseif ($type == 'Int') {
604
            $ret .= "\${$left} = XoopsRequest::getInt({$intVars});\n";
605
        } elseif ($type == 'Int' && $metod !== false) {
606
            $ret .= "\${$left} = XoopsRequest::getInt({$intVars}, '{$metod}');\n";
607
        }
608
609
        return $ret;
610
    }
611
612
    /**
613
     *  @public function getXoopsCodeTplAssign
614
     *
615
     *  @param $tplString
616
     *  @param $phpRender
617
     *
618
     *  @return string
619
     */
620
    public function getXoopsCodeTplAssign($tplString, $phpRender)
621
    {
622
        return "\$GLOBALS['xoopsTpl']->assign('{$tplString}', {$phpRender});\n";
623
    }
624
625
    /**
626
     *  @public function getXoopsCodeXoopsTplAppend
627
     *
628
     *  @param $tplString
629
     *  @param $phpRender
630
     *
631
     *  @return string
632
     */
633
    public function getXoopsCodeXoopsTplAppend($tplString, $phpRender)
634
    {
635
        return "\$GLOBALS['xoopsTpl']->append('{$tplString}', {$phpRender});\n";
636
    }
637
638
    /**
639
     *  @public function getXoopsCodeXoopsTplAppendByRef
640
     *
641
     *  @param $tplString
642
     *  @param $phpRender
643
     *
644
     *  @return string
645
     */
646
    public function getXoopsCodeXoopsTplAppendByRef($tplString, $phpRender)
647
    {
648
        return "\$GLOBALS['xoopsTpl']->appendByRef('{$tplString}', {$phpRender});\n";
649
    }
650
651
    /**
652
     *  @public function getXoopsCodePath
653
     *
654
     *  @param $directory
655
     *  @param $filename
656
     *  @param $condition
657
     *
658
     *  @return string
659
     */
660
    public function getXoopsCodePath($directory, $filename, $condition = false)
661
    {
662
        if ($condition === false) {
663
            $ret = "\$GLOBALS['xoops']->path({$directory}.'/{$filename}.php');\n";
664
        } else {
665
            $ret = "\$GLOBALS['xoops']->path({$directory}.'/{$filename}.php')";
666
        }
667
668
        return $ret;
669
    }
670
671
    /**
672
     *  @public function getXoopsCodeTplDisplay
673
     *
674
     *  @param null
675
     *
676
     *  @return string
677
     */
678
    public function getXoopsCodeTplDisplay()
679
    {
680
        return "\$GLOBALS['xoopsTpl']->display(\"db:{\$templateMain}\");\n";
681
    }
682
683
    /**
684
     *  @public function getXoopsCodeGetInfo
685
     *
686
     *  @param $string
687
     *  @param $isParam
688
     *
689
     *  @return string
690
     */
691
    public function getXoopsCodeGetInfo($string, $isParam = false)
692
    {
693
        if ($isParam === false) {
694
            $ret = "\$GLOBALS['xoopsModule']->getInfo('{$string}');\n";
695
        } else {
696
            $ret = "\$GLOBALS['xoopsModule']->getInfo('{$string}')";
697
        }
698
699
        return $ret;
700
    }
701
702
    /**
703
     *  @public function getXoopsCodeObjHandlerCreate
704
     *
705
     *  @param $tableName
706
     *
707
     *  @return string
708
     */
709
    public function getXoopsCodeObjHandlerCreate($tableName)
710
    {
711
        return "\${$tableName}Obj =& \${$tableName}Handler->create();\n";
712
    }
713
714
    /**
715
     *  @public function getXoopsCodeObjHandlerCount
716
     *
717
     *  @param $tableName
718
     *
719
     *  @return string
720
     */
721
    public function getXoopsCodeObjHandlerCount($tableName)
722
    {
723
        $ucfTableName = ucfirst($tableName);
724
        $ret = "\${$tableName}Count = \${$tableName}Handler->getCount{$ucfTableName}();\n";
725
726
        return $ret;
727
    }
728
729
    /**
730
     *  @public function getXoopsCodeObjHandlerAll
731
     *
732
     *  @param $tableName
733
     *  @param $fieldMain
734
     *  @param $start
735
     *  @param $limit
736
     *
737
     *  @return string
738
     */
739
    public function getXoopsCodeObjHandlerAll($tableName, $fieldMain, $start = '0', $limit = '0')
740
    {
741
        $ucfTableName = ucfirst($tableName);
742
        $param = ($fieldMain != '') ? "{$start}, {$limit}, '{$fieldMain}'" : "{$start}, {$limit}";
743
        $ret = "\${$tableName}All = \${$tableName}Handler->getAll{$ucfTableName}({$param});\n";
744
745
        return $ret;
746
    }
747
	
748
	/**
749
     *  @public function getXoopsCodeGetValues
750
     *
751
     *  @param $tableName
752
	 *  @param $tableSoleName
753
     *
754
     *  @return string
755
     */
756
    public function getXoopsCodeGetValues($tableName, $tableSoleName)
757
    {
758
        $ucfTableName = ucfirst($tableName);
759
        $ret = "\${$tableSoleName} = \${$tableName}All[\$i]->getValues{$ucfTableName}();\n";
760
761
        return $ret;
762
    }
763
764
    /**
765
     *  @public function getXoopsCodeSetVarsObjects
766
     *
767
     *  @param $moduleDirname
768
     *  @param $tableName
769
     *  @param $fields
770
     *
771
     *  @return string
772
     */
773
    public function getXoopsCodeSetVarsObjects($moduleDirname, $tableName, $fields)
774
    {
775
        $ret = '';
776
        foreach (array_keys($fields) as $f) {
777
            $fieldName = $fields[$f]->getVar('field_name');
778
            $fieldElement = $fields[$f]->getVar('field_element');
779
            if (1 == $fields[$f]->getVar('field_main')) {
780
                $fieldMain = $fieldName;
781
            }
782
            if ($f > 0) { // If we want to hide field id
783
                switch ($fieldElement) {
784
                    case 5:
785
                    case 6:
786
                        $ret .= $this->getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName);
787
                        break;
788
                    case 11:
789
                        $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...
790
                        break;
791
                    case 12:
792
                        $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...
793
                        break;
794
                    case 13:
795
                        $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...
796
                        break;
797
                    case 14:
798
                        $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...
799
                        break;
800
                    case 15:
801
                        $ret .= $this->getXoopsCodeTextDateSelectSetVar($tableName, $fieldName);
802
                        break;
803
                    default:
804
                        $ret .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
805
                        break;
806
                }
807
            }
808
        }
809
810
        return $ret;
811
    }
812
813
    /**
814
     *  @public function getXoopsCodeSecurity
815
     *
816
     *  @param $tableName
817
     *
818
     *  @return string
819
     */
820
    public function getXoopsCodeSecurity($tableName)
821
    {
822
        $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...
823
        $implode = $this->phpcode->getPhpCodeImplode(',', $securityError);
824
        $content = $this->getXoopsCodeRedirectHeader($tableName, '', 3, $implode);
825
        $securityCheck = $this->getXoopsCodeSecurityCheck();
826
827
        return $this->phpcode->getPhpCodeConditions('!'.$securityCheck, '', '', $content);
828
    }
829
830
    /*
831
    *  @public function getXoopsCodeInsertData
832
    *  @param $tableName
833
    *  @param $language
834
    *  @return string
835
    */
836
    public function getXoopsCodeInsertData($tableName, $language)
837
    {
838
        $content = $this->getXoopsCodeRedirectHeader($tableName, '?op=list', 2, "{$language}FORM_OK");
839
        $handlerInsert = $this->getXoopsCodeHandler($tableName, $tableName, false, true, false, 'Obj');
840
841
        return $this->phpcode->getPhpCodeConditions($handlerInsert, '', '', $content);
842
    }
843
844
    /*
845
    *  @public function getXoopsCodeRedirectHeader
846
    *  @param $tableName
847
    *  @param $options
848
    *  @param $numb
849
    *  @param $var
850
    *  @return string
851
    */
852
    public function getXoopsCodeRedirectHeader($tableName, $options = '', $numb = '2', $var)
853
    {
854
        return "redirect_header('{$tableName}.php{$options}', {$numb}, {$var});\n";
855
    }
856
857
    /*
858
    *  @public function getXoopsCodeXoopsConfirm
859
    *  @param $tableName
860
    *  @param $language
861
    *  @param $fieldId
862
    *  @param $fieldMain    
863
    *  @param $options
864
    *
865
    *  @return string
866
    */
867
    public function getXoopsCodeXoopsConfirm($tableName, $language, $fieldId, $fieldMain, $options = 'delete')
868
    {
869
        $stuOptions = strtoupper($options);
870
		$ccFieldId = $this->tdmcfile->getCamelCase($fieldId, false, true);
871
        $ret = "xoops_confirm(array('ok' => 1, '{$fieldId}' => \${$ccFieldId}, 'op' => {$options}), \$_SERVER['REQUEST_URI'], sprintf({$language}FORM_SURE_{$stuOptions}, \${$tableName}Obj->getVar('{$fieldMain}')));\n";
872
873
        return $ret;
874
    }
875
876
    /*
877
    *  @public function getXoopsCodeSecurityCheck
878
    *  @param null
879
    *  @return boolean
880
    */
881
    public function getXoopsCodeSecurityCheck()
882
    {
883
        return "\$GLOBALS['xoopsSecurity']->check()";
884
    }
885
886
    /*
887
    *  @public function getXoopsCodeSecurityErrors
888
    *  @param null
889
    *  @return string
890
    */
891
    public function getXoopsCodeSecurityErrors()
892
    {
893
        return "\$GLOBALS['xoopsSecurity']->getErrors()";
894
    }
895
896
    /**
897
     *  @public function getXoopsCodeHtmlErrors
898
     *
899
     *  @param $tableName
900
     *  @param $isParam
901
     *  @param $obj
902
     *
903
     *  @return string
904
     */
905
    public function getXoopsCodeHtmlErrors($tableName, $isParam = false, $obj = 'Obj')
906
    {
907
        $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...
908
        if ($isParam) {
909
            $ret = "\${$tableName}{$obj}->getHtmlErrors()";
910
        } else {
911
            $ret = "\${$tableName}{$obj} =& \${$tableName}->getHtmlErrors();";
912
        }
913
914
        return $ret;
915
    }
916
917
    /**
918
     *  @public function getXoopsCodeObjHandlerCount
919
     *
920
     *  @param $left
921
     *  @param $tableName
922
     *  @param $obj
923
     *
924
     *  @return string
925
     */
926
    public function getXoopsCodeGetForm($left, $tableName, $obj = '')
927
    {
928
        $ucfTableName = ucfirst($tableName);
929
		
930
		return "\${$left} =& \${$tableName}{$obj}->getForm{$ucfTableName}();\n";
931
    }
932
933
    /**
934
     *  @public function getXoopsCodeGet
935
     *
936
     *  @param $tableName
937
     *  @param $var
938
     *  @param $obj
939
     *  @param $isHandler
940
     *  @param $isParam
941
     *
942
     *  @return string
943
     */
944 View Code Duplication
    public function getXoopsCodeGet($tableName, $var, $obj = '', $isHandler = false, $isParam = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
945
    {
946
        $handler = $isHandler === false ? '' : 'Handler';
947
		if ($isParam) {
948
            $ret = "\${$tableName}{$handler}->get(\${$var})";           
949
        } else {
950
            $ret = "\${$tableName}{$obj} =& \${$tableName}{$handler}->get(\${$var});\n";            
951
        }
952
953
        return $ret;
954
    }
955
956
    /**
957
     *  @public function getXoopsCodeHandler
958
     *
959
     *  @param $tableName
960
     *  @param $var
961
     *  @param $obj
962
	 *  @param $isHandler
963
     *
964
     *  @return string
965
     */
966 View Code Duplication
    public function getXoopsCodeInsert($tableName, $var, $obj = '', $isHandler = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
967
    {
968
        $handler = $isHandler === false ? '' : 'Handler';
969
		if ($obj != '') {
970
            $ret = "\${$tableName}{$handler}->insert(\${$var}{$obj})";
971
        } else {
972
            $ret = "\${$tableName}{$handler}->insert(\${$var})";
973
        }
974
975
        return $ret;
976
    }
977
978
    /**
979
     *  @public function getXoopsCodeDelete
980
     *
981
     *  @param $tableName
982
     *  @param $var
983
     *  @param $obj
984
     *  @param $isHandler
985
     *
986
     *  @return string
987
     */
988 View Code Duplication
    public function getXoopsCodeDelete($tableName, $var, $obj = '', $isHandler = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
989
    {
990
        $handler = $isHandler === false ? '' : 'Handler';
991
		if ($obj != '') {
992
			$ret = "\${$tableName}{$handler}->delete(\${$var}{$obj})";
993
		} else {
994
			$ret = "\${$tableName}{$handler}->delete(\${$var})";
995
		}
996
997
        return $ret;
998
    }
999
1000
    /**
1001
     *  @public function getXoopsCodeHandler
1002
     *
1003
     *  @param $tableName
1004
     *  @param $var
1005
     *
1006
     *  @return string
1007
     */
1008
    public function getXoopsCodeHandler($tableName, $var, $get = false, $insert = false, $delete = false, $obj = '')
1009
    {
1010
        if ($get) {
1011
            $ret = "\${$tableName}Handler->get(\${$var});";
1012
        } elseif ($insert && ($obj != '')) {
1013
            $ret = "\${$tableName}Handler->insert(\${$var}{$obj});";
1014
        } elseif ($delete && ($obj != '')) {
1015
            $ret = "\${$tableName}Handler->delete(\${$var}{$obj});";
1016
        }
1017
1018
        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...
1019
    }
1020
1021
    /*
1022
    *  @public function getXoopsCodeCaseDelete
1023
    *  @param $tableName
1024
    *  @param $language
1025
    *  @param $fieldId
1026
    *  @param $fieldMain
1027
    *  @return string
1028
    */
1029
    public function getXoopsCodeCaseDelete($language, $tableName, $fieldId, $fieldMain)
1030
    {
1031
        $ccFieldId = $this->tdmcfile->getCamelCase($fieldId, false, true);
1032
		$ret = $this->getXoopsCodeGet($tableName, $ccFieldId, 'Obj', true);
1033
1034
        $reqOk = "\$_REQUEST['ok']";
1035
        $isset = $this->phpcode->getPhpCodeIsset($reqOk);
1036
        $xoopsSecurityCheck = $this->getXoopsCodeSecurityCheck();
1037
        $xoopsSecurityErrors = $this->getXoopsCodeSecurityErrors();
1038
        $implode = $this->phpcode->getPhpCodeImplode(', ', $xoopsSecurityErrors);
1039
        $redirectHeaderErrors = $this->getXoopsCodeRedirectHeader($tableName, '', '3', $implode);
1040
1041
        $delete = $this->getXoopsCodeDelete($tableName, $tableName, 'Obj', true);
1042
        $condition = $this->phpcode->getPhpCodeConditions('!'.$xoopsSecurityCheck, '', '', $redirectHeaderErrors);
1043
1044
        $redirectHeaderLanguage = $this->getXoopsCodeRedirectHeader($tableName, '', '3', "{$language}FORM_DELETE_OK");
1045
        $htmlErrors = $this->getXoopsCodeHtmlErrors($tableName, true);
1046
        $internalElse = $this->getXoopsCodeTplAssign('error', $htmlErrors);
1047
        $condition .= $this->phpcode->getPhpCodeConditions($delete, '', '', $redirectHeaderLanguage, $internalElse);
1048
1049
        $mainElse = $this->getXoopsCodeXoopsConfirm($tableName, $language, $fieldId, $fieldMain);
1050
        $ret .= $this->phpcode->getPhpCodeConditions($isset, ' && ', "1 == {$reqOk}", $condition, $mainElse);
1051
1052
        return $ret;
1053
    }
1054
1055
    /*
1056
    *  @public function getTopicGetVar
1057
    *  @param $lpFieldName
1058
    *  @param $rpFieldName
1059
    *  @param $tableName
1060
    *  @param $tableNameTopic
1061
    *  @param $fieldNameParent
1062
    *  @param $fieldNameTopic
1063
    *  @return string
1064
    */
1065
    public function getTopicGetVar($lpFieldName, $rpFieldName, $tableName, $tableNameTopic, $fieldNameParent, $fieldNameTopic)
1066
    {
1067
        $ret = <<<EOT
1068
\t\t// Get Var {$fieldNameParent}
1069
\t\t\${$rpFieldName} =& \${$tableNameTopic}Handler->get(\${$tableName}All[\$i]->getVar('{$fieldNameParent}'));
1070
\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$rpFieldName}->getVar('{$fieldNameTopic}');\n
1071
EOT;
1072
1073
        return $ret;
1074
    }
1075
1076
    /*
1077
    *  @public function getUploadImageGetVar
1078
    *  @param $lpFieldName
1079
    *  @param $rpFieldName
1080
    *  @param $tableName
1081
    *  @param $fieldName
1082
    *  @return string
1083
    */
1084
    public function getUploadImageGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
1085
    {
1086
        $ret = <<<EOT
1087
\t\t// Get Var {$fieldName}
1088
\t\t\${$fieldName} = \${$tableName}All[\$i]->getVar('{$fieldName}');
1089
\t\t\$upload_image = \${$fieldName} ? \${$fieldName} : 'blank.gif';
1090
\t\t\${$lpFieldName}['{$rpFieldName}'] = \$upload_image;\n
1091
EOT;
1092
1093
        return $ret;
1094
    }
1095
1096
    /*
1097
    *  @public function getXoopsCodeUpdate
1098
    *  @param $language
1099
    *  @param $tableName
1100
    *  @param $fieldId
1101
    *  @param $fieldName
1102
    *  @return string
1103
    */
1104
    public function getXoopsCodeUpdate($language, $tableName, $fieldId, $fieldName)
1105
    {
1106
        $ccFieldId = $this->tdmcfile->getCamelCase($fieldId, false, true);
1107
		$get = $this->getXoopsCodeGet($tableName, $ccFieldId, 'Obj', true);
0 ignored issues
show
Unused Code introduced by
$get 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...
1108
		$isset = $this->phpcode->getPhpCodeIsset($ccFieldId);
1109
        $get = $this->getXoopsCodeHandler($tableName, $fieldId, true);
1110
        $ret = $this->phpcode->getPhpCodeConditions($isset, '', '', $get);
1111
        $ret .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
1112
        $handlerInsert = $this->$this->getXoopsCodeHandler($tableName, $tableName, false, true, false, 'Obj');
1113
        $redirect = $this->getXoopsCodeRedirectHeader($tableName, '?op=list', 2, "{$language}FORM_UPDATE_OK");
1114
        $ret .= $this->phpcode->getPhpCodeConditions($handlerInsert, '', '', $redirect);
1115
1116
        $ret .= $this->getXoopsCodeTplAssign('error', "\${$tableName}Obj->getHtmlErrors()");
1117
1118
        return $this->phpcode->getPhpCodeCaseSwitch('update', $ret);
1119
    }
1120
1121
    /**
1122
     *  @public function getXoopsCodeSaveFieldId
1123
     *
1124
     *  @param $fields
1125
     *
1126
     *  @return string
1127
     */
1128 View Code Duplication
    public function getXoopsCodeSaveFieldId($fields)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
1129
    {
1130
        foreach (array_keys($fields) as $f) {
1131
            if (0 == $f) {
1132
                $fieldId = $fields[$f]->getVar('field_name');
1133
            }
1134
        }
1135
1136
        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...
1137
    }
1138
1139
    /**
1140
     *  @public function getXoopsCodeSaveFieldMain
1141
     *
1142
     *  @param $fields
1143
     *
1144
     *  @return string
1145
     */
1146 View Code Duplication
    public function getXoopsCodeSaveFieldMain($fields)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
1147
    {
1148
        foreach (array_keys($fields) as $f) {
1149
            if (1 == $fields[$f]->getVar('field_main')) {
1150
                $fieldMain = $fields[$f]->getVar('field_name');
1151
            }
1152
        }
1153
1154
        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...
1155
    }
1156
1157
    /**
1158
     *  @public function getXoopsCodeSaveElements
1159
     *
1160
     *  @param $moduleDirname
1161
     *  @param $tableName
1162
     *  @param $fields
1163
     *
1164
     *  @return string
1165
     */
1166 View Code Duplication
    public function getXoopsCodeSaveElements($moduleDirname, $tableName, $fields)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
1167
    {
1168
        $ret = '';
1169
        foreach (array_keys($fields) as $f) {
1170
            $fieldName = $fields[$f]->getVar('field_name');
1171
            $fieldElement = $fields[$f]->getVar('field_element');
1172
            if (1 == $fields[$f]->getVar('field_main')) {
1173
                $fieldMain = $fieldName;
1174
            }
1175
            if ((5 == $fieldElement) || (6 == $fieldElement)) {
1176
                $ret .= $this->getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName);
1177
            } elseif (13 == $fieldElement) {
1178
                $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...
1179
            } elseif (14 == $fieldElement) {
1180
                $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...
1181
            } elseif (15 == $fieldElement) {
1182
                $ret .= $this->getXoopsCodeTextDateSelectSetVar($tableName, $fieldName);
1183
            } else {
1184
                $ret .= $this->getXoopsCodeSimpleSetVar($tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The method getXoopsCodeSimpleSetVar() 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...
1185
            }
1186
        }
1187
1188
        return $ret;
1189
    }
1190
	
1191
	/*
1192
    *  @public function getXoopsCodePageNav
1193
    *  @param $tableName
1194
	*
1195
    *  @return string
1196
    */
1197
    public function getXoopsCodePageNav($tableName)
1198
    {
1199
        $condition = $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/pagenav', true);
1200
        $condition .= "\$pagenav = new XoopsPageNav(\${$tableName}Count, \$limit, \$start, 'start', 'op=list&limit=' . \$limit);\n";
1201
		$condition .= $this->getXoopsCodeTplAssign('pagenav', "\$pagenav->renderNav(4)");
1202
		$ret = $this->phpcode->getPhpCodeConditions("\${$tableName}Count", ' > ', "\$limit", $condition, false, "\t\t");
1203
1204
        return $ret;
1205
    }
1206
}
1207