Completed
Pull Request — master (#48)
by Gino
03:19
created

TDMCreateXoopsCode::getXoopsCodeGetHtmlErrors()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 11
rs 9.4285
cc 2
eloc 7
nc 2
nop 3
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 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 $phpcode = null;
34
35
    /*
36
    *  @public function constructor
37
    *  @param null
38
    */
39
    /**
40
     *
41
     */
42
    public function __construct()
43
    {
44
        $this->phpcode = TDMCreatePhpCode::getInstance();
45
    }
46
47
    /*
48
    *  @static function &getInstance
49
    *  @param null
50
    */
51
    /**
52
     * @return TDMCreateXoopsCode
53
     */
54
    public static function &getInstance()
55
    {
56
        static $instance = false;
57
        if (!$instance) {
58
            $instance = new self();
59
        }
60
61
        return $instance;
62
    }
63
64
    /*
65
    *  @public function getXoopsCodeEqualsOperator
66
    *  @param string $left
67
    *  @param string $right
68
    *  @param boolean $ref
69
    *  @return string
70
    */
71
    public function getXoopsCodeEqualsOperator($left, $right, $ref = false)
72
    {
73
        if (false === $ref) {
74
            $ret = "{$left} = {$right};\n";
75
        } else {
76
            $ret = "{$left} =& {$right};\n";
77
        }
78
79
        return $ret;
80
    }
81
82
    /*
83
     *  @private function getXoopsCodeSwitch
84
     *  @param $op
85
     *  @param $listCases
86
     *  @param $defaultList
87
     *
88
     * @return string
89
     */
90
    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...
91
    {
92
        $switch = $this->phpcode->getPhpCodeCaseSwitch(array($listCases), $defaultList);
93
94
        return $this->phpcode->getPhpCodeSwitch($op, $switch);
95
    }
96
97
    /*
98
    *  @public function getXoopsCodeCPHeader
99
    *  @param null
100
    *  @return string
101
    */
102
    public function getXoopsCodeCPHeader()
103
    {
104
        return "xoops_cp_header();\n";
105
    }
106
107
    /*
108
    *  @public function getXoopsCodeCPFooter
109
    *  @param null
110
    *  @return string
111
    */
112
    public function getXoopsCodeCPFooter()
113
    {
114
        return "xoops_cp_footer();\n";
115
    }
116
117
    /**
118
     *  @public function getXoopsCodeLoad
119
     *
120
     *  @param $var
121
     *
122
     *  @return string
123
     */
124
    public function getXoopsCodeLoad($var = '')
125
    {
126
        return "xoops_load('{$var}');\n";
127
    }
128
129
    /**
130
     *  @public function getXoopsCodeLoadLanguage
131
     *
132
     *  @param $lang
133
     *
134
     *  @return string
135
     */
136
    public function getXoopsCodeLoadLanguage($lang)
137
    {
138
        return "xoops_loadLanguage('{$lang}');\n";
139
    }
140
141
    /*
142
    *  @public function getXoopsCodeSetVar
143
    *  @param string $tableName
144
    *  @param string $fieldName
145
    *  @param string $var
146
    *  @return string
147
    */
148
    public function getXoopsCodeSetVar($tableName, $fieldName, $var)
149
    {
150
        return "\${$tableName}Obj->setVar('{$fieldName}', {$var});\n";
151
    }
152
153
    /*
154
    *  @public function getXoopsCodeGetVar
155
    *  @param string $varLeft
156
    *  @param string $handle
157
    *  @param string $var
158
    *  @param string $isParam
159
    *
160
    *  @return string
161
    */
162
    public function getXoopsCodeGetVar($varLeft = '', $handle = '', $var = '', $isParam = false)
163
    {
164
        if ($isParam === false) {
165
            $ret = "\${$varLeft} = \${$handle}->getVar('{$var}');\n";
166
        } else {
167
            $ret = "\${$handle}->getVar('{$var}')";
168
        }
169
170
        return $ret;
171
    }
172
173
    /*
174
    *  @public function getXoopsCodeGroupPermForm
175
    *  @param string $varLeft
176
    *  @param string $formTitle
177
    *  @param string $moduleId
178
    *  @param string $permName
179
    *  @param string $permDesc
180
    *  @param string $filename
181
    *
182
    *  @return string
183
    */
184
    public function getXoopsCodeGroupPermForm($varLeft = '', $formTitle = '', $moduleId = '', $permName = '', $permDesc = '', $filename = '')
185
    {
186
        return "\${$varLeft} = new XoopsGroupPermForm({$formTitle}, {$moduleId}, {$permName}, {$permDesc}, {$filename});\n";
187
    }
188
189
    /*
190
    *  @public function getXoopsCodeAddItem
191
    *  @param string $varLeft
192
    *  @param string $paramLeft
193
    *  @param string $paramRight
194
    *
195
    *  @return string
196
    */
197
    public function getXoopsCodeAddItem($varLeft = '', $paramLeft = '', $paramRight = '')
198
    {
199
        return "\${$varLeft}->addItem({$paramLeft}, {$paramRight});\n";
200
    }
201
202
    /*
203
    *  @public function getXoopsCodeTextDateSelectSetVar
204
    *  @param string $tableName
205
    *  @param string $fieldName
206
    *  @return string
207
    */
208
    public function getXoopsCodeTextDateSelectSetVar($tableName, $fieldName)
209
    {
210
        return $this->getXoopsCodeSetVar($tableName, $fieldName, "strtotime(\$_POST['{$fieldName}'])");
211
    }
212
213
    /*
214
    *  @public function getXoopsCodeCheckBoxOrRadioYNSetVar
215
    *  @param $tableName
216
    *  @param $fieldName
217
    *  @return string
218
    */
219
    public function getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName)
220
    {
221
        return $this->getXoopsCodeSetVar($tableName, $fieldName, "((1 == \$_REQUEST['{$fieldName}']) ? '1' : '0')");
222
    }
223
	
224
	/*
225
    *  @public function getXoopsCodeXoopsMediaUploader
226
    *  @param $var
227
    *  @param $dirPath
228
    *  @param $tableName
229
    *  @param $moduleDirname
230
    *  @return string
231
    */
232
    public function getXoopsCodeXoopsMediaUploader($var = '', $dirPath, $tableName, $moduleDirname)
233
    {
234
        $mimetypes = $this->getXoopsCodeGetConfig($moduleDirname, 'mimetypes');
235
		$maxsize = $this->getXoopsCodeGetConfig($moduleDirname, 'maxsize');
236
		
237
		return "\${$var} = new XoopsMediaUploader({$dirPath} . '/{$tableName}', {$mimetypes}, {$maxsize}, null, null);\n";
238
    }
239
240
    /*
241
    *  @public function getXoopsCodeGetConfig
242
    *  @param $moduleDirname
243
    *  @param $name
244
    *  @return string
245
    */
246
    public function getXoopsCodeGetConfig($moduleDirname, $name)
247
    {
248
        return "\${$moduleDirname}->getConfig('{$name}')";
249
    }
250
251
    /*
252
    *  @public function getXoopsCodeIdGetVar
253
    *  @param string $lpFieldName
254
    *  @return string
255
    */
256
    public function getXoopsCodeIdGetVar($lpFieldName)
257
    {
258
        return "\${$lpFieldName}['id'] = \$i;\n";
259
    }
260
261
    /*
262
    *  @public function getXoopsCodeGetVarAll
263
    *  @param string $lpFieldName
264
    *  @param string $rpFieldName
265
    *  @param string $tableName
266
    *  @param string $fieldName
267
    *  @return string
268
    */
269
    public function getXoopsCodeGetVarAll($lpFieldName, $rpFieldName, $tableName, $fieldName)
270
    {
271
        return "\${$lpFieldName}['{$rpFieldName}'] = \${$tableName}All[\$i]->getVar('{$fieldName}');\n";
272
    }
273
274
    /*
275
    *  @public function getXoopsHandlerLine
276
    *  @param $moduleDirname
277
    *  @param $tableName
278
    *  @return string
279
    */
280
    public function getXoopsHandlerLine($moduleDirname, $tableName)
281
    {
282
        return "\${$tableName}Handler =& \${$moduleDirname}->getHandler('{$tableName}');\n";
283
    }
284
285
    /*
286
    *  @public function getXoopsSimpleForm
287
    *  @param $left
288
    *  @param $element
289
    *  @param $elementsContent
290
    *  @param $caption
291
    *  @param $var
292
    *  @param $filename
293
    *  @param $type
294
    *  
295
    *  @return string
296
    */
297
    public function getXoopsSimpleForm($left = '', $element = '', $elementsContent = '', $caption = '', $var = '', $filename = '', $type = 'post')
298
    {
299
        $ret = "\${$left} = new XoopsSimpleForm({$caption}, '{$var}', '{$filename}.php', '{$type}');\n";
300
        if (!empty($elementsContent)) {
301
            $ret .= "{$elementsContent}";
302
        }
303
        $ret .= "\${$left}->addElement(\${$element});\n";
304
        $ret .= "\${$left}->display();\n";
305
306
        return $ret;
307
    }
308
309
    /*
310
    *  @public function getXoopsFormSelect
311
    *  @param $varSelect
312
    *  @param $caption
313
    *  @param $var
314
    *  @param $options
315
    *  @param $setExtra
316
    *  
317
    *  @return string
318
    */
319
    public function getXoopsFormSelect($varSelect = '', $caption = '', $var = '', $options = array(), $setExtra = true)
320
    {
321
        $ret = "\${$varSelect} = new XoopsFormSelect({$caption}, '{$var}', \${$var});\n";
322
        if (false !== $setExtra) {
323
            $ret .= "\${$varSelect}->setExtra('{$setExtra}');\n";
324
        }
325
        foreach ($options as $key => $value) {
326
            $ret .= "\${$varSelect}->addOption('{$key}', {$value});\n";
327
        }
328
329
        return $ret;
330
    }
331
332
    /*
333
    *  @public function getXoopsCodeTopicGetVar
334
    *  @param string $lpFieldName
335
    *  @param string $rpFieldName
336
    *  @param string $tableName
337
    *  @param string $tableNameTopic
338
    *  @param string $fieldNameParent
339
    *  @param string $fieldNameTopic
340
    *  @return string
341
    */
342
    public function getXoopsCodeTopicGetVar($lpFieldName, $rpFieldName, $tableName, $tableNameTopic, $fieldNameParent, $fieldNameTopic)
343
    {
344
        $ret = <<<EOT
345
\t\t\t\t// Get Var {$fieldNameParent}
346
\t\t\t\t\${$rpFieldName} =& \${$tableNameTopic}Handler->get(\${$tableName}All[\$i]->getVar('{$fieldNameParent}'));
347
\t\t\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$rpFieldName}->getVar('{$fieldNameTopic}');\n
348
EOT;
349
350
        return $ret;
351
    }
352
353
    /*
354
    *  @public function getXoopsCodeParentTopicGetVar
355
    *  @param string $moduleDirname
356
    *  @param string $lpFieldName
357
    *  @param string $rpFieldName
358
    *  @param string $tableName
359
    *  @param string $tableSoleNameTopic
360
    *  @param string $tableNameTopic
361
    *  @param string $fieldNameParent
362
    *  @return string
363
    */
364 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...
365
    {
366
        $ret = <<<EOT
367
\t\t\t\tif(!isset(\${$tableNameTopic}Handler)) {
368
\t\t\t\t\t// Get {$tableNameTopic} Handler
369
\t\t\t\t\t\${$tableNameTopic}Handler =& \${$moduleDirname}->getHandler('{$tableNameTopic}');
370
\t\t\t\t}
371
\t\t\t\t// Get Var {$fieldNameParent}
372
\t\t\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$tableNameTopic}Handler->get{$tableSoleNameTopic}FromId(\${$tableName}All[\$i]->getVar('{$fieldNameParent}'));\n
373
EOT;
374
375
        return $ret;
376
    }
377
378
    /*
379
    *  @public function getXoopsCodeUploadImageGetVar
380
    *  @param string $lpFieldName
381
    *  @param string $rpFieldName
382
    *  @param string $tableName
383
    *  @param string $fieldName
384
    *  @return string
385
    */
386
    public function getXoopsCodeUploadImageGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
387
    {
388
        $ret = <<<EOT
389
\t\t\t\t// Get Var {$fieldName}
390
\t\t\t\t\${$fieldName} = \${$tableName}All[\$i]->getVar('{$fieldName}');
391
\t\t\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$fieldName} ? \${$fieldName} : 'blank.gif';\n
392
EOT;
393
394
        return $ret;
395
    }
396
    /*
397
    *  @public function getXoopsCodeUrlFileGetVar
398
    *  @param string $lpFieldName
399
    *  @param string $rpFieldName
400
    *  @param string $tableName
401
    *  @param string $fieldName
402
    *  @return string
403
    */
404
    public function getXoopsCodeUrlFileGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
405
    {
406
        return $this->getXoopsCodeGetVarAll($lpFieldName, $rpFieldName, $tableName, $fieldName);
407
    }
408
    /*
409
    *  @public function getXoopsCodeTextAreaGetVar
410
    *  @param string $lpFieldName
411
    *  @param string $rpFieldName
412
    *  @param string $tableName
413
    *  @param string $fieldName
414
    *  @return string
415
    */
416
    public function getXoopsCodeTextAreaGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
417
    {
418
        return "\${$lpFieldName}['{$rpFieldName}'] = strip_tags(\${$tableName}All[\$i]->getVar('{$fieldName}'));\n";
419
    }
420
421
    /*
422
    *  @public function getXoopsCodeSelectUserGetVar
423
    *  @param string $lpFieldName
424
    *  @param string $rpFieldName
425
    *  @param string $tableName
426
    *  @param string $fieldName
427
    * @return string
428
    */
429
    public function getXoopsCodeSelectUserGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
430
    {
431
        return "\${$lpFieldName}['{$rpFieldName}'] = XoopsUser::getUnameFromId(\${$tableName}All[\$i]->getVar('{$fieldName}'), 's');\n";
432
    }
433
434
    /*
435
    *  @public function getXoopsCodeTextDateSelectGetVar
436
    *  @param string $lpFieldName
437
    *  @param string $rpFieldName
438
    *  @param string $tableName
439
    *  @param string $fieldName
440
    *  @return string
441
    */
442
    public function getXoopsCodeTextDateSelectGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
443
    {
444
        return "\${$lpFieldName}['{$rpFieldName}'] = formatTimeStamp(\${$tableName}All[\$i]->getVar('{$fieldName}'), 's');\n";
445
    }
446
447
    /*
448
    *  @public function getXoopsCodeUserHeader
449
    *  @param string $moduleDirname
450
    *  @param string $tableName
451
    *  @return string
452
    */
453
    public function getXoopsCodeXoopsOptionTemplateMain($moduleDirname, $tableName)
454
    {
455
        return "\$GLOBALS['xoopsOption']['template_main'] = '{$moduleDirname}_{$tableName}.tpl';\n";
456
    }
457
458
    /*
459
    *  @public function getXoopsCodeUserHeader
460
    *  @param string $moduleDirname
461
    *  @param string $tableName
462
    *  @return string
463
    */
464
    public function getXoopsCodeUserHeader($moduleDirname, $tableName)
465
    {
466
        $ret = $this->phpcode->getPhpCodeIncludeDir('__DIR__', 'header');
467
        $ret .= $this->getXoopsCodeXoopsOptionTemplateMain($moduleDirname, $tableName);
468
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'header', true);
469
470
        return $ret;
471
    }
472
473
    /*
474
    *  @public function getXoopsCodePermissionsHeader
475
    *  @param null
476
    */
477
    /**
478
     * @return string
479
     */
480
    public function getXoopsCodePermissionsHeader()
481
    {
482
        $ret = $this->phpcode->getPhpCodeCommentLine('Permission');
483
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/xoopsform/grouppermform', true);
484
        $ret .= $this->getXoopsCodeEqualsOperator('$gperm_handler', "xoops_gethandler('groupperm')", true);
485
        $groups = $this->getXoopsCodeEqualsOperator('$groups', '$xoopsUser->getGroups()');
486
        $elseGroups = $this->getXoopsCodeEqualsOperator('$groups', 'XOOPS_GROUP_ANONYMOUS');
487
        $ret .= $this->phpcode->getPhpCodeConditions('is_object($xoopsUser)', '', $type = '', $groups, $elseGroups);
488
489
        return $ret;
490
    }
491
492
    /**
493
     *  @public function getXoopsCodeGetFieldId
494
     *
495
     *  @param $fields
496
     *
497
     *  @return string
498
     */
499 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...
500
    {
501
        $fieldId = 'id';
502
        foreach (array_keys($fields) as $f) {
503
            $fieldName = $fields[$f]->getVar('field_name');
504
            if (0 == $f) {
505
                $fieldId = $fieldName;
506
            }
507
        }
508
509
        return $fieldId;
510
    }
511
512
    /**
513
     *  @public function getXoopsCodeGetFieldName
514
     *
515
     *  @param $fields
516
     *
517
     *  @return string
518
     */
519
    public function getXoopsCodeGetFieldName($fields)
520
    {
521
        foreach (array_keys($fields) as $f) {
522
            $fieldName = $fields[$f]->getVar('field_name');
523
        }
524
525
        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...
526
    }
527
528
    /**
529
     *  @public function getXoopsCodeGetFieldParentId
530
     *
531
     *  @param $fields
532
     *
533
     *  @return string
534
     */
535 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...
536
    {
537
        $fieldPid = 'pid';
538
        foreach (array_keys($fields) as $f) {
539
            $fieldName = $fields[$f]->getVar('field_name');
540
            if (1 == $fields[$f]->getVar('field_parent')) {
541
                $fieldPid = $fieldName;
542
            }
543
        }
544
545
        return $fieldPid;
546
    }
547
548
    /**
549
     *  @public function getXoopsCodeUserSaveElements
550
     *
551
     *  @param $moduleDirname
552
     *  @param $tableName
553
     *  @param $fields
554
     *
555
     *  @return string
556
     */
557 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...
558
    {
559
        $ret = '';
560
        foreach (array_keys($fields) as $f) {
561
            $fieldName = $fields[$f]->getVar('field_name');
562
            $fieldElement = $fields[$f]->getVar('field_element');
563
            if (1 == $fields[$f]->getVar('field_main')) {
564
                $fieldMain = $fieldName;
565
            }
566
            if ((5 == $fieldElement) || (6 == $fieldElement)) {
567
                $ret .= $this->getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName);
568
            } elseif (13 == $fieldElement) {
569
                $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...
570
            } elseif (14 == $fieldElement) {
571
                $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...
572
            } elseif (15 == $fieldElement) {
573
                $ret .= $this->getXoopsCodeTextDateSelectSetVar($tableName, $fieldName);
574
            } else {
575
                $ret .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
576
            }
577
        }
578
579
        return $ret;
580
    }
581
582
    /*
583
    *  @public function getXoopsCodeXoopsRequest
584
    *  @param $left
585
    *  @param $var1
586
    *  @param $var2
587
    *  @param $type
588
    *  @param $metod
589
    *  @return string
590
    */
591
    public function getXoopsCodeXoopsRequest($left = '', $var1 = '', $var2 = '', $type = 'String', $metod = false)
592
    {
593
        $ret = '';
594
		$intVars = ($var2 != '') ? "'{$var1}', {$var2}" : "'{$var1}'";
595
		if ($type == 'String') {
596
            $ret .= "\${$left} = XoopsRequest::getString('{$var1}', '{$var2}');\n";
597
        } elseif ($type == 'Int') {            
598
			$ret .= "\${$left} = XoopsRequest::getInt({$intVars});\n";
599
        } elseif ($type == 'Int' && $metod !== false) {
600
            $ret .= "\${$left} = XoopsRequest::getInt({$intVars}, '{$metod}');\n";
601
        }
602
603
        return $ret;
604
    }
605
606
    /**
607
     *  @public function getXoopsCodeTplAssign
608
     *
609
     *  @param string $tplString
610
     *  @param string $phpRender
611
     *
612
     *  @return string
613
     */
614
    public function getXoopsCodeTplAssign($tplString, $phpRender)
615
    {
616
        return "\$GLOBALS['xoopsTpl']->assign('{$tplString}', {$phpRender});\n";
617
    }
618
619
    /**
620
     *  @public function getXoopsCodeXoopsTplAppend
621
     *
622
     *  @param string $tplString
623
     *  @param string $phpRender
624
     *
625
     *  @return string
626
     */
627
    public function getXoopsCodeXoopsTplAppend($tplString, $phpRender)
628
    {
629
        return "\$GLOBALS['xoopsTpl']->append('{$tplString}', {$phpRender});\n";
630
    }
631
632
    /**
633
     *  @public function getXoopsCodeXoopsTplAppendByRef
634
     *
635
     *  @param string $tplString
636
     *  @param string $phpRender
637
     *
638
     *  @return string
639
     */
640
    public function getXoopsCodeXoopsTplAppendByRef($tplString, $phpRender)
641
    {
642
        return "\$GLOBALS['xoopsTpl']->appendByRef('{$tplString}', {$phpRender});\n";
643
    }
644
645
    /**
646
     *  @public function getXoopsCodePath
647
     *
648
     *  @param $directory
649
     *  @param $filename
650
     *  @param $condition
651
     *
652
     *  @return string
653
     */
654
    public function getXoopsCodePath($directory, $filename, $condition = false)
655
    {
656
        if ($condition === false) {
657
            $ret = "\$GLOBALS['xoops']->path({$directory}.'/{$filename}.php');\n";
658
        } else {
659
            $ret = "\$GLOBALS['xoops']->path({$directory}.'/{$filename}.php')";
660
        }
661
662
        return $ret;
663
    }
664
665
    /**
666
     *  @public function getXoopsCodeTplDisplay
667
     *
668
     *  @param null
669
     *
670
     *  @return string
671
     */
672
    public function getXoopsCodeTplDisplay()
673
    {
674
        return "\$GLOBALS['xoopsTpl']->display(\"db:{\$templateMain}\");\n";
675
    }
676
677
    /**
678
     *  @public function getXoopsCodeGetInfo
679
     *
680
     *  @param $string
681
     *  @param $isParam
682
     *
683
     *  @return string
684
     */
685
    public function getXoopsCodeGetInfo($string, $isParam = false)
686
    {
687
        if ($isParam === false) {
688
            $ret = "\$GLOBALS['xoopsModule']->getInfo('{$string}');\n";
689
        } else {
690
            $ret = "\$GLOBALS['xoopsModule']->getInfo('{$string}')";
691
        }
692
693
        return $ret;
694
    }
695
696
    /**
697
     *  @public function getXoopsCodeObjHandlerCreate
698
     *
699
     *  @param string $tableName
700
     *
701
     *  @return string
702
     */
703
    public function getXoopsCodeObjHandlerCreate($tableName)
704
    {
705
        $ret = "\${$tableName}Obj =& \${$tableName}Handler->create();\n";
706
707
        return $ret;
708
    }
709
710
    /**
711
     *  @public function getXoopsCodeObjHandlerCount
712
     *
713
     *  @param string $tableName
714
     *
715
     *  @return string
716
     */
717
    public function getXoopsCodeObjHandlerCount($tableName)
718
    {
719
        $ucfTableName = ucfirst($tableName);
720
        $ret = "\${$tableName}Count = \${$tableName}Handler->getCount{$ucfTableName}();\n";
721
722
        return $ret;
723
    }
724
725
    /**
726
     *  @public function getXoopsCodeObjHandlerAll
727
     *
728
     *  @param string $tableName
729
     *  @param string $fieldMain
730
	 *  @param string $start
731
	 *  @param string $limit
732
     *
733
     *  @return string
734
     */
735
    public function getXoopsCodeObjHandlerAll($tableName, $fieldMain, $start = '0', $limit = '0')
736
    {
737
        $ucfTableName = ucfirst($tableName);
738
		$param = ($fieldMain != '') ? "{$start}, {$limit}, '{$fieldMain}'" : "{$start}, {$limit}";
739
        $ret = "\${$tableName}All = \${$tableName}Handler->getAll{$ucfTableName}({$param});\n";
740
741
        return $ret;
742
    }
743
744
    /**
745
     *  @public function getXoopsCodeSetVarsObjects
746
     *
747
     *  @param $moduleDirname
748
     *  @param $tableName
749
     *  @param $fields
750
     *
751
     *  @return string
752
     */
753
    public function getXoopsCodeSetVarsObjects($moduleDirname, $tableName, $fields)
754
    {
755
        $ret = '';
756
        foreach (array_keys($fields) as $f) {
757
            $fieldName = $fields[$f]->getVar('field_name');
758
            $fieldElement = $fields[$f]->getVar('field_element');
759
            if (1 == $fields[$f]->getVar('field_main')) {
760
                $fieldMain = $fieldName;
761
            }
762
            if ($f > 0) { // If we want to hide field id
763
                switch ($fieldElement) {
764
                    case 5:
765
                    case 6:
766
                        $ret .= $this->getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName);
767
                        break;
768
                    case 11:
769
                        $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...
770
                        break;
771
                    case 12:
772
                        $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...
773
                        break;
774
                    case 13:
775
                        $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...
776
                        break;
777
                    case 14:
778
                        $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...
779
                        break;
780
                    case 15:
781
                        $ret .= $this->getXoopsCodeTextDateSelectSetVar($tableName, $fieldName);
782
                        break;
783
                    default:
784
                        $ret .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
785
                        break;
786
                }
787
            }
788
        }
789
790
        return $ret;
791
    }	
792
	
793
    /**
794
     *  @public function getXoopsCodeSecurity
795
     *
796
     *  @param $tableName
797
     *
798
     *  @return string
799
     */
800
    public function getXoopsCodeSecurity($tableName)
801
    {
802
        $securityError = $this->getXoopsCodeSecurityGetError();
803
        $implode = $this->phpcode->getPhpCodeImplode(',', $securityError);
804
        $content = $this->getXoopsCodeRedirectHeader($tableName, '', 3, $implode);
805
        $securityCheck = $this->getXoopsCodeSecurityCheck();
806
807
        return $this->phpcode->getPhpCodeConditions('!'.$securityCheck, '', '', $content);
808
    }
809
810
    /*
811
    *  @public function getXoopsCodeInsertData
812
    *  @param $tableName
813
    *  @param $language
814
    *  @return string
815
    */
816
    public function getXoopsCodeInsertData($tableName, $language)
817
    {
818
        $content = $this->getXoopsCodeRedirectHeader($tableName, '?op=list', 2, "{$language}FORM_OK");
819
        $handlerInsert = $this->getXoopsCodeHandler($tableName, $tableName, false, true, false, 'Obj');
820
821
        return $this->phpcode->getPhpCodeConditions($handlerInsert, '', '', $content);
822
    }
823
824
    /*
825
    *  @public function getXoopsCodeRedirectHeader
826
    *  @param $tableName
827
    *  @param $options
828
    *  @param $numb
829
    *  @param $var
830
    *  @return string
831
    */
832
    public function getXoopsCodeRedirectHeader($tableName, $options = '', $numb = '2', $var)
833
    {
834
        return "redirect_header('{$tableName}.php{$options}', {$numb}, {$var});\n";
835
    }
836
837
    /*
838
    *  @public function getXoopsCodeXoopsConfirm
839
    *  @param $tableName
840
    *  @param $language
841
    *  @param $fieldId
842
    *  @param $fieldMain    
843
	*  @param $options
844
    *
845
    *  @return string
846
    */
847
    public function getXoopsCodeXoopsConfirm($tableName, $language, $fieldId, $fieldMain, $options = 'delete')
848
    {
849
        $stuOptions = strtoupper($options);
850
        $ret = "xoops_confirm(array('ok' => 1, '{$fieldId}' => \${$fieldId}, 'op' => {$options}), \$_SERVER['REQUEST_URI'], sprintf({$language}FORM_SURE_{$stuOptions}, \${$tableName}Obj->getVar('{$fieldMain}')));\n";
851
852
        return $ret;
853
    }
854
855
    /*
856
    *  @public function getXoopsCodeSecurityCheck
857
    *  @param null
858
    *  @return boolean
859
    */
860
    public function getXoopsCodeSecurityCheck()
861
    {
862
        return "\$GLOBALS['xoopsSecurity']->check()";
863
    }
864
865
    /*
866
    *  @public function getXoopsCodeSecurityGetError
867
    *  @param null
868
    *  @return string
869
    */
870
    public function getXoopsCodeSecurityGetError()
871
    {
872
        return "\$GLOBALS['xoopsSecurity']->getErrors()";
873
    }
874
	
875
	/**
876
     *  @public function getXoopsCodeGetHtmlErrors
877
     *
878
     *  @param $tableName
879
	 *  @param $isParam
880
	 *  @param $obj
881
     *
882
     *  @return string
883
     */
884
    public function getXoopsCodeGetHtmlErrors($tableName, $isParam = false, $obj = 'Obj')
885
    {
886
        $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...
887
		if ($isParam) {            
888
			$ret = "\${$tableName}{$obj}->getHtmlErrors()";
889
		} else {
890
			$ret = "\${$tableName}{$obj} =& \${$tableName}->getHtmlErrors();";
891
		} 
892
893
        return $ret;		
894
    }
895
	
896
	/**
897
     *  @public function getXoopsCodeObjHandlerCount
898
     *
899
     *  @param $left
900
	 *  @param $tableName
901
	 *  @param $obj
902
     *
903
     *  @return string
904
     */
905
    public function getXoopsCodeGetForm($left, $tableName, $obj = '')
906
    {
907
        return "\${$left} =& \${$tableName}{$obj}->getForm();\n";
908
    }    
909
    
910
    /**
911
     *  @public function getXoopsCodeGet
912
     *
913
     *  @param string $tableName
914
     *  @param string $var
915
	 *  @param string $obj
916
	 *  @param string $isHandler
917
     *  @param string $isParam
918
     *
919
     *  @return string
920
     */
921
    public function getXoopsCodeGet($tableName, $var, $obj = '', $isHandler = false, $isParam = false)
922
    {
923
        if ($isParam) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $isParam of type false|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
924
            if ($isHandler) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $isHandler of type false|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
925
				$ret = "\${$tableName}Handler->get(\${$var});";
926
			} else {
927
				$ret = "\${$tableName}->get(\${$var});";
928
			}
929
		} else {
930
            if ($isHandler) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $isHandler of type false|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
931
				$ret = "\${$tableName}{$obj} =& \${$tableName}Handler->get(\${$var});";
932
			} else {
933
				$ret = "\${$tableName}{$obj} =& \${$tableName}->get(\${$var});";
934
			}
935
		} 
936
937
        return $ret;
938
    }
939
	
940
	/**
941
     *  @public function getXoopsCodeHandler
942
     *
943
     *  @param string $tableName
944
     *  @param string $var
945
	 *  @param string $obj
946
     *
947
     *  @return string
948
     */
949
    public function getXoopsCodeInsert($tableName, $var, $obj = '')
950
    {
951 View Code Duplication
        if ($obj != '') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
952
            $ret = "\${$tableName}Handler->insert(\${$var}{$obj});";
953
        } else {
954
            $ret = "\${$tableName}Handler->insert(\${$var});";
955
        }
956
957
        return $ret;
958
    }
959
	
960
	/**
961
     *  @public function getXoopsCodeDelete
962
     *
963
     *  @param string $tableName
964
     *  @param string $var
965
	 *  @param string $obj
966
	 *  @param string $isHandler
967
     *
968
     *  @return string
969
     */
970
    public function getXoopsCodeDelete($tableName, $var, $obj = '', $isHandler = false)
971
    {
972
        if ($isHandler) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $isHandler of type false|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
973 View Code Duplication
			if ($obj != '') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
974
				$ret = "\${$tableName}Handler->delete(\${$var}{$obj});";
975
			} else {
976
				$ret = "\${$tableName}Handler->delete(\${$var});";
977
			}
978 View Code Duplication
		} else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
979
			if ($obj != '') {
980
				$ret = "\${$tableName}->delete(\${$var}{$obj});";
981
			} else {
982
				$ret = "\${$tableName}->delete(\${$var});";
983
			}
984
		}
985
        return $ret;
986
    }
987
	
988
	/**
989
     *  @public function getXoopsCodeHandler
990
     *
991
     *  @param string $tableName
992
     *  @param string $var
993
     *
994
     *  @return string
995
     */
996
    public function getXoopsCodeHandler($tableName, $var, $get = false, $insert = false, $delete = false, $obj = '')
997
    {
998
        if ($get) {
999
            $ret = "\${$tableName}Handler->get(\${$var});";
1000
        } elseif ($insert && ($obj != '')) {
1001
            $ret = "\${$tableName}Handler->insert(\${$var}{$obj});";
1002
        } elseif ($delete && ($obj != '')) {
1003
            $ret = "\${$tableName}Handler->delete(\${$var}{$obj});";
1004
        }
1005
1006
        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...
1007
    }
1008
1009
    /*
1010
    *  @public function getXoopsCodeCaseDelete
1011
    *  @param string $tableName
1012
    *  @param string $language
1013
    *  @param string $fieldId
1014
    *  @param string $fieldMain
1015
    *  @return string
1016
    */
1017
    public function getXoopsCodeCaseDelete($language, $tableName, $fieldId, $fieldMain)
1018
    {
1019
        $ret = $this->getXoopsCodeGet($tableName, $fieldId, 'Obj', true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a false|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...
1020
		        
1021
		$reqOk = "\$_REQUEST['ok']";
1022
		$isset = $this->phpcode->getPhpCodeIsset($reqOk);
1023
		$xoopsSecurityCheck = $this->getXoopsCodeSecurityCheck();
1024
        $xoopsSecurityErrors = $this->getXoopsCodeSecurityErrors();
0 ignored issues
show
Bug introduced by
The method getXoopsCodeSecurityErrors() 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...
1025
		$implode = $this->phpcode->getPhpCodeImplode(', ', $xoopsSecurityErrors);
1026
		$redirectHeaderErrors = $this->getXoopsCodeRedirectHeader($tableName, '', '3', $implode);
1027
		
1028
		$delete = $this->getXoopsCodeDelete($tableName, $tableName, 'Obj', true);		
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a false|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...
1029
        $condition = $this->phpcode->getPhpCodeConditions('!'.$xoopsSecurityCheck, '', '', $redirectHeaderErrors);
1030
        
1031
		$redirectHeaderLanguage = $this->getXoopsCodeRedirectHeader($tableName, '', '3', "{$language}FORM_DELETE_OK");
1032
		$htmlErrors = $this->getXoopsCodeGetHtmlErrors($tableName, true);
1033
		$internalElse = $this->getXoopsCodeTplAssign('error', $htmlErrors);
1034
		$condition .= $this->phpcode->getPhpCodeConditions($delete, '', '', $redirectHeaderLanguage, $internalElse);        
1035
1036
		$mainElse = $this->getXoopsCodeXoopsConfirm($tableName, $language, $fieldId, $fieldMain);
1037
		$ret .= $this->phpcode->getPhpCodeConditions($isset, ' && ', "1 == {$reqOk}", $condition, $mainElse);
1038
1039
        return $ret;
1040
    }
1041
	
1042
	/*
1043
    *  @public function getTopicGetVar
1044
    *  @param string $lpFieldName
1045
    *  @param string $rpFieldName
1046
    *  @param string $tableName
1047
    *  @param string $tableNameTopic
1048
    *  @param string $fieldNameParent
1049
    *  @param string $fieldNameTopic
1050
    *  @return string
1051
    */
1052
    public function getTopicGetVar($lpFieldName, $rpFieldName, $tableName, $tableNameTopic, $fieldNameParent, $fieldNameTopic)
1053
    {
1054
        $ret = <<<EOT
1055
\t\t// Get Var {$fieldNameParent}
1056
\t\t\${$rpFieldName} =& \${$tableNameTopic}Handler->get(\${$tableName}All[\$i]->getVar('{$fieldNameParent}'));
1057
\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$rpFieldName}->getVar('{$fieldNameTopic}');\n
1058
EOT;
1059
1060
        return $ret;
1061
    }
1062
	
1063
	/*
1064
    *  @public function getUploadImageGetVar
1065
    *  @param string $lpFieldName
1066
    *  @param string $rpFieldName
1067
    *  @param string $tableName
1068
    *  @param string $fieldName
1069
    *  @return string
1070
    */
1071
    public function getUploadImageGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
1072
    {
1073
        $ret = <<<EOT
1074
\t\t// Get Var {$fieldName}
1075
\t\t\${$fieldName} = \${$tableName}All[\$i]->getVar('{$fieldName}');
1076
\t\t\$upload_image = \${$fieldName} ? \${$fieldName} : 'blank.gif';
1077
\t\t\${$lpFieldName}['{$rpFieldName}'] = \$upload_image;\n
1078
EOT;
1079
1080
        return $ret;
1081
    }	        
1082
    
1083
    /*
1084
    *  @public function getXoopsCodeUpdate
1085
    *  @param $language
1086
    *  @param $tableName
1087
    *  @param $fieldId
1088
    *  @param $fieldName
1089
    *  @return string
1090
    */
1091
    public function getXoopsCodeUpdate($language, $tableName, $fieldId, $fieldName)
1092
    {
1093
        $isset = $this->phpcode->getPhpCodeIsset($fieldId);
1094
        $get = $this->getXoopsCodeHandler($tableName, $fieldId, true);
1095
        $content = $this->phpcode->getPhpCodeConditions($isset, '', '', "\${$tableName}Obj =& ".$get);
1096
        $content .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
1097
        $handlerInsert = $this->$this->getXoopsCodeHandler($tableName, $tableName, false, true, false, 'Obj');
1098
        $redirect = $this->getXoopsCodeRedirectHeader($tableName, '?op=list', 2, "{$language}FORM_UPDATE_OK");
1099
        $content .= $this->phpcode->getPhpCodeConditions($handlerInsert, '', '', $redirect);
1100
1101
        $content .= $this->getXoopsCodeTplAssign('error', "\${$tableName}Obj->getHtmlErrors()");
1102
1103
        return $this->phpcode->getPhpCodeCaseSwitch('update', $content);
1104
    }
1105
	
1106
	/**
1107
     *  @public function getXoopsCodeSaveFieldId
1108
     *
1109
     *  @param $fields
1110
     *
1111
     *  @return string
1112
     */
1113 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...
1114
    {
1115
        foreach (array_keys($fields) as $f) {
1116
            if (0 == $f) {
1117
                $fieldId = $fields[$f]->getVar('field_name');
1118
            }
1119
        }
1120
1121
        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...
1122
    }
1123
1124
    /**
1125
     *  @public function getXoopsCodeSaveFieldMain
1126
     *
1127
     *  @param $fields
1128
     *
1129
     *  @return string
1130
     */
1131 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...
1132
    {
1133
        foreach (array_keys($fields) as $f) {
1134
            if (1 == $fields[$f]->getVar('field_main')) {
1135
                $fieldMain = $fields[$f]->getVar('field_name');
1136
            }
1137
        }
1138
1139
        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...
1140
    }
1141
1142
    /**
1143
     *  @public function getXoopsCodeSaveElements
1144
     *
1145
     *  @param $moduleDirname
1146
     *  @param $tableName
1147
     *  @param $fields
1148
     *
1149
     *  @return string
1150
     */
1151 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...
1152
    {
1153
        $ret = '';
1154
        foreach (array_keys($fields) as $f) {
1155
            $fieldName = $fields[$f]->getVar('field_name');
1156
            $fieldElement = $fields[$f]->getVar('field_element');
1157
            if (1 == $fields[$f]->getVar('field_main')) {
1158
                $fieldMain = $fieldName;
1159
            }
1160
            if ((5 == $fieldElement) || (6 == $fieldElement)) {
1161
                $ret .= $this->getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName);
1162
            } elseif (13 == $fieldElement) {
1163
                $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...
1164
            } elseif (14 == $fieldElement) {
1165
                $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...
1166
            } elseif (15 == $fieldElement) {
1167
                $ret .= $this->getXoopsCodeTextDateSelectSetVar($tableName, $fieldName);
1168
            } else {
1169
                $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...
1170
            }
1171
        }
1172
1173
        return $ret;
1174
    }    
1175
}
1176