Completed
Push — master ( 3f0046...b1c777 )
by Gino
06:41 queued 03:19
created

TDMCreateXoopsCode   D

Complexity

Total Complexity 139

Size/Duplication

Total Lines 1323
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2
Metric Value
wmc 139
lcom 1
cbo 2
dl 0
loc 1323
rs 4.4102

75 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getInstance() 0 9 2
A getXoopsCodeSwitch() 0 6 1
A getXoopsCodeEqualsOperator() 0 10 2
A getXoopsCodeCPHeader() 0 4 1
A getXoopsCodeCPFooter() 0 4 1
A getXoopsCodeLoad() 0 4 1
A getXoopsCodeLoadLanguage() 0 4 1
A getXoopsCodeAnchorFunction() 0 4 1
A getXoopsCodeSetVar() 0 4 1
A getXoopsCodeGetVar() 0 10 2
A getXoopsCodeGroupPermForm() 0 4 1
A getXoopsCodeAddItem() 0 4 1
A getXoopsCodeTextDateSelectSetVar() 0 4 1
A getXoopsCodeCheckBoxOrRadioYNSetVar() 0 4 1
A getXoopsCodeXoopsMediaUploader() 0 7 1
A getXoopsCodeXoopsCaptcha() 0 4 1
A getXoopsCodeGetConfig() 0 4 1
A getXoopsCodeIdGetVar() 0 4 1
A getXoopsCodeGetVarAll() 0 4 1
A getXoopsHandlerInstance() 0 8 1
A getXoopsHandlerLine() 0 4 1
A getXoopsSimpleForm() 0 11 2
A getXoopsFormSelect() 0 12 3
A getXoopsCodeUnameFromId() 0 4 1
A getXoopsCodeFormatTimeStamp() 0 4 1
A getXoopsCodeTopicGetVar() 0 10 1
A getXoopsCodeUploadImageGetVar() 0 10 1
A getXoopsCodeUrlFileGetVar() 0 4 1
A getXoopsCodeTextAreaGetVar() 0 4 1
A getXoopsCodeSelectUserGetVar() 0 4 1
A getXoopsCodeTextDateSelectGetVar() 0 4 1
A getXoopsCodeXoopsOptionTemplateMain() 0 4 1
A getXoopsCodeUserHeader() 0 8 1
A getXoopsCodePermissionsHeader() 0 11 1
A getXoopsCodeGetFieldName() 0 8 2
B getXoopsCodeXoopsRequest() 0 14 6
A getXoopsCodeTplAssign() 0 11 2
A getXoopsCodeXoopsTplAppend() 0 4 1
A getXoopsCodeXoopsTplAppendByRef() 0 4 1
A getXoopsCodePath() 0 10 2
A getXoopsCodeTplDisplay() 0 4 1
A getXoopsCodeGetInfo() 0 10 2
A getXoopsCodeCheckRight() 0 10 2
A getXoopsCodeObjHandlerCreate() 0 4 1
A getXoopsCodeObjHandlerCount() 0 7 1
A getXoopsCodeObjHandlerAll() 0 9 3
A getXoopsCodeGetValues() 0 11 2
A getXoopsCodeObjectTree() 0 6 1
C getXoopsCodeSetVarsObjects() 0 39 11
A getXoopsCodeSecurity() 0 9 1
A getXoopsCodeInsertData() 0 7 1
A getXoopsCodeRedirectHeader() 0 10 2
A getXoopsCodeXoopsConfirm() 0 8 1
A getXoopsCodeAddStylesheet() 0 4 1
A getXoopsCodeSecurityCheck() 0 4 1
A getXoopsCodeSecurityErrors() 0 4 1
A getXoopsCodeHtmlErrors() 0 11 2
A getXoopsCodeGetForm() 0 6 1
B getXoopsCodeHandler() 0 12 6
B getXoopsCodeCaseDelete() 0 25 1
A getTopicGetVar() 0 10 1
A getUploadImageGetVar() 0 11 1
A getXoopsCodeUpdate() 0 16 1
A getXoopsCodePageNav() 0 10 1
A getXoopsCodeParentTopicGetVar() 0 13 1
A getXoopsCodeGetFieldId() 0 12 3
A getXoopsCodeGetFieldParentId() 0 12 3
C getXoopsCodeUserSaveElements() 0 24 8
A getXoopsCodeGet() 0 11 3
A getXoopsCodeInsert() 0 11 3
A getXoopsCodeDelete() 0 11 3
A getXoopsCodeSaveFieldId() 0 10 3
A getXoopsCodeSaveFieldMain() 0 10 3
C getXoopsCodeSaveElements() 0 24 8

How to fix   Complexity   

Complex Class

Complex classes like TDMCreateXoopsCode often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use TDMCreateXoopsCode, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
8
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
/**
13
 * tdmcreate module.
14
 *
15
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 *
18
 * @since           2.5.0
19
 *
20
 * @author          Txmod Xoops http://www.txmodxoops.org
21
 *
22
 * @version         $Id: TDMCreateXoopsCode.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
25
/**
26
 * Class TDMCreateXoopsCode.
27
 */
28
class TDMCreateXoopsCode
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

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

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
864
            $ret = "\${$tableSoleName} = \${$tableName}All[\${$index}]->getValues{$ucfTableName}();\n";
865
        } else {
866
            $ret = "\${$tableSoleName} = \${$tableName}->getValues{$ucfTableName}();\n";
867
        }
868
869
        return $ret;
870
    }
871
872
    /**
873
     *  @public function getXoopsCodeObjectTree
874
     *
875
     *  @param $tableName
876
     *  @param $fieldId
877
     *  @param $fieldParent
878
     *
879
     *  @return string
880
     */
881
    public function getXoopsCodeObjectTree($tableName, $fieldId, $fieldParent)
882
    {
883
        $ret = "\$mytree = new XoopsObjectTree(\${$tableName}All, '{$fieldId}', '{$fieldParent}');\n";
884
885
        return $ret;
886
    }
887
888
    /**
889
     *  @public function getXoopsCodeSetVarsObjects
890
     *
891
     *  @param $moduleDirname
892
     *  @param $tableName
893
     *  @param $fields
894
     *
895
     *  @return string
896
     */
897
    public function getXoopsCodeSetVarsObjects($moduleDirname, $tableName, $fields)
898
    {
899
        $ret = '';
900
        foreach (array_keys($fields) as $f) {
901
            $fieldName = $fields[$f]->getVar('field_name');
902
            $fieldElement = $fields[$f]->getVar('field_element');
903
            if (1 == $fields[$f]->getVar('field_main')) {
904
                $fieldMain = $fieldName;
905
            }
906
            if ($f > 0) { // If we want to hide field id
907
                switch ($fieldElement) {
908
                    case 5:
909
                    case 6:
910
                        $ret .= $this->getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName);
911
                        break;
912
                    case 11:
913
                        $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...
914
                        break;
915
                    case 12:
916
                        $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...
917
                        break;
918
                    case 13:
919
                        $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...
920
                        break;
921
                    case 14:
922
                        $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...
923
                        break;
924
                    case 15:
925
                        $ret .= $this->getXoopsCodeTextDateSelectSetVar($tableName, $fieldName);
926
                        break;
927
                    default:
928
                        $ret .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
929
                        break;
930
                }
931
            }
932
        }
933
934
        return $ret;
935
    }
936
937
    /**
938
     *  @public function getXoopsCodeSecurity
939
     *
940
     *  @param $tableName
941
     *
942
     *  @return string
943
     */
944
    public function getXoopsCodeSecurity($tableName)
945
    {
946
        $securityError = $this->getXoopsCodeSecurityGetError();
0 ignored issues
show
Bug introduced by
The method getXoopsCodeSecurityGetError() does not exist on TDMCreateXoopsCode. Did you maybe mean getXoopsCodeSecurity()?

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

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

Loading history...
947
        $implode = $this->phpcode->getPhpCodeImplode(',', $securityError);
948
        $content = $this->getXoopsCodeRedirectHeader($tableName.'.php', '', 3, $implode);
949
        $securityCheck = $this->getXoopsCodeSecurityCheck();
950
951
        return $this->phpcode->getPhpCodeConditions('!'.$securityCheck, '', '', $content);
952
    }
953
954
    /*
955
    *  @public function getXoopsCodeInsertData
956
    *  @param $tableName
957
    *  @param $language
958
    *  @return string
959
    */
960
    public function getXoopsCodeInsertData($tableName, $language)
961
    {
962
        $content = $this->getXoopsCodeRedirectHeader($tableName.'.php', '?op=list', 2, "{$language}FORM_OK");
963
        $handlerInsert = $this->getXoopsCodeHandler($tableName, $tableName, false, true, false, 'Obj');
964
965
        return $this->phpcode->getPhpCodeConditions($handlerInsert, '', '', $content);
966
    }
967
968
    /*
969
    *  @public function getXoopsCodeRedirectHeader
970
    *  @param $tableName
971
    *  @param $options
972
    *  @param $numb
973
    *  @param $var
974
    *  @param $isString
975
    *
976
    *  @return string
977
    */
978
    public function getXoopsCodeRedirectHeader($tableName, $options = '', $numb = '2', $var, $isString = true)
979
    {
980
        if ($isString === false) {
981
            $ret = "redirect_header({$tableName}, {$numb}, {$var});\n";
982
        } else {
983
            $ret = "redirect_header('{$tableName}{$options}', {$numb}, {$var});\n";
984
        }
985
986
        return $ret;
987
    }
988
989
    /*
990
    *  @public function getXoopsCodeXoopsConfirm
991
    *  @param $tableName
992
    *  @param $language
993
    *  @param $fieldId
994
    *  @param $fieldMain    
995
    *  @param $options
996
    *
997
    *  @return string
998
    */
999
    public function getXoopsCodeXoopsConfirm($tableName, $language, $fieldId, $fieldMain, $options = 'delete')
1000
    {
1001
        $stuOptions = strtoupper($options);
1002
        $ccFieldId = $this->tdmcfile->getCamelCase($fieldId, false, true);
1003
        $ret = "xoops_confirm(array('ok' => 1, '{$fieldId}' => \${$ccFieldId}, 'op' => {$options}), \$_SERVER['REQUEST_URI'], sprintf({$language}FORM_SURE_{$stuOptions}, \${$tableName}Obj->getVar('{$fieldMain}')));\n";
1004
1005
        return $ret;
1006
    }
1007
1008
    /*
1009
    *  @public function getXoopsCodeAddStylesheet
1010
    *  @param $style
1011
    *  
1012
    *  @return string
1013
    */
1014
    public function getXoopsCodeAddStylesheet($style = 'style')
1015
    {
1016
        return "\$GLOBALS['xoTheme']->addStylesheet( \${$style}, null );\n";
1017
    }
1018
1019
    /*
1020
    *  @public function getXoopsCodeSecurityCheck
1021
    *  @param $denial
1022
    *  @return boolean
1023
    */
1024
    public function getXoopsCodeSecurityCheck($denial = '')
1025
    {
1026
        return "{$denial}\$GLOBALS['xoopsSecurity']->check()";
1027
    }
1028
1029
    /*
1030
    *  @public function getXoopsCodeSecurityErrors
1031
    *  @param null
1032
    *  @return string
1033
    */
1034
    public function getXoopsCodeSecurityErrors()
1035
    {
1036
        return "\$GLOBALS['xoopsSecurity']->getErrors()";
1037
    }
1038
1039
    /**
1040
     *  @public function getXoopsCodeHtmlErrors
1041
     *
1042
     *  @param $tableName
1043
     *  @param $isParam
1044
     *  @param $obj
1045
     *
1046
     *  @return string
1047
     */
1048
    public function getXoopsCodeHtmlErrors($tableName, $isParam = false, $obj = 'Obj')
1049
    {
1050
        $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...
1051
        if ($isParam) {
1052
            $ret = "\${$tableName}{$obj}->getHtmlErrors()";
1053
        } else {
1054
            $ret = "\${$tableName}{$obj} =& \${$tableName}->getHtmlErrors();";
1055
        }
1056
1057
        return $ret;
1058
    }
1059
1060
    /**
1061
     *  @public function getXoopsCodeObjHandlerCount
1062
     *
1063
     *  @param $left
1064
     *  @param $tableName
1065
     *  @param $obj
1066
     *
1067
     *  @return string
1068
     */
1069
    public function getXoopsCodeGetForm($left, $tableName, $obj = '')
1070
    {
1071
        $ucfTableName = ucfirst($tableName);
1072
1073
        return "\${$left} =& \${$tableName}{$obj}->getForm{$ucfTableName}();\n";
1074
    }
1075
1076
    /**
1077
     *  @public function getXoopsCodeGet
1078
     *
1079
     *  @param $tableName
1080
     *  @param $var
1081
     *  @param $obj
1082
     *  @param $isHandler
1083
     *  @param $isParam
1084
     *
1085
     *  @return string
1086
     */
1087
    public function getXoopsCodeGet($tableName, $var, $obj = '', $isHandler = false, $isParam = false)
1088
    {
1089
        $handler = $isHandler === false ? '' : 'Handler';
1090
        if ($isParam) {
1091
            $ret = "\${$tableName}{$handler}->get(\${$var})";
1092
        } else {
1093
            $ret = "\${$tableName}{$obj} =& \${$tableName}{$handler}->get(\${$var});\n";
1094
        }
1095
1096
        return $ret;
1097
    }
1098
1099
    /**
1100
     *  @public function getXoopsCodeHandler
1101
     *
1102
     *  @param $tableName
1103
     *  @param $var
1104
     *  @param $obj
1105
     *  @param $isHandler
1106
     *
1107
     *  @return string
1108
     */
1109
    public function getXoopsCodeInsert($tableName, $var, $obj = '', $isHandler = false)
1110
    {
1111
        $handler = ($isHandler === false) ? '' : 'Handler';
1112
        if ($obj != '') {
1113
            $ret = "\${$tableName}{$handler}->insert(\${$var}{$obj})";
1114
        } else {
1115
            $ret = "\${$tableName}{$handler}->insert(\${$var})";
1116
        }
1117
1118
        return $ret;
1119
    }
1120
1121
    /**
1122
     *  @public function getXoopsCodeDelete
1123
     *
1124
     *  @param $tableName
1125
     *  @param $var
1126
     *  @param $obj
1127
     *  @param $isHandler
1128
     *
1129
     *  @return string
1130
     */
1131
    public function getXoopsCodeDelete($tableName, $var, $obj = '', $isHandler = false)
1132
    {
1133
        $handler = $isHandler === false ? '' : 'Handler';
1134
        if ($obj != '') {
1135
            $ret = "\${$tableName}{$handler}->delete(\${$var}{$obj})";
1136
        } else {
1137
            $ret = "\${$tableName}{$handler}->delete(\${$var})";
1138
        }
1139
1140
        return $ret;
1141
    }
1142
1143
    /**
1144
     *  @public function getXoopsCodeHandler
1145
     *
1146
     *  @param $tableName
1147
     *  @param $var
1148
     *
1149
     *  @return string
1150
     */
1151
    public function getXoopsCodeHandler($tableName, $var, $get = false, $insert = false, $delete = false, $obj = '')
1152
    {
1153
        if ($get) {
1154
            $ret = "\${$tableName}Handler->get(\${$var});";
1155
        } elseif ($insert && ($obj != '')) {
1156
            $ret = "\${$tableName}Handler->insert(\${$var}{$obj});";
1157
        } elseif ($delete && ($obj != '')) {
1158
            $ret = "\${$tableName}Handler->delete(\${$var}{$obj});";
1159
        }
1160
1161
        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...
1162
    }
1163
1164
    /*
1165
    *  @public function getXoopsCodeCaseDelete
1166
    *  @param $tableName
1167
    *  @param $language
1168
    *  @param $fieldId
1169
    *  @param $fieldMain
1170
    *  @return string
1171
    */
1172
    public function getXoopsCodeCaseDelete($language, $tableName, $fieldId, $fieldMain)
1173
    {
1174
        $ccFieldId = $this->tdmcfile->getCamelCase($fieldId, false, true);
1175
        $ret = $this->getXoopsCodeGet($tableName, $ccFieldId, 'Obj', true);
1176
1177
        $reqOk = "\$_REQUEST['ok']";
1178
        $isset = $this->phpcode->getPhpCodeIsset($reqOk);
1179
        $xoopsSecurityCheck = $this->getXoopsCodeSecurityCheck();
1180
        $xoopsSecurityErrors = $this->getXoopsCodeSecurityErrors();
1181
        $implode = $this->phpcode->getPhpCodeImplode(', ', $xoopsSecurityErrors);
1182
        $redirectHeaderErrors = $this->getXoopsCodeRedirectHeader($tableName, '', '3', $implode);
1183
1184
        $delete = $this->getXoopsCodeDelete($tableName, $tableName, 'Obj', true);
1185
        $condition = $this->phpcode->getPhpCodeConditions('!'.$xoopsSecurityCheck, '', '', $redirectHeaderErrors);
1186
1187
        $redirectHeaderLanguage = $this->getXoopsCodeRedirectHeader($tableName, '', '3', "{$language}FORM_DELETE_OK");
1188
        $htmlErrors = $this->getXoopsCodeHtmlErrors($tableName, true);
1189
        $internalElse = $this->getXoopsCodeTplAssign('error', $htmlErrors);
1190
        $condition .= $this->phpcode->getPhpCodeConditions($delete, '', '', $redirectHeaderLanguage, $internalElse);
1191
1192
        $mainElse = $this->getXoopsCodeXoopsConfirm($tableName, $language, $fieldId, $fieldMain);
1193
        $ret .= $this->phpcode->getPhpCodeConditions($isset, ' && ', "1 == {$reqOk}", $condition, $mainElse);
1194
1195
        return $ret;
1196
    }
1197
1198
    /*
1199
    *  @public function getTopicGetVar
1200
    *  @param $lpFieldName
1201
    *  @param $rpFieldName
1202
    *  @param $tableName
1203
    *  @param $tableNameTopic
1204
    *  @param $fieldNameParent
1205
    *  @param $fieldNameTopic
1206
    *  @return string
1207
    */
1208
    public function getTopicGetVar($lpFieldName, $rpFieldName, $tableName, $tableNameTopic, $fieldNameParent, $fieldNameTopic)
1209
    {
1210
        $ret = <<<EOT
1211
\t\t// Get Var {$fieldNameParent}
1212
\t\t\${$rpFieldName} =& \${$tableNameTopic}Handler->get(\${$tableName}All[\$i]->getVar('{$fieldNameParent}'));
1213
\t\t\${$lpFieldName}['{$rpFieldName}'] = \${$rpFieldName}->getVar('{$fieldNameTopic}');\n
1214
EOT;
1215
1216
        return $ret;
1217
    }
1218
1219
    /*
1220
    *  @public function getUploadImageGetVar
1221
    *  @param $lpFieldName
1222
    *  @param $rpFieldName
1223
    *  @param $tableName
1224
    *  @param $fieldName
1225
    *  @return string
1226
    */
1227
    public function getUploadImageGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName)
1228
    {
1229
        $ret = <<<EOT
1230
\t\t// Get Var {$fieldName}
1231
\t\t\${$fieldName} = \${$tableName}All[\$i]->getVar('{$fieldName}');
1232
\t\t\$upload_image = \${$fieldName} ? \${$fieldName} : 'blank.gif';
1233
\t\t\${$lpFieldName}['{$rpFieldName}'] = \$upload_image;\n
1234
EOT;
1235
1236
        return $ret;
1237
    }
1238
1239
    /*
1240
    *  @public function getXoopsCodeUpdate
1241
    *  @param $language
1242
    *  @param $tableName
1243
    *  @param $fieldId
1244
    *  @param $fieldName
1245
    *  @return string
1246
    */
1247
    public function getXoopsCodeUpdate($language, $tableName, $fieldId, $fieldName)
1248
    {
1249
        $ccFieldId = $this->tdmcfile->getCamelCase($fieldId, false, true);
1250
        $get = $this->getXoopsCodeGet($tableName, $ccFieldId, 'Obj', true);
0 ignored issues
show
Unused Code introduced by
$get is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1251
        $isset = $this->phpcode->getPhpCodeIsset($ccFieldId);
1252
        $get = $this->getXoopsCodeHandler($tableName, $fieldId, true);
1253
        $ret = $this->phpcode->getPhpCodeConditions($isset, '', '', $get);
1254
        $ret .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
1255
        $handlerInsert = $this->$this->getXoopsCodeHandler($tableName, $tableName, false, true, false, 'Obj');
1256
        $redirect = $this->getXoopsCodeRedirectHeader($tableName, '?op=list', 2, "{$language}FORM_UPDATE_OK");
1257
        $ret .= $this->phpcode->getPhpCodeConditions($handlerInsert, '', '', $redirect);
1258
1259
        $ret .= $this->getXoopsCodeTplAssign('error', "\${$tableName}Obj->getHtmlErrors()");
1260
1261
        return $this->phpcode->getPhpCodeCaseSwitch('update', $ret);
1262
    }
1263
1264
    /**
1265
     *  @public function getXoopsCodeSaveFieldId
1266
     *
1267
     *  @param $fields
1268
     *
1269
     *  @return string
1270
     */
1271
    public function getXoopsCodeSaveFieldId($fields)
1272
    {
1273
        foreach (array_keys($fields) as $f) {
1274
            if (0 == $f) {
1275
                $fieldId = $fields[$f]->getVar('field_name');
1276
            }
1277
        }
1278
1279
        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...
1280
    }
1281
1282
    /**
1283
     *  @public function getXoopsCodeSaveFieldMain
1284
     *
1285
     *  @param $fields
1286
     *
1287
     *  @return string
1288
     */
1289
    public function getXoopsCodeSaveFieldMain($fields)
1290
    {
1291
        foreach (array_keys($fields) as $f) {
1292
            if (1 == $fields[$f]->getVar('field_main')) {
1293
                $fieldMain = $fields[$f]->getVar('field_name');
1294
            }
1295
        }
1296
1297
        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...
1298
    }
1299
1300
    /**
1301
     *  @public function getXoopsCodeSaveElements
1302
     *
1303
     *  @param $moduleDirname
1304
     *  @param $tableName
1305
     *  @param $fields
1306
     *
1307
     *  @return string
1308
     */
1309
    public function getXoopsCodeSaveElements($moduleDirname, $tableName, $fields)
1310
    {
1311
        $ret = '';
1312
        foreach (array_keys($fields) as $f) {
1313
            $fieldName = $fields[$f]->getVar('field_name');
1314
            $fieldElement = $fields[$f]->getVar('field_element');
1315
            if (1 == $fields[$f]->getVar('field_main')) {
1316
                $fieldMain = $fieldName;
1317
            }
1318
            if ((5 == $fieldElement) || (6 == $fieldElement)) {
1319
                $ret .= $this->getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName);
1320
            } elseif (13 == $fieldElement) {
1321
                $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...
1322
            } elseif (14 == $fieldElement) {
1323
                $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...
1324
            } elseif (15 == $fieldElement) {
1325
                $ret .= $this->getXoopsCodeTextDateSelectSetVar($tableName, $fieldName);
1326
            } else {
1327
                $ret .= $this->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
1328
            }
1329
        }
1330
1331
        return $ret;
1332
    }
1333
1334
    /*
1335
    *  @public function getXoopsCodePageNav
1336
    *  @param $tableName
1337
    *
1338
    *  @return string
1339
    */
1340
    public function getXoopsCodePageNav($tableName)
1341
    {
1342
        $condition = $this->phpcode->getPhpCodeCommentLine('Display Navigation');
1343
        $condition .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/pagenav', true);
1344
        $condition .= "\$pagenav = new XoopsPageNav(\${$tableName}Count, \$limit, \$start, 'start', 'op=list&limit=' . \$limit);\n";
1345
        $condition .= $this->getXoopsCodeTplAssign('pagenav', '$pagenav->renderNav(4)');
1346
        $ret = $this->phpcode->getPhpCodeConditions("\${$tableName}Count", ' > ', '$limit', $condition, false, "\t\t");
1347
1348
        return $ret;
1349
    }
1350
}
1351