Completed
Pull Request — master (#43)
by Gino
03:32
created

TDMCreateXoopsCode::getXoopsCodeSetVarsObjects()   C

Complexity

Conditions 11
Paths 19

Size

Total Lines 40
Code Lines 32

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 40
rs 5.2653
cc 11
eloc 32
nc 19
nop 3

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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') or die('Restricted access');
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

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

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

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

Let’s take a look at a few examples:

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

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


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

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

Logical Operators are used for Control-Flow

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

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

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

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

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

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

Loading history...
25
/**
26
 * 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
    *  @public function getXoopsCodeCPHeader
84
    *  @param null
85
    *  @return string
86
    */
87
    public function getXoopsCodeCPHeader()
88
    {
89
        return "xoops_cp_header();\n";
90
    }
91
92
    /*
93
    *  @public function getXoopsCodeCPFooter
94
    *  @param null
95
    *  @return string
96
    */
97
    public function getXoopsCodeCPFooter()
98
    {
99
        return "xoops_cp_footer();\n";
100
    }
101
102
    /**
103
     *  @public function getXoopsCodeLoadLanguage
104
     *
105
     *  @param $lang
106
     *
107
     *  @return string
108
     */
109
    public function getXoopsCodeLoadLanguage($lang)
110
    {
111
        return "xoops_loadLanguage('{$lang}');\n";
112
    }
113
114
    /*
115
    *  @public function getXoopsCodeSetVar
116
    *  @param string $tableName
117
    *  @param string $fieldName
118
    *  @param string $var
119
    *  @return string
120
    */
121
    public function getXoopsCodeSetVar($tableName, $fieldName, $var)
122
    {
123
        return "\${$tableName}Obj->setVar('{$fieldName}', {$var});\n";
124
    }
125
126
    /*
127
    *  @public function getXoopsCodeTextDateSelectSetVar
128
    *  @param string $tableName
129
    *  @param string $fieldName
130
    *  @return string
131
    */
132
    public function getXoopsCodeTextDateSelectSetVar($tableName, $fieldName)
133
    {
134
        return $this->getXoopsCodeSetVar($tableName, $fieldName, "strtotime(\$_POST['{$fieldName}'])");
135
    }
136
137
    /*
138
    *  @public function getXoopsCodeCheckBoxOrRadioYNSetVar
139
    *  @param $tableName
140
    *  @param $fieldName
141
    *  @return string
142
    */
143
    public function getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName)
144
    {
145
        $ret = $this->getXoopsCodeSetVar($tableName, $fieldName, "((1 == \$_REQUEST['{$fieldName}']) ? '1' : '0')");
146
147
        return $ret;
148
    }
149
150
    /*
151
    *  @public function getXoopsCodeGetConfig
152
    *  @param $moduleDirname
153
    *  @param $name
154
    *  @return string
155
    */
156
    public function getXoopsCodeGetConfig($moduleDirname, $name)
157
    {
158
        return "\${$moduleDirname}->getConfig('{$name}')";
159
    }
160
161
    /*
162
    *  @public function getXoopsCodeGetConfig
163
    *  @param $var
164
    *  @param $dirPath
165
    *  @param $tableName
166
    *  @param $moduleDirname
167
    *  @return string
168
    */
169
    public function getXoopsCodeMediaUploader($var = '', $dirPath, $tableName, $moduleDirname)
170
    {
171
        return "\${$var} = new XoopsMediaUploader({$dirPath} . '/{$tableName}',
172
														\${$moduleDirname}->getConfig('mimetypes'),
173
                                                        \${$moduleDirname}->getConfig('maxsize'), null, null);\n";
174
    }
175
176
    /*
177
    *  @public function getXoopsCodeImageListSetVar
178
    *  @param string $moduleDirname
179
    *  @param string $tableName
180
    *  @param string $fieldName
181
    *  @return string
182
    */
183
    public function getXoopsCodeImageListSetVar($moduleDirname, $tableName, $fieldName)
184
    {
185
        $ret = $this->phpcode->phpcode->getPhpCodeCommentLine('Set Var', $fieldName);
186
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/uploader', true);
187
        $ret .= $this->getXoopsCodeMediaUploader('uploader', "XOOPS_ROOT_PATH . '/Frameworks/moduleclasses/icons/32'", $tableName, $moduleDirname);
188
        $fetchMedia = "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])";
189
        $ifelse = "//\$uploader->setPrefix('{$fieldName}_');\n";
190
        $ifelse .= "//\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])\n";
191
        $contentElseInt = "\${$tableName}Obj->setVar('{$fieldName}', \$uploader->getSavedFileName());";
192
        $contentIf = "\$errors = \$uploader->getErrors();\n";
193
        $contentIf .= "redirect_header('javascript:history.go(-1)', 3, \$errors);\n";
194
        $ifelse .= $this->phpcode->getPhpCodeConditions('!$uploader->upload()', '', '', $contentIf, $contentElseInt);
195
        $contentElseExt = "\${$tableName}Obj->setVar('{$fieldName}', \$_POST['{$fieldName}']);\n";
196
197
        $ret .= $this->phpcode->getPhpCodeConditions($fetchMedia, '', '', $ifelse, $contentElseExt);
198
199
        return $ret;
200
    }
201
202
    /*
203
    *  @public function getXoopsCodeUploadImageSetVar
204
    *  @param string $moduleDirname
205
    *  @param string $tableName
206
    *  @param string $fieldName
207
    *  @return string
208
    */
209
    public function getXoopsCodeUploadImageSetVar($moduleDirname, $tableName, $fieldName, $fieldMain)
210
    {
211
        $stuModuleDirname = strtoupper($moduleDirname);
212
        $ret = $this->phpcode->getPhpCodeCommentLine('Set Var', $fieldName);
213
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/uploader', true);
214
        $ret .= $this->getXoopsCodeMediaUploader('uploader', "{$stuModuleDirname}_UPLOAD_IMAGE_PATH", $tableName, $moduleDirname);
215
216
        $fetchMedia = "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])";
217
        $ifelse = "\$extension = preg_replace( '/^.+\.([^.]+)$/sU' , '' , \$_FILES['attachedfile']['name']);\n";
218
        $ifelse .= "\$imgName = str_replace(' ', '', \$_POST['{$fieldMain}']).'.'.\$extension;\n";
219
        $ifelse .= "\$uploader->setPrefix(\$imgName);\n";
220
        $ifelse .= "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0]);\n";
221
        $contentElseInt = "\${$tableName}Obj->setVar('{$fieldName}', \$uploader->getSavedFileName());";
222
        $contentIf = "\$errors = \$uploader->getErrors();\n";
223
        $contentIf .= "redirect_header('javascript:history.go(-1)', 3, \$errors);\n";
224
        $ifelse .= $this->phpcode->getPhpCodeConditions('!$uploader->upload()', '', '', $contentIf, $contentElseInt);
225
        $contentElseExt = "\${$tableName}Obj->setVar('{$fieldName}', \$_POST['{$fieldName}']);\n";
226
227
        $ret .= $this->phpcode->getPhpCodeConditions($fetchMedia, '', '', $ifelse, $contentElseExt);
228
229
        return $ret;
230
    }
231
232
    /*
233
    *  @public function getXoopsCodeFileSetVar
234
    *  @param $moduleDirname
235
    *  @param $tableName
236
    *  @param $fieldName
237
    *  @param $formatUrl
238
    *  @return string
239
    */
240
    public function getXoopsCodeFileSetVar($moduleDirname, $tableName, $fieldName, $formatUrl = false)
241
    {
242
        $stuModuleDirname = strtoupper($moduleDirname);
243
        if ($formatUrl) {
244
            $ret = $this->getXoopsCodeSetVar($tableName, $fieldName, "formatUrl(\$_REQUEST['{$fieldName}'])");
245
            $ret .= $this->phpcode->getPhpCodeCommentLine('Set Var', $fieldName);
246
        } else {
247
            $ret = $this->phpcode->getPhpCodeCommentLine('Set Var', $fieldName);
248
        }
249
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/uploader', true);
250
        $ret .= $this->getXoopsCodeMediaUploader('uploader', "{$stuModuleDirname}_UPLOAD_FILES_PATH", $tableName, $moduleDirname);
251
        $fetchMedia = "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])";
252
        if ($formatUrl) {
253
            $ifelse = "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])\n";
254
        } else {
255
            $ifelse = "//\$uploader->setPrefix('{$fieldName}_');\n";
256
            $ifelse .= "//\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])\n";
257
        }
258
        $contentElse = "\${$tableName}Obj->setVar('{$fieldName}', \$uploader->getSavedFileName());";
259
        $contentIf = "\$errors = \$uploader->getErrors();\n";
260
        $contentIf .= "redirect_header('javascript:history.go(-1)', 3, \$errors);\n";
261
        $ifelse .= $this->phpcode->getPhpCodeConditions('!$uploader->upload()', '', '', $contentIf, $contentElse);
262
263
        $ret .= $this->phpcode->getPhpCodeConditions($fetchMedia, '', '', $ifelse);
264
265
        return $ret;
266
    }
267
268
    /*
269
    *  @public function getXoopsCodeIdGetVar
270
    *  @param string $lpFieldName
271
    *  @return string
272
    */
273
    public function getXoopsCodeIdGetVar($lpFieldName)
274
    {
275
        return "\${$lpFieldName}['id'] = \$i;\n";
276
    }
277
278
    /*
279
    *  @public function getXoopsCodeGetVarAll
280
    *  @param string $lpFieldName
281
    *  @param string $rpFieldName
282
    *  @param string $tableName
283
    *  @param string $fieldName
284
    *  @return string
285
    */
286
    public function getXoopsCodeGetVarAll($lpFieldName, $rpFieldName, $tableName, $fieldName)
287
    {
288
        return "\${$lpFieldName}['{$rpFieldName}'] = \${$tableName}All[\$i]->getVar('{$fieldName}');\n";
289
    }
290
291
    /*
292
    *  @public function getXoopsCodeTopicGetVar
293
    *  @param string $lpFieldName
294
    *  @param string $rpFieldName
295
    *  @param string $tableName
296
    *  @param string $tableNameTopic
297
    *  @param string $fieldNameParent
298
    *  @param string $fieldNameTopic
299
    *  @return string
300
    */
301
    public function getXoopsCodeTopicGetVar($lpFieldName, $rpFieldName, $tableName, $tableNameTopic, $fieldNameParent, $fieldNameTopic)
302
    {
303
        $ret = <<<EOT
304
\t\t\t\t// Get Var {$fieldNameParent}
305
\t\t\t\t\${$rpFieldName} =& \${$tableNameTopic}Handler->get(\${$tableName}All[\$i]->getVar('{$fieldNameParent}'));
306
\t\t\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$rpFieldName}->getVar('{$fieldNameTopic}');\n
307
EOT;
308
309
        return $ret;
310
    }
311
312
    /*
313
    *  @public function getXoopsCodeParentTopicGetVar
314
    *  @param string $moduleDirname
315
    *  @param string $lpFieldName
316
    *  @param string $rpFieldName
317
    *  @param string $tableName
318
    *  @param string $tableSoleNameTopic
319
    *  @param string $tableNameTopic
320
    *  @param string $fieldNameParent
321
    *  @return string
322
    */
323 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...
324
    {
325
        $ret = <<<EOT
326
\t\t\t\tif(!isset(\${$tableNameTopic}Handler)) {
327
\t\t\t\t\t// Get {$tableNameTopic} Handler
328
\t\t\t\t\t\${$tableNameTopic}Handler =& \${$moduleDirname}->getHandler('{$tableNameTopic}');
329
\t\t\t\t}
330
\t\t\t\t// Get Var {$fieldNameParent}
331
\t\t\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$tableNameTopic}Handler->get{$tableSoleNameTopic}FromId(\${$tableName}All[\$i]->getVar('{$fieldNameParent}'));\n
332
EOT;
333
334
        return $ret;
335
    }
336
337
    /*
338
    *  @public function getXoopsCodeUploadImageGetVar
339
    *  @param string $lpFieldName
340
    *  @param string $rpFieldName
341
    *  @param string $tableName
342
    *  @param string $fieldName
343
    *  @return string
344
    */
345
    public function getXoopsCodeUploadImageGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
346
    {
347
        $ret = <<<EOT
348
\t\t\t\t// Get Var {$fieldName}
349
\t\t\t\t\${$fieldName} = \${$tableName}All[\$i]->getVar('{$fieldName}');
350
\t\t\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$fieldName} ? \${$fieldName} : 'blank.gif';\n
351
EOT;
352
353
        return $ret;
354
    }
355
    /*
356
    *  @public function getXoopsCodeUrlFileGetVar
357
    *  @param string $lpFieldName
358
    *  @param string $rpFieldName
359
    *  @param string $tableName
360
    *  @param string $fieldName
361
    *  @return string
362
    */
363
    public function getXoopsCodeUrlFileGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
364
    {
365
        return $this->getXoopsCodeGetVarAll($lpFieldName, $rpFieldName, $tableName, $fieldName);
366
    }
367
    /*
368
    *  @public function getXoopsCodeTextAreaGetVar
369
    *  @param string $lpFieldName
370
    *  @param string $rpFieldName
371
    *  @param string $tableName
372
    *  @param string $fieldName
373
    *  @return string
374
    */
375
    public function getXoopsCodeTextAreaGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
376
    {
377
        return "\${$lpFieldName}['{$rpFieldName}'] = strip_tags(\${$tableName}All[\$i]->getVar('{$fieldName}'));\n";
378
    }
379
380
    /*
381
    *  @public function getXoopsCodeSelectUserGetVar
382
    *  @param string $lpFieldName
383
    *  @param string $rpFieldName
384
    *  @param string $tableName
385
    *  @param string $fieldName
386
    * @return string
387
    */
388
    public function getXoopsCodeSelectUserGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
389
    {
390
        return "\${$lpFieldName}['{$rpFieldName}'] = XoopsUser::getUnameFromId(\${$tableName}All[\$i]->getVar('{$fieldName}'), 's');\n";
391
    }
392
393
    /*
394
    *  @public function getXoopsCodeTextDateSelectGetVar
395
    *  @param string $lpFieldName
396
    *  @param string $rpFieldName
397
    *  @param string $tableName
398
    *  @param string $fieldName
399
    *  @return string
400
    */
401
    public function getXoopsCodeTextDateSelectGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
402
    {
403
        return "\${$lpFieldName}['{$rpFieldName}'] = formatTimeStamp(\${$tableName}All[\$i]->getVar('{$fieldName}'), 's');\n";
404
    }
405
406
    /*
407
    *  @public function getXoopsCodeUserHeader
408
    *  @param string $moduleDirname
409
    *  @param string $tableName
410
    *  @return string
411
    */
412
    public function getXoopsCodeXoopsOptionTemplateMain($moduleDirname, $tableName)
413
    {
414
        return "\$GLOBALS['xoopsOption']['template_main'] = '{$moduleDirname}_{$tableName}.tpl';\n";
415
    }
416
417
    /*
418
    *  @public function getXoopsCodeUserHeader
419
    *  @param string $moduleDirname
420
    *  @param string $tableName
421
    *  @return string
422
    */
423
    public function getXoopsCodeUserHeader($moduleDirname, $tableName)
424
    {
425
        $ret = $this->phpcode->getPhpCodeIncludeDir('__DIR__', 'header');
426
        $ret .= $this->getXoopsCodeXoopsOptionTemplateMain($moduleDirname, $tableName);
427
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'header', true);
428
429
        return $ret;
430
    }
431
432
    /*
433
    *  @public function getXoopsCodePermissionsHeader
434
    *  @param null
435
    */
436
    /**
437
     * @return string
438
     */
439
    public function getXoopsCodePermissionsHeader()
440
    {
441
        $ret = $this->phpcode->getPhpCodeCommentLine('Permission');
442
		$ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/xoopsform/grouppermform', true);
443
		$ret .= $this->getXoopsCodeEqualsOperator("\$gperm_handler", "xoops_gethandler('groupperm')", true);
444
		$groups = $this->getXoopsCodeEqualsOperator("\$groups", "\$xoopsUser->getGroups()");
445
		$elseGroups = $this->getXoopsCodeEqualsOperator("\$groups", "XOOPS_GROUP_ANONYMOUS");		
446
		$ret .= $this->phpcode->getPhpCodeConditions("is_object(\$xoopsUser)", '', $type = '', $groups, $elseGroups);
447
		
448
        return $ret;
449
    }
450
451
    /**
452
     *  @public function getXoopsCodeGetFieldId
453
     *
454
     *  @param $fields
455
     *
456
     *  @return string
457
     */
458 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...
459
    {
460
        $fieldId = 'id';
461
        foreach (array_keys($fields) as $f) {
462
            $fieldName = $fields[$f]->getVar('field_name');
463
            if (0 == $f) {
464
                $fieldId = $fieldName;
465
            }
466
        }
467
468
        return $fieldId;
469
    }
470
471
    /**
472
     *  @public function getXoopsCodeGetFieldName
473
     *
474
     *  @param $fields
475
     *
476
     *  @return string
477
     */
478
    public function getXoopsCodeGetFieldName($fields)
479
    {
480
        foreach (array_keys($fields) as $f) {
481
            $fieldName = $fields[$f]->getVar('field_name');
482
        }
483
484
        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...
485
    }
486
487
    /**
488
     *  @public function getXoopsCodeGetFieldParentId
489
     *
490
     *  @param $fields
491
     *
492
     *  @return string
493
     */
494 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...
495
    {
496
        $fieldPid = 'pid';
497
        foreach (array_keys($fields) as $f) {
498
            $fieldName = $fields[$f]->getVar('field_name');
499
            if (1 == $fields[$f]->getVar('field_parent')) {
500
                $fieldPid = $fieldName;
501
            }
502
        }
503
504
        return $fieldPid;
505
    }
506
507
    /**
508
     *  @public function getXoopsCodeUserSaveElements
509
     *
510
     *  @param $moduleDirname
511
     *  @param $tableName
512
     *  @param $fields
513
     *
514
     *  @return string
515
     */
516
    public function getXoopsCodeUserSaveElements($moduleDirname, $tableName, $fields)
517
    {
518
        $ret = '';
519
        foreach (array_keys($fields) as $f) {
520
            $fieldName = $fields[$f]->getVar('field_name');
521
            $fieldElement = $fields[$f]->getVar('field_element');
522
            if (1 == $fields[$f]->getVar('field_main')) {
523
                $fieldMain = $fieldName;
524
            }
525
            if ((5 == $fieldElement) || (6 == $fieldElement)) {
526
                $ret .= $this->getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName);
527
            } elseif (13 == $fieldElement) {
528
                $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...
529
            } elseif (14 == $fieldElement) {
530
                $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...
531
            } elseif (15 == $fieldElement) {
532
                $ret .= $this->getXoopsCodeTextDateSelectSetVar($tableName, $fieldName);
533
            } else {
534
                $ret .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
535
            }
536
        }
537
538
        return $ret;
539
    }
540
541
    /*
542
    *  @public function getXoopsCodeXoopsRequest
543
    *  @param $left
544
    *  @param $var1
545
    *  @param $var2
546
    *  @param $type
547
    *  @param $metod
548
    *  @return string
549
    */
550
    public function getXoopsCodeXoopsRequest($left = '', $var1 = '', $var2 = '', $type = 'String', $metod = false)
551
    {
552
        if ($type == 'String') {
553
            $ret = "\${$left} = XoopsRequest::getString('{$var1}', '{$var2}');\n";
554
        } elseif ($type == 'Int') {
555
            $ret = "\${$left} = XoopsRequest::getInt('{$var1}', {$var2});\n";
556
        } elseif ($type == 'Int' && $metod !== false) {
557
            $ret = "\${$left} = XoopsRequest::getInt('{$var1}', {$var2}, '{$metod}');\n";
558
        }
559
560
        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...
561
    }
562
563
    /*
564
    *  @public function getXoopsCodeAddInfoBox
565
    *  @param $language
566
    *  
567
    *  @return string
568
    */
569
    public function getXoopsCodeAddInfoBox($language)
570
    {
571
        return "\$adminMenu->addInfoBox({$language});\n";
572
    }
573
574
    /*
575
    *  @public function getXoopsCodeAddInfoBoxLine
576
    *  @param $language
577
    *  @param $label
578
    *  @param $var
579
    *  
580
    *  @return string
581
    */
582 View Code Duplication
    public function getXoopsCodeAddInfoBoxLine($language, $label = '', $var = '')
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...
583
    {
584
        if ($var != '') {
585
            $ret = "\$adminMenu->addInfoBoxLine({$language}, '<label>'.{$label}.'</label>', {$var});\n";
586
        } else {
587
            $ret = "\$adminMenu->addInfoBoxLine({$language}, '<label>'.{$label}.'</label>');\n";
588
        }
589
590
        return $ret;
591
    }
592
	
593
	/*
594
    *  @public function getXoopsCodeAddConfigBoxLine
595
    *  @param $language
596
    *  @param $label
597
    *  @param $var
598
    *  
599
    *  @return string
600
    */
601 View Code Duplication
    public function getXoopsCodeAddConfigBoxLine($language, $label = '', $var = '')
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...
602
    {
603
        if ($var != '') {
604
            $ret = "\$adminMenu->addConfigBoxLine({$language}, '{$label}', {$var});\n";
605
        } else {
606
            $ret = "\$adminMenu->addConfigBoxLine({$language}, '{$label}');\n";
607
        }
608
609
        return $ret;
610
    }
611
612
    /*
613
    *  @public function getXoopsCodeTemplateMain
614
    *  @param $moduleDirname
615
    *  @param $filename
616
    *  @return string
617
    */
618
    public function getXoopsCodeTemplateMain($moduleDirname, $filename)
619
    {
620
        return "\$templateMain = '{$moduleDirname}_admin_{$filename}.tpl';\n";
621
    }
622
623
    /**
624
     *  @public function getXoopsCodeTplAssign
625
     *
626
     *  @param string $tplString
627
     *  @param string $phpRender
628
     *
629
     *  @return string
630
     */
631
    public function getXoopsCodeTplAssign($tplString, $phpRender)
632
    {
633
        return "\$GLOBALS['xoopsTpl']->assign('{$tplString}', {$phpRender});\n";
634
    }
635
636
    /**
637
     *  @public function getXoopsCodeXoopsTplAppend
638
     *
639
     *  @param string $tplString
640
     *  @param string $phpRender
641
     *
642
     *  @return string
643
     */
644
    public function getXoopsCodeXoopsTplAppend($tplString, $phpRender)
645
    {
646
        return "\$GLOBALS['xoopsTpl']->append('{$tplString}', {$phpRender});\n";
647
    }
648
649
    /**
650
     *  @public function getXoopsCodeXoopsTplAppendByRef
651
     *
652
     *  @param string $tplString
653
     *  @param string $phpRender
654
     *
655
     *  @return string
656
     */
657
    public function getXoopsCodeXoopsTplAppendByRef($tplString, $phpRender)
658
    {
659
        return "\$GLOBALS['xoopsTpl']->appendByRef('{$tplString}', {$phpRender});\n";
660
    }
661
662
    /**
663
     *  @public function getXoopsCodePath
664
     *
665
     *  @param $directory
666
     *  @param $filename
667
     *  @param $condition
668
     *
669
     *  @return string
670
     */
671
    public function getXoopsCodePath($directory, $filename, $condition = false)
672
    {
673
        if ($condition === false) {
674
            $ret = "\$GLOBALS['xoops']->path({$directory}.'/{$filename}.php');\n";
675
        } else {
676
            $ret = "\$GLOBALS['xoops']->path({$directory}.'/{$filename}.php')";
677
        }
678
679
        return $ret;
680
    }
681
682
    /**
683
     *  @public function getXoopsCodeTplDisplay
684
     *
685
     *  @param null
686
     *
687
     *  @return string
688
     */
689
    public function getXoopsCodeTplDisplay()
690
    {
691
        return "\$GLOBALS['xoopsTpl']->display(\"db:{\$templateMain}\");\n";
692
    }
693
694
    /*
695
    *  @public function getXoopsCodeItemButton
696
    *  @param $language
697
    *  @param $tableName
698
    *  @param $admin
699
    *  @return string
700
    */
701
    public function getXoopsCodeItemButton($language, $tableName, $tableSoleName, $op = '?op=new', $type = 'add')
702
    {
703
        $stuTableName = strtoupper($tableName);
704
        $stuTableSoleName = strtoupper($tableSoleName);
705
        $stuType = strtoupper($type);
706
        $aMIB = '$adminMenu->addItemButton(';
707
        if ($type = 'add') {
708
            $ret = $aMIB."{$language}{$stuType}_{$stuTableSoleName}, '{$tableName}.php{$op}', '{$type}');\n";
709
        } elseif ($type = 'list') {
710
            $ret = $aMIB."{$language}{$stuTableName}_{$stuType}, '{$tableName}.php', '{$type}');\n";
711
        } else {
712
            $ret = $aMIB."{$language}{$stuTableName}_{$stuType}, '{$tableName}.php', '{$type}');\n";
713
        }
714
715
        return $ret;
716
    }
717
718
    /**
719
     *  @public function getXoopsCodeGetInfo
720
     *
721
     *  @param $string
722
     *  @param $isParam
723
     *
724
     *  @return string
725
     */
726
    public function getXoopsCodeGetInfo($string, $isParam = false)
727
    {
728
        if ($isParam === false) {
729
            $ret = "\$GLOBALS['xoopsModule']->getInfo('{$string}');\n";
730
        } else {
731
            $ret = "\$GLOBALS['xoopsModule']->getInfo('{$string}')";
732
        }
733
734
        return $ret;
735
    }
736
737
    /**
738
     *  @public function getXoopsCodeObjHandlerCreate
739
     *
740
     *  @param string $tableName
741
     *
742
     *  @return string
743
     */
744
    public function getXoopsCodeObjHandlerCreate($tableName)
745
    {
746
        $ret = "\${$tableName}Obj =& \${$tableName}Handler->create();\n";
747
748
        return $ret;
749
    }
750
751
    /**
752
     *  @public function getXoopsCodeSetVarsObjects
753
     *
754
     *  @param $moduleDirname
755
     *  @param $tableName
756
     *  @param $fields
757
     *
758
     *  @return string
759
     */
760
    public function getXoopsCodeSetVarsObjects($moduleDirname, $tableName, $fields)
761
    {
762
        $ret = '';
763
764
        foreach (array_keys($fields) as $f) {
765
            $fieldName = $fields[$f]->getVar('field_name');
766
            $fieldElement = $fields[$f]->getVar('field_element');
767
            if (1 == $fields[$f]->getVar('field_main')) {
768
                $fieldMain = $fieldName;
769
            }
770
            if ($f > 0) { // If we want to hide field id
771
                switch ($fieldElement) {
772
                    case 5:
773
                    case 6:
774
                        $ret .= $this->getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName);
775
                        break;
776
                    case 11:
777
                        $ret .= $this->getXoopsCodeImageListSetVar($moduleDirname, $tableName, $fieldName);
778
                        break;
779
                    case 12:
780
                        $ret .= $this->getXoopsCodeFileSetVar($moduleDirname, $tableName, $fieldName, true);
781
                        break;
782
                    case 13:
783
                        $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...
784
                        break;
785
                    case 14:
786
                        $ret .= $this->getXoopsCodeFileSetVar($moduleDirname, $tableName, $fieldName);
787
                        break;
788
                    case 15:
789
                        $ret .= $this->getXoopsCodeTextDateSelectSetVar($tableName, $fieldName);
790
                        break;
791
                    default:
792
                        $ret .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
793
                        break;
794
                }
795
            }
796
        }
797
798
        return $ret;
799
    }
800
801
    /**
802
     *  @public function getXoopsCodeSecurity
803
     *
804
     *  @param $tableName
805
     *
806
     *  @return string
807
     */
808
    public function getXoopsCodeSecurity($tableName)
809
    {
810
        $securityError = $this->getXoopsCodeSecurityGetError();
811
        $implode = $this->phpcode->getPhpCodeImplode(',', $securityError);
812
        $content = $this->getXoopsCodeRedirectHeader($tableName, '', 3, $implode);
813
        $securityCheck = $this->getXoopsCodeSecurityCheck();
814
815
        return $this->phpcode->getPhpCodeConditions('!'.$securityCheck, '', '', $content);
816
    }
817
818
    /*
819
    *  @public function getXoopsCodeInsertData
820
    *  @param $tableName
821
    *  @param $language
822
    *  @return string
823
    */
824
    public function getXoopsCodeInsertData($tableName, $language)
825
    {
826
        $content = $this->getXoopsCodeRedirectHeader($tableName, '?op=list', 2, "{$language}FORM_OK");
827
        $handlerInsert = $this->getXoopsCodeHandler($tableName, $tableName, false, true, false, 'Obj');
828
829
        return $this->phpcode->getPhpCodeConditions($handlerInsert, '', '', $content);
830
    }
831
832
    /*
833
    *  @public function getXoopsCodeRedirectHeader
834
    *  @param $tableName
835
    *  @param $options
836
    *  @param $numb
837
    *  @param $var
838
    *  @return string
839
    */
840
    public function getXoopsCodeRedirectHeader($tableName, $options = '', $numb = '2', $var)
841
    {
842
        return "redirect_header('{$tableName}.php{$options}', {$numb}, {$var});\n";
843
    }
844
845
    /*
846
    *  @public function getXoopsCodeSecurityCheck
847
    *  @param null
848
    *  @return boolean
849
    */
850
    public function getXoopsCodeSecurityCheck()
851
    {
852
        return "\$GLOBALS['xoopsSecurity']->check()";
853
    }
854
855
    /*
856
    *  @public function getXoopsCodeSecurityGetError
857
    *  @param null
858
    *  @return string
859
    */
860
    public function getXoopsCodeSecurityGetError()
861
    {
862
        return "\$GLOBALS['xoopsSecurity']->getErrors()";
863
    }
864
865
    /**
866
     *  @public function getXoopsCodeGetFormError
867
     *
868
     *  @param $tableName
869
     *
870
     *  @return string
871
     */
872
    public function getXoopsCodeGetFormError($tableName)
873
    {
874
        $ret = <<<EOT
875
        // Get Form
876
        \$GLOBALS['xoopsTpl']->assign('error', \${$tableName}Obj->getHtmlErrors());
877
        \$form =& \${$tableName}Obj->getForm();
878
        \$GLOBALS['xoopsTpl']->assign('form', \$form->render());\n
879
EOT;
880
881
        return $ret;
882
    }
883
884
    /**
885
     *  @public function getXoopsCodeGetFormId
886
     *
887
     *  @param string $tableName
888
     *  @param string $fieldId
889
     *
890
     *  @return string
891
     */
892
    public function getXoopsCodeGetFormId($tableName, $fieldId)
893
    {
894
        $ret = <<<EOT
895
        // Get Form
896
        \${$tableName}Obj = \${$tableName}Handler->get(\${$fieldId});
897
        \$form = \${$tableName}Obj->getForm();
898
        \$GLOBALS['xoopsTpl']->assign('form', \$form->render());\n
899
EOT;
900
901
        return $ret;
902
    }
903
904
    /**
905
     *  @public function getXoopsCodeHandler
906
     *
907
     *  @param string $tableName
908
     *  @param string $var
909
     *
910
     *  @return string
911
     */
912
    public function getXoopsCodeHandler($tableName, $var, $get = false, $insert = false, $delete = false, $obj = '')
913
    {
914
        if ($get) {
915
            $ret = "\${$tableName}Handler->get(\${$var});";
916
        } elseif ($insert && ($obj != '')) {
917
            $ret = "\${$tableName}Handler->insert(\${$var}{$obj});";
918
        } elseif ($delete && ($obj != '')) {
919
            $ret = "\${$tableName}Handler->delete(\${$var}{$obj});";
920
        }
921
922
        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...
923
    }
924
925
    /*
926
    *  @public function getXoopsCodeCaseDelete
927
    *  @param string $tableName
928
    *  @param string $language
929
    *  @param string $fieldId
930
    *  @param string $fieldMain
931
    *  @return string
932
    */
933 View Code Duplication
    public function getXoopsCodeCaseDelete($language, $tableName, $fieldId, $fieldMain)
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...
934
    {
935
        $ret = <<<EOT
936
        \${$tableName}Obj =& \${$tableName}Handler->get(\${$fieldId});
937
        if (isset(\$_REQUEST['ok']) && 1 == \$_REQUEST['ok']) {
938
            if ( !\$GLOBALS['xoopsSecurity']->check() ) {
939
                redirect_header('{$tableName}.php', 3, implode(', ', \$GLOBALS['xoopsSecurity']->getErrors()));
940
            }
941
            if (\${$tableName}Handler->delete(\${$tableName}Obj)) {
942
                redirect_header('{$tableName}.php', 3, {$language}FORM_DELETE_OK);
943
            } else {
944
                echo \${$tableName}Obj->getHtmlErrors();
945
            }
946
        } else {
947
            xoops_confirm(array('ok' => 1, '{$fieldId}' => \${$fieldId}, 'op' => 'delete'), \$_SERVER['REQUEST_URI'], sprintf({$language}FORM_SURE_DELETE, \${$tableName}Obj->getVar('{$fieldMain}')));
948
        }\n
949
EOT;
950
        /*$isset = $this->phpcode->getPhpCodeIsset($fieldId);
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
951
        $if1 = $this->phpcode->getPhpCodeConditions($isset, '', '', "\${$tableName}Obj =& ".$get);
952
        $get = $this->getXoopsCodeHandler($tableName, $fieldId, true);
953
        $if2 = $this->phpcode->getPhpCodeConditions($isset, '', '', "\${$tableName}Obj =& ".$get);
954
        $ret = $this->phpcode->getPhpCodeConditions($isset, '', '', "\${$tableName}Obj =& ".$get);
955
        //$ret .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
956
        $handlerInsert = $this->$this->getXoopsCodeHandler($tableName, $tableName, false, true, false, 'Obj');
957
        $redirect = $this->getXoopsCodeRedirectHeader($tableName, '', 2, "{$language}FORM_DELETE_OK");
958
959
        $else = $this->getXoopsCodeTplAssign('error', "\${$tableName}Obj->getHtmlErrors()");
960
961
        $ret .= $this->phpcode->getPhpCodeConditions($handlerInsert, '', '', $redirect, $else);*/
962
963
        return $this->phpcode->getPhpCodeCaseSwitch('delete', $ret);
964
    }
965
966
    /*
967
    *  @public function getXoopsCodeUpdate
968
    *  @param $language
969
    *  @param $tableName
970
    *  @param $fieldId
971
    *  @param $fieldName
972
    *  @return string
973
    */
974
    public function getXoopsCodeUpdate($language, $tableName, $fieldId, $fieldName)
975
    {
976
        $isset = $this->phpcode->getPhpCodeIsset($fieldId);
977
        $get = $this->getXoopsCodeHandler($tableName, $fieldId, true);
978
        $content = $this->phpcode->getPhpCodeConditions($isset, '', '', "\${$tableName}Obj =& ".$get);
979
        $content .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
980
        $handlerInsert = $this->$this->getXoopsCodeHandler($tableName, $tableName, false, true, false, 'Obj');
981
        $redirect = $this->getXoopsCodeRedirectHeader($tableName, '?op=list', 2, "{$language}FORM_UPDATE_OK");
982
        $content .= $this->phpcode->getPhpCodeConditions($handlerInsert, '', '', $redirect);
983
984
        $content .= $this->getXoopsCodeTplAssign('error', "\${$tableName}Obj->getHtmlErrors()");
985
986
        return $this->phpcode->getPhpCodeCaseSwitch('update', $content);
987
    }
988
}
989