Passed
Branch master (31be8b)
by Gino
03:04
created

ClassFiles::getClassEnd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
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: ClassFiles.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
25
/**
26
 * Class ClassFiles.
27
 */
28
class ClassFiles extends TDMCreateFile
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 string
32
    */
33
    private $classcode = null;
34
35
    /*
36
    * @var string
37
    */
38
    private $tdmcfile = null;
39
40
    /*
41
    * @var string
42
    */
43
    private $formelements = null;
44
45
    /*
46
    *  @public function constructor
47
    *  @param null
48
    */
49
    /**
50
     *
51
     */
52
    public function __construct()
53
    {
54
        parent::__construct();
55
        $this->phpcode = TDMCreatePhpCode::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like \TDMCreatePhpCode::getInstance() of type object<TDMCreatePhpCode> is incompatible with the declared type string of property $phpcode.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
56
        $this->tdmcfile = TDMCreateFile::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like \TDMCreateFile::getInstance() of type object<TDMCreateFile> is incompatible with the declared type string of property $tdmcfile.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
57
        $this->tdmcreate = TDMCreateHelper::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like \TDMCreateHelper::getInstance() of type object<TDMCreateHelper> is incompatible with the declared type string of property $tdmcreate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
Bug introduced by
The property tdmcreate cannot be accessed from this context as it is declared private in class TDMCreateFile.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
58
        $this->classcode = ClassXoopsCode::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like \ClassXoopsCode::getInstance() of type object<ClassXoopsCode> is incompatible with the declared type string of property $classcode.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
59
        $this->formelements = ClassFormElements::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like \ClassFormElements::getInstance() of type object<ClassFormElements> is incompatible with the declared type string of property $formelements.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
60
    }
61
62
    /*
63
    *  @static function &getInstance
64
    *  @param null
65
    */
66
    /**
67
     * @return ClassFiles
68
     */
69
    public static function &getInstance()
70
    {
71
        static $instance = false;
72
        if (!$instance) {
73
            $instance = new self();
74
        }
75
76
        return $instance;
77
    }
78
79
    /*
80
    *  @public function write
81
    *  @param string $module
82
    *  @param string $table
83
    *  @param mixed $tables
84
    */
85
    /**
86
     * @param $module
87
     * @param $table
88
     * @param $tables
89
     */
90
    public function write($module, $table, $tables)
91
    {
92
        $this->setModule($module);
93
        $this->setTable($table);
94
        $this->setTables($tables);
95
    }
96
97
    /*
98
    *  @private function getInitVar
99
    *  @param string $fieldName
100
    *  @param string $type
101
    */
102
    /**
103
     * @param        $fieldName
104
     * @param string $type
105
     *
106
     * @return string
107
     */
108
    private function getInitVar($fieldName, $type = 'INT')
109
    {
110
        return $this->classcode->getClassInitVar($fieldName, $type);
0 ignored issues
show
Bug introduced by
The method getClassInitVar cannot be called on $this->classcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
111
    }
112
113
    /*
114
    *  @private function getInitVars
115
    *  @param array $fields
116
    */
117
    /**
118
     * @param $fields
119
     *
120
     * @return string
121
     */
122
    private function getInitVars($fields)
123
    {
124
        $ret = '';
125
        // Creation of the initVar functions list
126
        foreach (array_keys($fields) as $f) {
127
            $fieldName = $fields[$f]->getVar('field_name');
128
            $fieldType = $fields[$f]->getVar('field_type');
129
            if ($fieldType > 1) {
130
                $fType = $this->tdmcreate->getHandler('fieldtype')->get($fieldType);
0 ignored issues
show
Bug introduced by
The property tdmcreate cannot be accessed from this context as it is declared private in class TDMCreateFile.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Bug introduced by
The method getHandler cannot be called on $this->tdmcreate (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
131
                $fieldTypeName = $fType->getVar('fieldtype_name');
0 ignored issues
show
Unused Code introduced by
$fieldTypeName 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...
132
            } else {
133
                $fieldType = null;
134
            }
135
            switch ($fieldType) {
136
                case 2:
137
                case 3:
138
                case 4:
139
                case 5:
140
                    $ret .= $this->getInitVar($fieldName, 'INT');
141
                    break;
142
                case 6:
143
                    $ret .= $this->getInitVar($fieldName, 'FLOAT');
144
                    break;
145
                case 7:
146
                case 8:
147
                    $ret .= $this->getInitVar($fieldName, 'DECIMAL');
148
                    break;
149
                case 10:
150
                    $ret .= $this->getInitVar($fieldName, 'ENUM');
151
                    break;
152
                case 11:
153
                    $ret .= $this->getInitVar($fieldName, 'EMAIL');
154
                    break;
155
                case 12:
156
                    $ret .= $this->getInitVar($fieldName, 'URL');
157
                    break;
158
                case 13:
159
                case 14:
160
                    $ret .= $this->getInitVar($fieldName, 'TXTBOX');
161
                    break;
162
                case 15:
163
                case 16:
164
                case 17:
165
                case 18:
166
                    $ret .= $this->getInitVar($fieldName, 'TXTAREA');
167
                    break;
168
                case 19:
169
                case 20:
170
                case 21:
171
                case 22:
172
                case 23:
173
                    $ret .= $this->getInitVar($fieldName, 'LTIME');
174
                    break;
175
            }
176
        }
177
178
        return $ret;
179
    }
180
181
    /*
182
    *  @private function getHeadClass
183
    *  @param string $moduleDirname
184
    *  @param string $tableName
185
    *  @param array $fields
186
    */
187
    /**
188
     * @param $moduleDirname
189
     * @param $tableName
190
     * @param $fields
191
     *
192
     * @return string
193
     */
194
    private function getHeadClass($moduleDirname, $tableName, $fields)
195
    {
196
        $ucfModuleDirname = ucfirst($moduleDirname);
197
        $ucfTableName = ucfirst($tableName);
198
        $ret = $this->phpcode->getPhpCodeDefined();
0 ignored issues
show
Bug introduced by
The method getPhpCodeDefined cannot be called on $this->phpcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
199
        $ret .= $this->phpcode->getPhpCodeCommentMultiLine(array('Class Object ' => $ucfModuleDirname.$ucfTableName));
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->phpcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
200
        $contentClass = $this->phpcode->getPhpCodeCommentMultiLine(array('@var ' => 'mixed'));
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->phpcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
201
        $contentClass .= $this->phpcode->getPhpCodeVariableClass('private', $moduleDirname);
0 ignored issues
show
Bug introduced by
The method getPhpCodeVariableClass cannot be called on $this->phpcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
202
        $ret .= <<<EOT
203
class {$ucfModuleDirname}{$ucfTableName} extends XoopsObject
204
{
205
    /*
206
    * @var mixed
207
    */
208
    private \${$moduleDirname} = null;\n\n
209
EOT;
210
        $fieldElementId = array();
211
        $optionsFieldName = array();
212
        foreach (array_keys($fields) as $f) {
213
            $fieldName = $fields[$f]->getVar('field_name');
214
            $fieldElement = $fields[$f]->getVar('field_element');
215
            $fieldElements = $this->tdmcreate->getHandler('fieldelements')->get($fieldElement);
0 ignored issues
show
Bug introduced by
The property tdmcreate cannot be accessed from this context as it is declared private in class TDMCreateFile.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Bug introduced by
The method getHandler cannot be called on $this->tdmcreate (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
216
            $fieldElementId[] = $fieldElements->getVar('fieldelement_id');
217
            $rpFieldName = $this->tdmcfile->getRightString($fieldName);
0 ignored issues
show
Bug introduced by
The method getRightString cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
218
            if (in_array(5, $fieldElementId)) {
219
                if (count($rpFieldName) % 5) {
220
                    $optionsFieldName[] = "'".$rpFieldName."'";
221
                } else {
222
                    $optionsFieldName[] = "'".$rpFieldName."'\n";
223
                }
224
            }
225
        }
226
        if (in_array(5, $fieldElementId) > 1) {
227
            $optionsElements = implode(', ', $optionsFieldName);
228
            $ret .= <<<EOT
229
	/**
230
     * Options
231
     */
232
	public \$options = array({$optionsElements});\n\n
233
EOT;
234
        }
235
        unset($fieldElementId, $optionsFieldName);
236
        $ret .= <<<EOT
237
	/*
238
     * Constructor
239
     *
240
     * @param null
241
     */
242
    public function __construct()
243
    {
244
        \$this->{$moduleDirname} = {$ucfModuleDirname}Helper::getInstance();
245
{$this->getInitVars($fields)}\t}\n
246
    /*
247
    *  @static function &getInstance
248
    *  @param null
249
    */
250
    public static function &getInstance()
251
    {
252
        static \$instance = false;
253
        if(!\$instance) {
254
            \$instance = new self();
255
        }
256
        return \$instance;
257
    }\n\n
258
EOT;
259
260
        return $ret;
261
    }
262
263
    /*
264
    *  @private function getHeadInForm
265
    *  @param string $module
266
    *  @param string $table
267
    */
268
    /**
269
     * @param $module
270
     * @param $table
271
     *
272
     * @return string
273
     */
274
    private function getHeadInForm($module, $table)
275
    {
276
        $moduleDirname = $module->getVar('mod_dirname');
277
        $tableName = $table->getVar('table_name');
278
        $tableSoleName = $table->getVar('table_solename');
279
        $tablePermissions = $table->getVar('table_permissions');
280
        $ucfTableName = ucfirst($tableName);
281
        $stuTableSoleName = strtoupper($tableSoleName);
282
        $language = $this->getLanguage($moduleDirname, 'AM');
283
        $this->formelements->initForm($module, $table);
0 ignored issues
show
Bug introduced by
The method initForm cannot be called on $this->formelements (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
284
        $ret = <<<EOT
285
    /*
286
     * Get form
287
     *
288
     * @param mixed \$action
289
     */
290
    public function getForm{$ucfTableName}(\$action = false)
291
    {
292
        if(\$action === false) {
293
            \$action = \$_SERVER['REQUEST_URI'];
294
        }\n
295
EOT;
296
        if (1 == $tablePermissions) {
297
            $ret .= <<<EOT
298
		global \$xoopsUser, \$xoopsModule;
299
		// Permissions for uploader
300
        \$gpermHandler =& xoops_gethandler('groupperm');
301
        \$groups = is_object(\$xoopsUser) ? \$xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
302
        if(\$xoopsUser) {
303
            if( !\$xoopsUser->isAdmin(\$xoopsModule->mid()) ) {
304
                \$permissionUpload =(\$gpermHandler->checkRight('{$moduleDirname}_ac', 32, \$groups, \$xoopsModule->getVar('mid'))) ? true : false ;
305
            }else{
306
                \$permissionUpload = true;
307
            }
308
        }else{
309
            \$permissionUpload = (\$gpermHandler->checkRight('{$moduleDirname}_ac', 32, \$groups, \$xoopsModule->getVar('mid'))) ? true : false ;
310
        }\n
311
EOT;
312
        }
313
        $ret .= <<<EOT
314
		// Title
315
        \$title = \$this->isNew() ? sprintf({$language}{$stuTableSoleName}_ADD) : sprintf({$language}{$stuTableSoleName}_EDIT);
316
        // Get Theme Form
317
        xoops_load('XoopsFormLoader');
318
        \$form = new XoopsThemeForm(\$title, 'form', \$action, 'post', true);
319
        \$form->setExtra('enctype="multipart/form-data"');\n
320
EOT;
321
322
        if (0 == $table->getVar('table_category')) {
323
            $ret .= <<<EOT
324
		// {$ucfTableName} handler
325
		//\${$tableName}Handler =& \$this->{$moduleDirname}->getHandler('{$tableName}');\n
326
EOT;
327
        }
328
329
        $ret .= <<<EOT
330
{$this->formelements->renderElements()}
0 ignored issues
show
Bug introduced by
The method renderElements cannot be called on $this->formelements (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
331
EOT;
332
333
        return $ret;
334
    }
335
336
    /*
337
    *  @private function getPermissionsInForm
338
    *  @param string $moduleDirname
339
    *  @param string $fieldId
340
    */
341
    /**
342
     * @param $moduleDirname
343
     * @param $fieldId
344
     *
345
     * @return string
346
     */
347
    private function getPermissionsInForm($moduleDirname, $fieldId)
348
    {
349
        $permissionApprove = $this->tdmcfile->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_APPROVE');
0 ignored issues
show
Bug introduced by
The method getLanguage cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
350
        $permissionSubmit = $this->tdmcfile->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_SUBMIT');
0 ignored issues
show
Bug introduced by
The method getLanguage cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
351
        $permissionView = $this->tdmcfile->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_VIEW');
0 ignored issues
show
Bug introduced by
The method getLanguage cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
352
        $ret = <<<EOT
353
        // Permissions
354
        \$memberHandler = & xoops_gethandler( 'member' );
355
        \$groupList     = \$memberHandler->getGroupList();
356
        \$gpermHandler  = &xoops_gethandler( 'groupperm' );
357
        \$fullList = array_keys( \$groupList );
358
        global \$xoopsModule;
359
        if( !\$this->isNew() ) {
360
            \$groupsIdsApprove = \$gpermHandler->getGroupIds( '{$moduleDirname}_approve', \$this->getVar( '{$fieldId}' ), \$xoopsModule->getVar( 'mid' ) );
361
            \$groupsIdsSubmit = \$gpermHandler->getGroupIds( '{$moduleDirname}_submit', \$this->getVar( '{$fieldId}' ), \$xoopsModule->getVar( 'mid' ) );
362
            \$groupsIdsView = \$gpermHandler->getGroupIds( '{$moduleDirname}_view', \$this->getVar( '{$fieldId}' ), \$xoopsModule->getVar( 'mid' ) );
363
            \$groupsIdsApprove = array_values( \$groupsIdsApprove );
364
            \$groupsCanApproveCheckbox = new XoopsFormCheckBox( {$permissionApprove}, 'groups_approve[]', \$groupsIdsApprove );
365
            \$groupsIdsSubmit = array_values( \$groupsIdsSubmit );
366
            \$groupsCanSubmitCheckbox = new XoopsFormCheckBox( {$permissionSubmit}, 'groups_submit[]', \$groupsIdsSubmit );
367
            \$groupsIdsView = array_values( \$groupsIdsView );
368
            \$groupsCanViewCheckbox = new XoopsFormCheckBox( {$permissionView}, 'groups_view[]', \$groupsIdsView );
369
        } else {
370
            \$groupsCanApproveCheckbox = new XoopsFormCheckBox( {$permissionApprove}, 'groups_approve[]', \$fullList );
371
            \$groupsCanSubmitCheckbox = new XoopsFormCheckBox( {$permissionSubmit}, 'groups_submit[]', \$fullList );
372
            \$groupsCanViewCheckbox = new XoopsFormCheckBox( {$permissionView}, 'groups_view[]', \$fullList );
373
        }
374
        // For approve
375
        \$groupsCanApproveCheckbox->addOptionArray( \$groupList );
376
        \$form->addElement( \$groupsCanApproveCheckbox );
377
        // For submit
378
        \$groupsCanSubmitCheckbox->addOptionArray( \$groupList );
379
        \$form->addElement( \$groupsCanSubmitCheckbox );
380
        // For view
381
        \$groupsCanViewCheckbox->addOptionArray( \$groupList );
382
        \$form->addElement( \$groupsCanViewCheckbox );\n\n
383
EOT;
384
385
        return $ret;
386
    }
387
388
    /*
389
    *  @private function getFootInForm
390
    *  @param null
391
    */
392
    /**
393
     * @return string
394
     */
395
    private function getFootInForm()
396
    {
397
        $ret = <<<EOT
398
        // Send
399
        \$form->addElement(new XoopsFormHidden('op', 'save'));
400
        \$form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
401
        return \$form;
402
    }\n\n
403
EOT;
404
405
        return $ret;
406
    }
407
408
    /*
409
    *  @private function getToArray
410
    *  @param null
411
    */
412
    /**
413
     * @return string
414
     */
415
    private function getValuesInForm($moduleDirname, $table, $fields)
416
    {
417
        $stuModuleDirname = strtoupper($moduleDirname);
0 ignored issues
show
Unused Code introduced by
$stuModuleDirname 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...
418
        $ucfTableName = ucfirst($table->getVar('table_name'));
419
        $ret = <<<EOT
420
	/**
421
     * Get Values
422
     */
423
	public function getValues{$ucfTableName}(\$keys = null, \$format = null, \$maxDepth = null)
424
    {
425
		\$ret = parent::getValues(\$keys, \$format, \$maxDepth);\n
426
EOT;
427
        foreach (array_keys($fields) as $f) {
428
            $fieldName = $fields[$f]->getVar('field_name');
429
            $fieldElement = $fields[$f]->getVar('field_element');
430
            $rpFieldName = $this->tdmcfile->getRightString($fieldName);
0 ignored issues
show
Bug introduced by
The method getRightString cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
431
            switch ($fieldElement) {
432
                case 3:
433
                case 4:
434
                    $ret .= <<<EOT
435
		\$ret['{$rpFieldName}'] = strip_tags(\$this->getVar('{$fieldName}'));\n
436
EOT;
437
                break;
438
                case 8:
439
                    $ret .= <<<EOT
440
		\$ret['{$rpFieldName}'] = XoopsUser::getUnameFromId(\$this->getVar('{$fieldName}'));\n
441
EOT;
442
                break;
443
                /*case 10:
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
444
                    $ret .= <<<EOT
445
        \$ret['{$rpFieldName}'] = XOOPS_ICONS32_URL .'/'. \$this->getVar('{$fieldName}');\n
446
EOT;
447
                break;
448
                case 13:
449
                    $ret .= <<<EOT
450
        \$ret['{$rpFieldName}'] = {$stuModuleDirname}_UPLOAD_IMAGE_URL .'/'. \$this->getVar('{$fieldName}');\n
451
EOT;
452
                break;*/
453
                case 15:
454
                    $ret .= <<<EOT
455
		\$ret['{$rpFieldName}'] = formatTimeStamp(\$this->getVar('{$fieldName}'));\n
456
EOT;
457
                break;
458
                default:
459
                    if ($fieldElement > 15) {
460
                        $fieldElements = $this->tdmcreate->getHandler('fieldelements')->get($fieldElement);
0 ignored issues
show
Bug introduced by
The property tdmcreate cannot be accessed from this context as it is declared private in class TDMCreateFile.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Bug introduced by
The method getHandler cannot be called on $this->tdmcreate (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
461
                        $fieldElementMid = $fieldElements->getVar('fieldelement_mid');
462
                        $fieldElementTid = $fieldElements->getVar('fieldelement_tid');
463
                        $fieldElementName = $fieldElements->getVar('fieldelement_name');
464
                        $fieldNameDesc = substr($fieldElementName, strrpos($fieldElementName, ':'), strlen($fieldElementName));
465
                        $topicTableName = str_replace(': ', '', strtolower($fieldNameDesc));
466
                        $fieldsTopics = $this->tdmcfile->getTableFields($fieldElementMid, $fieldElementTid);
0 ignored issues
show
Bug introduced by
The method getTableFields cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
467
                        foreach (array_keys($fieldsTopics) as $f) {
468
                            $fieldNameTopic = $fieldsTopics[$f]->getVar('field_name');
469
                            if (1 == $fieldsTopics[$f]->getVar('field_main')) {
470
                                $fieldMainTopic = $fieldNameTopic;
471
                            }
472
                        }
473
                        $ret .= <<<EOT
474
		\$ret['{$rpFieldName}'] = \$this->{$moduleDirname}->getHandler('{$topicTableName}')->get(\$this->getVar('{$fieldName}'))->getVar('{$fieldMainTopic}');\n
0 ignored issues
show
Bug introduced by
The variable $fieldMainTopic 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...
475
EOT;
476
                    } else {
477
                        $ret .= <<<EOT
478
		\$ret['{$rpFieldName}'] = \$this->getVar('{$fieldName}');\n
479
EOT;
480
                    }
481
                break;
482
            }
483
        }
484
        $ret .= <<<EOT
485
486
		return \$ret;
487
    }\n\n
488
EOT;
489
490
        return $ret;
491
    }
492
    /*
493
    *  @private function getToArray
494
    *  @param $table
495
    */
496
    /**
497
     * @return string
498
     */
499
    private function getToArrayInForm($table)
500
    {
501
        $tableName = $table->getVar('table_name');
502
        $ucfTableName = ucfirst($tableName);
503
        $ret = <<<EOT
504
    /**
505
     * Returns an array representation of the object
506
     *
507
     * @return array
508
     **/
509
    public function toArray{$ucfTableName}()
510
    {
511
        \$ret = array();
512
        \$vars = \$this->getVars();
513
        foreach( array_keys( \$vars ) as \$var ) {
514
            \$ret[\$var] = \$this->getVar( \$var );
515
        }
516
        return \$ret;
517
    }
518
}\n\n
519
EOT;
520
521
        return $ret;
522
    }
523
524
    /*
525
    *  @private function getOptionsCheck
526
    *  @param $table
527
    */
528
    /**
529
     * @return string
530
     */
531
    private function getOptionsCheck($table)
532
    {
533
        $tableName = $table->getVar('table_name');
534
        $ucfTableName = ucfirst($tableName);
535
        $ret = <<<EOT
536
    /**
537
     * Get Options
538
     */
539
	public function getOptions{$ucfTableName}()
540
    {
541
        \$ret = array();\n
542
EOT;
543
        $fields = $this->tdmcfile->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
0 ignored issues
show
Bug introduced by
The method getTableFields cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
544
        foreach (array_keys($fields) as $f) {
545
            $fieldName = $fields[$f]->getVar('field_name');
546
            $fieldElement = $fields[$f]->getVar('field_element');
547
            //
548
            $fieldElements = $this->tdmcreate->getHandler('fieldelements')->get($fieldElement);
0 ignored issues
show
Bug introduced by
The property tdmcreate cannot be accessed from this context as it is declared private in class TDMCreateFile.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Bug introduced by
The method getHandler cannot be called on $this->tdmcreate (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
549
            $fieldElementId = $fieldElements->getVar('fieldelement_id');
550
            $rpFieldName = $this->tdmcfile->getRightString($fieldName);
0 ignored issues
show
Bug introduced by
The method getRightString cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
551
            if (5 == $fieldElementId) {
552
                $ret .= <<<EOT
553
		if(1 == \$this->getVar('{$fieldName}')) {
554
            array_push(\$ret, '{$rpFieldName}');
555
        }\n
556
EOT;
557
            }
558
        }
559
        $ret .= <<<EOT
560
        return \$ret;
561
    }
562
}\n\n
563
EOT;
564
565
        return $ret;
566
    }
567
568
    /*
569
    *  @public function getClassHandler
570
    *  @param string $moduleDirname
571
    *  @param string $tableName
572
    *  @param string $fieldId
573
    *  @param string $fieldMain
574
    */
575
    /**
576
     * @param $moduleDirname
577
     * @param $tableName
578
     * @param $tableCategory
579
     * @param $tableFieldname
580
     * @param $fieldId
581
     * @param $fieldMain
582
     *
583
     * @return string
584
     */
585
    private function getClassObjectHandler($moduleDirname, $table, $fieldId, $fieldMain)
586
    {
587
        $tableName = $table->getVar('table_name');
588
        $tableCategory = $table->getVar('table_category');
0 ignored issues
show
Unused Code introduced by
$tableCategory 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...
589
        $tableSoleName = $table->getVar('table_solename');
590
        $tableFieldname = $table->getVar('table_fieldname');
0 ignored issues
show
Unused Code introduced by
$tableFieldname 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...
591
        $ucfModuleDirname = ucfirst($moduleDirname);
592
        $ucfTableName = ucfirst($tableName);
593
        $ucfTableSoleName = ucfirst($tableSoleName);
0 ignored issues
show
Unused Code introduced by
$ucfTableSoleName 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...
594
        $ucfModuleTable = $ucfModuleDirname.$ucfTableName;
595
        $ret = <<<EOT
596
/*
597
 * Class Object Handler {$ucfModuleDirname}{$ucfTableName}
598
 */
599
class {$ucfModuleTable}Handler extends XoopsPersistableObjectHandler
600
{
601
    /*
602
    * @var mixed
603
    */
604
    private \${$moduleDirname} = null;
605
	/*
606
     * Constructor
607
     *
608
     * @param string \$db
609
     */
610
    public function __construct(&\$db)
611
    {
612
        parent::__construct(\$db, '{$moduleDirname}_{$tableName}', '{$moduleDirname}{$tableName}', '{$fieldId}', '{$fieldMain}');
613
		\$this->{$moduleDirname} = {$ucfModuleDirname}Helper::getInstance();
614
    }\n\n
615
EOT;
616
617
        return $ret;
618
    }
619
620
    /**
621
     *  @public function getClassCreate
622
     *
623
     *  @return string
624
     */
625
    private function getClassCreate()
626
    {
627
        $ret = <<<EOT
628
	/**
629
     * @param bool \$isNew
630
     *
631
     * @return object
632
     */
633
    public function &create(\$isNew = true)
634
    {
635
        return parent::create(\$isNew);
636
    }\n\n
637
EOT;
638
639
        return $ret;
640
    }
641
642
    /**
643
     *  @public function getClassGet
644
     *
645
     *  @return string
646
     */
647
    private function getClassGet()
648
    {
649
        $ret = <<<EOT
650
	/**
651
     * retrieve a field
652
     *
653
     * @param int \$i field id
654
     * @return mixed reference to the {@link TDMCreateFields} object
655
     */
656
    public function &get(\$i = null, \$fields = null)
657
    {
658
        return parent::get(\$i, \$fields);
659
    }\n\n
660
EOT;
661
662
        return $ret;
663
    }
664
665
    /**
666
     *  @public function getClassGetInsertId
667
     *
668
     *  @return string
669
     */
670
    private function getClassGetInsertId()
671
    {
672
        $ret = <<<EOT
673
    /**
674
     * get inserted id
675
     *
676
     * @param null
677
     * @return integer reference to the {@link TDMCreateFields} object
678
     */
679
    public function &getInsertId()
680
    {
681
        return \$this->db->getInsertId();
682
    }\n\n
683
EOT;
684
685
        return $ret;
686
    }
687
688
    /**
689
     *  @public function getClassGetIds
690
     *
691
     *  @return string
692
     */
693
    private function getClassGetIds()
694
    {
695
        $ret = <<<EOT
696
	/**
697
     * get IDs of objects matching a condition
698
     *
699
     * @param object \$criteria {@link CriteriaElement} to match
700
     * @return array of object IDs
701
     */
702
    public function &getIds(\$criteria)
703
    {
704
        return parent::getIds(\$criteria);
705
    }\n\n
706
EOT;
707
708
        return $ret;
709
    }
710
711
    /**
712
     *  @public function getClassInsert
713
     *
714
     *  @return string
715
     */
716
    private function getClassInsert()
717
    {
718
        $ret = <<<EOT
719
	/**
720
     * insert a new field in the database
721
     *
722
     * @param object \$field reference to the {@link TDMCreateFields} object
723
     * @param bool \$force
724
     *
725
     * @return bool FALSE if failed, TRUE if already present and unchanged or successful
726
     */
727
    public function &insert(&\$field, \$force = false)
728
    {
729
        if(!parent::insert(\$field, \$force)) {
730
            return false;
731
        }
732
        return true;
733
    }\n\n
734
EOT;
735
736
        return $ret;
737
    }
738
739
    /**
740
     *  @public function getClassCounter
741
     *
742
     *  @param $tableName
743
     *  @param $fieldId
744
     *  @param $fieldMain
745
     *
746
     *  @return string
747
     */
748
    private function getClassCounter($tableName, $fieldId, $fieldMain)
749
    {
750
        $ucfTableName = ucfirst($tableName);
751
        $ret = <<<EOT
752
    /**
753
     * Get Count {$ucfTableName}
754
     */
755
    public function getCount{$ucfTableName}(\$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC')
756
    {
757
        \$criteriaCount{$ucfTableName} = new CriteriaCompo();
758
        \$criteriaCount{$ucfTableName} = \$this->get{$ucfTableName}Criteria(\$criteriaCount{$ucfTableName}, \$start, \$limit, \$sort, \$order);
759
		return parent::getCount(\$criteriaCount{$ucfTableName});
760
    }\n\n
761
EOT;
762
763
        return $ret;
764
    }
765
766
    /**
767
     *  @public function getClassAll
768
     *
769
     *  @param $tableName
770
     *  @param $fieldId
771
     *  @param $fieldMain
772
     *
773
     *  @return string
774
     */
775
    private function getClassAll($tableName, $fieldId, $fieldMain)
776
    {
777
        $ucfTableName = ucfirst($tableName);
778
        $ret = <<<EOT
779
	/**
780
     * Get All {$ucfTableName}
781
     */
782
	public function getAll{$ucfTableName}(\$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC')
783
    {
784
        \$criteriaAll{$ucfTableName} = new CriteriaCompo();
785
        \$criteriaAll{$ucfTableName} = \$this->get{$ucfTableName}Criteria(\$criteriaAll{$ucfTableName}, \$start, \$limit, \$sort, \$order);
786
        return parent::getAll(\$criteriaAll{$ucfTableName});
787
    }\n\n
788
EOT;
789
790
        return $ret;
791
    }
792
793
    /**
794
     *  @public function getClassByCategory
795
     *
796
     *  @param $tableName
797
     *  @param $fieldId
798
     *  @param $fieldMain
799
     *  @param $fieldParent
800
     *
801
     *  @return string
802
     */
803
    private function getClassByCategory($moduleDirname, $tableName, $tableFieldName, $fieldId, $fieldName, $fieldMain, $fieldParent, $fieldElement)
804
    {
805
        $ucfTableName = ucfirst($tableName);
806
        $fieldElements = $this->tdmcreate->getHandler('fieldelements')->get($fieldElement);
0 ignored issues
show
Bug introduced by
The property tdmcreate cannot be accessed from this context as it is declared private in class TDMCreateFile.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Bug introduced by
The method getHandler cannot be called on $this->tdmcreate (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
807
        $fieldElementMid = $fieldElements->getVar('fieldelement_mid');
0 ignored issues
show
Unused Code introduced by
$fieldElementMid 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...
808
        $fieldElementTid = $fieldElements->getVar('fieldelement_tid');
0 ignored issues
show
Unused Code introduced by
$fieldElementTid 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...
809
        $fieldElementName = $fieldElements->getVar('fieldelement_name');
810
        $fieldNameDesc = ucfirst(substr($fieldElementName, strrpos($fieldElementName, ':'), strlen($fieldElementName)));
811
        $topicTableName = str_replace(': ', '', $fieldNameDesc);
812
        $lcfTopicTableName = lcfirst($topicTableName);
813
        $ret = <<<EOT
814
	/**
815
     * Get All {$ucfTableName} By {$fieldNameDesc} Id
816
     */
817
	public function getAll{$ucfTableName}By{$fieldNameDesc}Id(\${$tableFieldName}Id, \$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC')
818
    {
819
        \$gpermHandler =& xoops_gethandler('groupperm');
820
		\${$lcfTopicTableName} = \$gpermHandler->getItemIds('{$moduleDirname}_view', \$GLOBALS['xoopsUser']->getGroups(), \$GLOBALS['xoopsModule']->getVar('mid') );
821
822
		\$criteriaAll{$ucfTableName} = new CriteriaCompo();\n
823
EOT;
824
        if (strstr($fieldName, 'status')) {
825
            $ret .= <<<EOT
826
		\$criteriaAll{$ucfTableName}->add(new Criteria('{$fieldName}', 0, '!='));\n
827
EOT;
828
        }
829
        $ret .= <<<EOT
830
		\$criteriaAll{$ucfTableName}->add(new Criteria('{$fieldParent}', \${$tableFieldName}Id));
831
		\$criteriaAll{$ucfTableName}->add(new Criteria('{$fieldId}', '(' . implode(',', \${$lcfTopicTableName}) . ')','IN'));
832
        \$criteriaAll{$ucfTableName} = \$this->get{$ucfTableName}Criteria(\$criteriaAll{$ucfTableName}, \$start, \$limit, \$sort, \$order);
833
        return parent::getAll(\$criteriaAll{$ucfTableName});
834
    }\n\n
835
EOT;
836
837
        return $ret;
838
    }
839
840
    /**
841
     *  @public function getClassCriteria
842
     *
843
     *  @param $tableName
844
     *  @param $fieldId
845
     *  @param $fieldMain
846
     *
847
     *  @return string
848
     */
849
    private function getClassCriteria($tableName)
850
    {
851
        $ucfTableName = ucfirst($tableName);
852
        $ret = <<<EOT
853
	/**
854
     * Get {$ucfTableName} Criteria.
855
     */
856
    private function get{$ucfTableName}Criteria(\$criteria{$ucfTableName}, \$start, \$limit, \$sort, \$order)
857
    {
858
        \$criteria{$ucfTableName}->setStart(\$start);
859
        \$criteria{$ucfTableName}->setLimit(\$limit);
860
        \$criteria{$ucfTableName}->setSort(\$sort);
861
        \$criteria{$ucfTableName}->setOrder(\$order);
862
863
        return \$criteria{$ucfTableName};
864
    }\n\n
865
EOT;
866
867
        return $ret;
868
    }
869
870
    /**
871
     *  @public function getClassGetTableSolenameById
872
     *
873
     *  @param $moduleDirname
874
     *  @param $table
875
     *
876
     *  @return string
877
     */
878
    private function getClassGetTableSolenameById($moduleDirname, $table, $fieldMain)
879
    {
880
        $tableName = $table->getVar('table_name');
881
        $tableSoleName = $table->getVar('table_solename');
882
        $ucfTableSoleName = ucfirst($tableSoleName);
883
        $ret = <<<EOT
884
	/**
885
     * Returns the {$ucfTableSoleName} from id
886
     *
887
     * @return string
888
     **/
889
    public function get{$ucfTableSoleName}FromId(\${$tableSoleName}Id)
890
    {
891
        \${$tableSoleName}Id = (int) ( \${$tableSoleName}Id );
892
        \${$tableSoleName} = '';
893
        if(\${$tableSoleName}Id > 0) {
894
            \${$tableName}Handler = \$this->{$moduleDirname}->getHandler( '{$tableName}' );
895
            \${$tableSoleName}Obj = & \${$tableName}Handler->get( \${$tableSoleName}Id );
896
            if(is_object( \${$tableSoleName}Obj )) {
897
                \${$tableSoleName} = \${$tableSoleName}Obj->getVar( '{$fieldMain}' );
898
            }
899
        }
900
        return \${$tableSoleName};
901
    }\n
902
EOT;
903
904
        return $ret;
905
    }
906
907
    /**
908
     *  @public function getClassEnd
909
     */
910
    private function getClassEnd()
911
    {
912
        $ret = <<<EOT
913
}\n
914
EOT;
915
916
        return $ret;
917
    }
918
919
    /*
920
    *  @public function renderFile
921
    *  @param string $filename
922
    */
923
    /**
924
     * @param $filename
925
     *
926
     * @return bool|string
927
     */
928
    public function renderFile($filename)
929
    {
930
        $module = $this->getModule();
931
        $table = $this->getTable();
932
        $tableName = $table->getVar('table_name');
933
        $tableFieldName = $table->getVar('table_fieldname');
934
        $tableCategory = $table->getVar('table_category');
0 ignored issues
show
Unused Code introduced by
$tableCategory 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...
935
        $moduleDirname = $module->getVar('mod_dirname');
936
        $fields = $this->tdmcfile->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
0 ignored issues
show
Bug introduced by
The method getTableFields cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
937
        $fieldInForm = array();
938
        $fieldParentId = array();
939
        $fieldElementId = array();
940
        foreach (array_keys($fields) as $f) {
941
            $fieldName = $fields[$f]->getVar('field_name');
942
            $fieldInForm[] = $fields[$f]->getVar('field_inform');
943
            $fieldParentId[] = $fields[$f]->getVar('field_parent');
944
            if ((0 == $f) && (1 == $table->getVar('table_autoincrement'))) {
945
                $fieldId = $fieldName; // $fieldId = fields parameter index field
946
            }
947
            if (1 == $fields[$f]->getVar('field_main')) {
948
                $fieldMain = $fieldName; // $fieldMain = fields parameter main field
949
            }
950
            if (1 == $fields[$f]->getVar('field_parent')) {
951
                $fieldParent = $fieldName; // $fieldParent = fields parameter parent field
952
            }
953
            $fieldElement = $fields[$f]->getVar('field_element');
954
            //
955
            $fieldElements = $this->tdmcreate->getHandler('fieldelements')->get($fieldElement);
0 ignored issues
show
Bug introduced by
The property tdmcreate cannot be accessed from this context as it is declared private in class TDMCreateFile.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Bug introduced by
The method getHandler cannot be called on $this->tdmcreate (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
956
            $fieldElementId[] = $fieldElements->getVar('fieldelement_id');
957
        }
958
        $content = $this->getHeaderFilesComments($module, $filename);
959
        $content .= $this->getHeadClass($moduleDirname, $tableName, $fields);
960
        if (in_array(1, $fieldInForm)) {
961
            $content .= $this->getHeadInForm($module, $table);
962
            if (1 == $table->getVar('table_permissions')) {
963
                $content .= $this->getPermissionsInForm($moduleDirname, $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...
964
            }
965
            $content .= $this->getFootInForm();
966
        }
967
        $content .= $this->getValuesInForm($moduleDirname, $table, $fields);
968
        $content .= $this->getToArrayInForm($table);
969
        if (in_array(5, $fieldElementId) > 1) {
970
            $content .= $this->getOptionsCheck($table);
971
        }
972
        $content .= $this->getClassObjectHandler($moduleDirname, $table, $fieldId, $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...
973
        $content .= $this->getClassCreate();
974
        $content .= $this->getClassGet();
975
        $content .= $this->getClassGetInsertId();
976
        $content .= $this->getClassGetIds();
977
        $content .= $this->getClassInsert();
978
        $content .= $this->getClassCounter($tableName, $fieldId, $fieldMain);
979
        $content .= $this->getClassAll($tableName, $fieldId, $fieldMain);
980
        $content .= $this->getClassCriteria($tableName);
981
        if (in_array(1, $fieldParentId) && $fieldElement > 15) {
982
            $content .= $this->getClassByCategory($moduleDirname, $tableName, $tableFieldName, $fieldId, $fieldName, $fieldMain, $fieldParent, $fieldElement);
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...
Bug introduced by
The variable $fieldParent 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 variable $fieldElement 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...
983
            $content .= $this->getClassGetTableSolenameById($moduleDirname, $table, $fieldMain);
984
        }
985
        $content .= $this->getClassEnd();
986
        $this->tdmcfile->create($moduleDirname, 'class', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
0 ignored issues
show
Bug introduced by
The method create cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
987
988
        return $this->tdmcfile->renderFile();
0 ignored issues
show
Bug introduced by
The method renderFile cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
989
    }
990
}
991