Completed
Pull Request — master (#144)
by Michael
03:13
created

ClassFiles   F

Complexity

Total Complexity 74

Size/Duplication

Total Lines 788
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 438
dl 0
loc 788
rs 2.48
c 0
b 0
f 0
wmc 74

22 Methods

Rating   Name   Duplication   Size   Complexity  
A getInitVar() 0 5 1
A getClassGetTableSolenameById() 0 23 1
A getClassCreate() 0 9 1
A __construct() 0 3 1
A getClassCounter() 0 17 1
A getToArrayInObject() 0 18 1
A getClassByCategory() 0 37 2
A getPermissionsInForm() 0 41 1
A getClassAll() 0 17 1
A getOptionsCheck() 0 28 3
A getClassObjectHandler() 0 32 3
B getValuesInObject() 0 59 9
A write() 0 6 1
A getFunctionForm() 0 57 4
B render() 0 40 6
B getClassObject() 0 65 8
A getClassCriteria() 0 18 1
A getInstance() 0 8 2
A getClassGet() 0 9 1
D getInitVars() 0 58 24
A getNewInsertId() 0 13 1
A getClassGetInsertId() 0 9 1

How to fix   Complexity   

Complex Class

Complex classes like ClassFiles 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.

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 ClassFiles, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace XoopsModules\Tdmcreate\Files\Classes;
4
5
use XoopsModules\Tdmcreate;
6
use XoopsModules\Tdmcreate\Files;
7
8
/*
9
 You may not change or alter any portion of this comment or credits
10
 of supporting developers from this source code or any supporting source code
11
 which is considered copyrighted (c) material of the original comment or credit authors.
12
13
 This program is distributed in the hope that it will be useful,
14
 but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
 */
17
/**
18
 * tc module.
19
 *
20
 * @copyright       XOOPS Project (https://xoops.org)
21
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
22
 *
23
 * @since           2.5.0
24
 *
25
 * @author          Txmod Xoops http://www.txmodxoops.org
26
 *
27
 * @version         $Id: ClassFiles.php 12258 2014-01-02 09:33:29Z timgno $
28
 */
29
30
/**
31
 * Class ClassFiles.
32
 */
33
class ClassFiles extends Files\CreateFile
34
{
35
    /**
36
     * @public function constructor
37
     *
38
     * @param null
39
     */
40
    public function __construct()
41
    {
42
        parent::__construct();
43
    }
44
45
    /**
46
     * @static function getInstance
47
     *
48
     * @param null
49
     *
50
     * @return ClassFiles
51
     */
52
    public static function getInstance()
53
    {
54
        static $instance = false;
55
        if (!$instance) {
56
            $instance = new self();
57
        }
58
59
        return $instance;
60
    }
61
62
    /**
63
     * @public function write
64
     *
65
     * @param string $module
66
     * @param string $table
67
     * @param mixed  $tables
68
     * @param        $filename
69
     */
70
    public function write($module, $table, $tables, $filename)
71
    {
72
        $this->setModule($module);
73
        $this->setTable($table);
74
        $this->setTables($tables);
75
        $this->setFileName($filename);
76
    }
77
78
    /**
79
     * @private function getInitVar
80
     *
81
     * @param string $fieldName
82
     * @param string $type
83
     *
84
     * @return string
85
     */
86
    private function getInitVar($fieldName, $type = 'INT')
87
    {
88
        $cc = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance();
89
90
        return $cc->getClassInitVar($fieldName, $type);
91
    }
92
93
    /**
94
     * @private function getInitVars
95
     *
96
     * @param array $fields
97
     *
98
     * @return string
99
     */
100
    private function getInitVars($fields)
101
    {
102
        $tc  = Tdmcreate\Helper::getInstance();
103
        $ret = '';
104
        // Creation of the initVar functions list
105
        foreach (array_keys($fields) as $f) {
106
            $fieldName = $fields[$f]->getVar('field_name');
107
            $fieldType = $fields[$f]->getVar('field_type');
108
            if ($fieldType > 1) {
109
                $fType         = $tc->getHandler('fieldtype')->get($fieldType);
110
                $fieldTypeName = $fType->getVar('fieldtype_name');
0 ignored issues
show
Unused Code introduced by
The assignment to $fieldTypeName is dead and can be removed.
Loading history...
111
            } else {
112
                $fieldType = null;
113
            }
114
            switch ($fieldType) {
115
                case 2:
116
                case 3:
117
                case 4:
118
                case 5:
119
                    $ret .= $this->getInitVar($fieldName, 'INT');
120
                    break;
121
                case 6:
122
                    $ret .= $this->getInitVar($fieldName, 'FLOAT');
123
                    break;
124
                case 7:
125
                case 8:
126
                    $ret .= $this->getInitVar($fieldName, 'DECIMAL');
127
                    break;
128
                case 10:
129
                    $ret .= $this->getInitVar($fieldName, 'ENUM');
130
                    break;
131
                case 11:
132
                    $ret .= $this->getInitVar($fieldName, 'EMAIL');
133
                    break;
134
                case 12:
135
                    $ret .= $this->getInitVar($fieldName, 'URL');
136
                    break;
137
                case 13:
138
                case 14:
139
                    $ret .= $this->getInitVar($fieldName, 'TXTBOX');
140
                    break;
141
                case 15:
142
                case 16:
143
                case 17:
144
                case 18:
145
                    $ret .= $this->getInitVar($fieldName, 'TXTAREA');
146
                    break;
147
                case 19:
148
                case 20:
149
                case 21:
150
                case 22:
151
                case 23:
152
                    $ret .= $this->getInitVar($fieldName, 'LTIME');
153
                    break;
154
            }
155
        }
156
157
        return $ret;
158
    }
159
160
    /**
161
     * @private  function getClassObject
162
     * @param $module
163
     * @param $table
164
     * @param $fields
165
     * @return string
166
     */
167
    private function getClassObject($module, $table, $fields)
168
    {
169
        $tc               = Tdmcreate\Helper::getInstance();
170
        $pc               = Tdmcreate\Files\CreatePhpCode::getInstance();
171
        $xc               = Tdmcreate\Files\CreateXoopsCode::getInstance();
172
        $moduleDirname    = $module->getVar('mod_dirname');
173
        $tableName        = $table->getVar('table_name');
174
        $ucfModuleDirname = ucfirst($moduleDirname);
175
        $ucfTableName     = ucfirst($tableName);
176
        $ret              = $pc->getPhpCodeDefined();
177
        $ret              .= $pc->getPhpCodeCommentMultiLine(['Class Object' => $ucfModuleDirname . $ucfTableName]);
178
        $cCl              = '';
179
180
        $fieldInForm      = [];
181
        $fieldElementId   = [];
182
        $optionsFieldName = [];
183
        foreach (array_keys($fields) as $f) {
184
            $fieldName        = $fields[$f]->getVar('field_name');
185
            $fieldElement     = $fields[$f]->getVar('field_element');
186
            $fieldInForm[]    = $fields[$f]->getVar('field_inform');
187
            $fieldElements    = $tc->getHandler('fieldelements')->get($fieldElement);
188
            $fieldElementId[] = $fieldElements->getVar('fieldelement_id');
189
            $rpFieldName      = $this->getRightString($fieldName);
190
            if (in_array(5, $fieldElementId)) {
191
                if (count($rpFieldName) % 5) {
0 ignored issues
show
Bug introduced by
$rpFieldName of type string is incompatible with the type Countable|array expected by parameter $var of count(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

191
                if (count(/** @scrutinizer ignore-type */ $rpFieldName) % 5) {
Loading history...
192
                    $optionsFieldName[] = "'" . $rpFieldName . "'";
193
                } else {
194
                    $optionsFieldName[] = "'" . $rpFieldName . "'\n";
195
                }
196
            }
197
            if ((0 == $f) && (1 == $table->getVar('table_autoincrement'))) {
198
                $fieldId = $fieldName;
199
            }
200
        }
201
        if (in_array(5, $fieldElementId) > 1) {
202
            $optionsElements = implode(', ', $optionsFieldName);
0 ignored issues
show
Unused Code introduced by
The assignment to $optionsElements is dead and can be removed.
Loading history...
203
            $cCl             .= $pc->getPhpCodeCommentMultiLine(['Options' => '']);
204
            $options         = $pc->getPhpCodeArray('', $optionsFieldName, true);
205
            $cCl             .= $pc->getPhpCodeVariableClass('private', 'options', $options);
206
        }
207
        unset($optionsFieldName);
208
209
        $cCl              .= $pc->getPhpCodeCommentMultiLine(['Constructor' => '', '' => '', '@param' => 'null'], "\t");
210
        $constr           = $this->getInitVars($fields);
211
        $cCl              .= $pc->getPhpCodeFunction('__construct', '', $constr, 'public ', false, "\t");
212
        $arrayGetInstance = ['@static function' => '&getInstance', '' => '', '@param' => 'null'];
213
        $cCl              .= $pc->getPhpCodeCommentMultiLine($arrayGetInstance, "\t");
214
        $getInstance      = $pc->getPhpCodeVariableClass('static', 'instance', 'false', "\t\t");
215
        $instance         = $xc->getXcEqualsOperator('$instance', 'new self()', null, false, "\t\t\t");
216
        $getInstance      .= $pc->getPhpCodeConditions('!$instance', '', '', $instance, false, "\t\t");
217
        $cCl              .= $pc->getPhpCodeFunction('getInstance', '', $getInstance, 'public static ', false, "\t");
218
219
        $cCl .= $this->getNewInsertId($table);
220
        $cCl .= $this->getFunctionForm($module, $table, $fieldId, $fieldInForm);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fieldId does not seem to be defined for all execution paths leading up to this point.
Loading history...
221
        $cCl .= $this->getValuesInObject($moduleDirname, $table, $fields);
222
        $cCl .= $this->getToArrayInObject($table);
223
224
        if (in_array(5, $fieldElementId) > 1) {
225
            $cCl .= $this->getOptionsCheck($table);
226
        }
227
        unset($fieldElementId);
228
229
        $ret .= $pc->getPhpCodeClass($ucfModuleDirname . $ucfTableName, $cCl, 'XoopsObject');
230
231
        return $ret;
232
    }
233
234
    /**
235
     * @private function getNewInsertId
236
     *
237
     * @param $table
238
     *
239
     * @return string
240
     */
241
    private function getNewInsertId($table)
242
    {
243
        $pc            = Tdmcreate\Files\CreatePhpCode::getInstance();
244
        $xc            = Tdmcreate\Files\CreateXoopsCode::getInstance();
245
        $tableName     = $table->getVar('table_name');
246
        $ucfTableName  = ucfirst($tableName);
247
        $ret           = $pc->getPhpCodeCommentMultiLine(['The new inserted' => '$Id', '@return' => 'inserted id'], "\t");
248
        $getInsertedId = $xc->getXcEqualsOperator('$newInsertedId', "\$GLOBALS['xoopsDB']->getInsertId()", null, false, "\t\t");
249
        $getInsertedId .= $this->getSimpleString('return $newInsertedId;', "\t\t");
250
251
        $ret .= $pc->getPhpCodeFunction('getNewInsertedId' . $ucfTableName, '', $getInsertedId, 'public ', false, "\t");
252
253
        return $ret;
254
    }
255
256
    /**
257
     * @private function getFunctionForm
258
     *
259
     * @param string $module
260
     * @param string $table
261
     *
262
     * @param        $fieldId
263
     * @param        $fieldInForm
264
     * @return string
265
     */
266
    private function getFunctionForm($module, $table, $fieldId, $fieldInForm)
267
    {
268
        $pc               = Tdmcreate\Files\CreatePhpCode::getInstance();
269
        $xc               = Tdmcreate\Files\CreateXoopsCode::getInstance();
270
        $cc               = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance();
271
        $fe               = ClassFormElements::getInstance();
272
        $moduleDirname    = $module->getVar('mod_dirname');
273
        $tableName        = $table->getVar('table_name');
274
        $tableSoleName    = $table->getVar('table_solename');
275
        $tableCategory    = $table->getVar('table_category');
276
        $tablePermissions = $table->getVar('table_permissions');
0 ignored issues
show
Unused Code introduced by
The assignment to $tablePermissions is dead and can be removed.
Loading history...
277
        $ucfTableName     = ucfirst($tableName);
278
        $stuTableSoleName = mb_strtoupper($tableSoleName);
279
        $language         = $this->getLanguage($moduleDirname, 'AM');
280
        $fe->initForm($module, $table);
281
        $ret              = $pc->getPhpCodeCommentMultiLine(['@public function' => 'getForm', '@param bool' => '$action', '@return' => 'XoopsThemeForm'], "\t");
282
        $action           = $xc->getXcEqualsOperator('$action', "\$_SERVER['REQUEST_URI']", null, false, "\t\t\t");
283
        $ucfModuleDirname = ucfirst($moduleDirname);
284
        $getForm          = $xc->getXcGetInstance((string)$moduleDirname, "{$ucfModuleDirname}Helper", "\t\t");
285
        //$getForm .= $pc->getPhpCodeConditions('$action', ' === ', 'false', $action, false, "\t\t");
286
        $getForm .= $pc->getPhpCodeConditions('false', ' === ', '$action', $action, false, "\t\t");
287
        $xUser   = $pc->getPhpCodeGlobals('xoopsUser');
288
        $xModule = $pc->getPhpCodeGlobals('xoopsModule');
289
        if (1 != $tableCategory/* && (1 == $tablePermissions)*/) {
290
            $getForm          .= $pc->getPhpCodeCommentLine('Permissions for', 'uploader', "\t\t");
291
            $getForm          .= $xc->getXcEqualsOperator('$gpermHandler', "xoops_getHandler('groupperm')", null, true, "\t\t");
292
            $getForm          .= $pc->getPhpCodeTernaryOperator('groups', 'is_object(' . $xUser . ')', $xUser . '->getGroups()', 'XOOPS_GROUP_ANONYMOUS', "\t\t");
293
            $checkRight       = $xc->getXcCheckRight('$gpermHandler', $permString = '', 32, '$groups', $xModule . '->getVar(\'mid\')', true);
294
            $ternaryOperator  = $pc->getPhpCodeTernaryOperator('permissionUpload', $checkRight, 'true', 'false', "\t\t\t\t");
295
            $permissionUpload = $xc->getXcEqualsOperator('$permissionUpload', 'true', null, false, "\t\t\t\t");
296
            $ternOperator     = $pc->getPhpCodeRemoveCarriageReturn($ternaryOperator, '', "\r");
297
            $if               = $pc->getPhpCodeConditions('!' . $xUser . '->isAdmin(' . $xModule . '->mid())', '', '', $ternaryOperator, $permissionUpload, "\t\t\t");
298
            $getForm          .= $pc->getPhpCodeConditions($xUser, '', '', $if, $ternOperator, "\t\t");
299
        }
300
        $getForm .= $pc->getPhpCodeCommentLine('Title', '', "\t\t");
301
        $getForm .= $pc->getPhpCodeTernaryOperator('title', '$this->isNew()', "sprintf({$language}{$stuTableSoleName}_ADD)", "sprintf({$language}{$stuTableSoleName}_EDIT)", "\t\t");
302
        $getForm .= $pc->getPhpCodeCommentLine('Get Theme', 'Form', "\t\t");
303
        $getForm .= $xc->getXcLoad('XoopsFormLoader', "\t\t");
304
        $getForm .= $cc->getClassXoopsThemeForm('form', 'title', 'form', 'action', 'post');
305
        $getForm .= $cc->getClassSetExtra('form', "'enctype=\"multipart/form-data\"'");
306
        $getForm .= $fe->renderElements();
307
308
        if (in_array(1, $fieldInForm)) {
309
            if (1 == $table->getVar('table_permissions')) {
310
                $getForm .= $this->getPermissionsInForm($moduleDirname, $fieldId);
311
            }
312
        }
313
        $getForm .= $pc->getPhpCodeCommentLine('To Save', '', "\t\t");
314
        //$hiddenSave = $cc->getClassXoopsFormHidden('', "'op'", "'save'", true, false);
315
        $getForm .= $cc->getClassAddElement('form', "new \XoopsFormHidden('op', 'save')");
316
        //$buttonSend = $cc->getClassXoopsFormButton('', '', 'submit', '_SUBMIT', 'submit', true);
317
        $getForm .= $cc->getClassAddElement('form', "new \XoopsFormButtonTray('', _SUBMIT, 'submit', '', false)");
318
        $getForm .= $this->getSimpleString('return $form;', "\t\t");
319
320
        $ret .= $pc->getPhpCodeFunction('getForm' . $ucfTableName, '$action = false', $getForm, 'public ', false, "\t");
321
322
        return $ret;
323
    }
324
325
    /**
326
     * @private function getPermissionsInForm
327
     *
328
     * @param string $moduleDirname
329
     * @param string $fieldId
330
     *
331
     * @return string
332
     */
333
    private function getPermissionsInForm($moduleDirname, $fieldId)
334
    {
335
        $pc                = Tdmcreate\Files\CreatePhpCode::getInstance();
336
        $xc                = Tdmcreate\Files\CreateXoopsCode::getInstance();
337
        $cc                = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance();
338
        $permissionApprove = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_APPROVE');
339
        $permissionSubmit  = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_SUBMIT');
340
        $permissionView    = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_VIEW');
341
        $ret               = $pc->getPhpCodeCommentLine('Permissions', '', "\t\t");
342
        $ret               .= $xc->getXcEqualsOperator('$memberHandler', "xoops_getHandler('member')", null, false, "\t\t");
343
        $ret               .= $xc->getXcEqualsOperator('$groupList', '$memberHandler->getGroupList()', null, false, "\t\t");
344
        $ret               .= $xc->getXcEqualsOperator('$gpermHandler', "xoops_getHandler('groupperm')", null, false, "\t\t");
345
        $ret               .= $pc->getPhpCodeArrayType('fullList', 'keys', 'groupList', null, false, "\t\t");
346
        $fId               = $xc->getXcGetVar('', 'this', $fieldId, true);
347
        $mId               = $xc->getXcGetVar('', "GLOBALS['xoopsModule']", 'mid', true);
348
        $ifGroups          = $xc->getXcGetGroupIds('groupsIdsApprove', 'gpermHandler', "'{$moduleDirname}_approve'", $fId, $mId, "\t\t\t");
349
        $ifGroups          .= $pc->getPhpCodeArrayType('groupsIdsApprove', 'values', 'groupsIdsApprove', null, false, "\t\t\t");
350
        $ifGroups          .= $cc->getClassXoopsFormCheckBox('groupsCanApproveCheckbox', $permissionApprove, 'groups_approve[]', '$groupsIdsApprove', false, "\t\t\t");
351
        $ifGroups          .= $xc->getXcGetGroupIds('groupsIdsSubmit', 'gpermHandler', "'{$moduleDirname}_submit'", $fId, $mId, "\t\t\t");
352
        $ifGroups          .= $pc->getPhpCodeArrayType('groupsIdsSubmit', 'values', 'groupsIdsSubmit', null, false, "\t\t\t");
353
        $ifGroups          .= $cc->getClassXoopsFormCheckBox('groupsCanSubmitCheckbox', $permissionSubmit, 'groups_submit[]', '$groupsIdsSubmit', false, "\t\t\t");
354
        $ifGroups          .= $xc->getXcGetGroupIds('groupsIdsView', 'gpermHandler', "'{$moduleDirname}_view'", $fId, $mId, "\t\t\t");
355
        $ifGroups          .= $pc->getPhpCodeArrayType('groupsIdsView', 'values', 'groupsIdsView', null, false, "\t\t\t");
356
        $ifGroups          .= $cc->getClassXoopsFormCheckBox('groupsCanViewCheckbox', $permissionView, 'groups_view[]', '$groupsIdsView', false, "\t\t\t");
357
358
        $else = $cc->getClassXoopsFormCheckBox('groupsCanApproveCheckbox', $permissionApprove, 'groups_approve[]', '$fullList', false, "\t\t\t");
359
        $else .= $cc->getClassXoopsFormCheckBox('groupsCanSubmitCheckbox', $permissionSubmit, 'groups_submit[]', '$fullList', false, "\t\t\t");
360
        $else .= $cc->getClassXoopsFormCheckBox('groupsCanViewCheckbox', $permissionView, 'groups_view[]', '$fullList', false, "\t\t\t");
361
362
        $ret .= $pc->getPhpCodeConditions('!$this->isNew()', null, null, $ifGroups, $else, "\t\t");
363
        $ret .= $pc->getPhpCodeCommentLine('To Approve', '', "\t\t");
364
        $ret .= $cc->getClassAddOptionArray('groupsCanApproveCheckbox', '$groupList');
365
        $ret .= $cc->getClassAddElement('form', '$groupsCanApproveCheckbox');
366
        $ret .= $pc->getPhpCodeCommentLine('To Submit', '', "\t\t");
367
        $ret .= $cc->getClassAddOptionArray('groupsCanSubmitCheckbox', '$groupList');
368
        $ret .= $cc->getClassAddElement('form', '$groupsCanSubmitCheckbox');
369
        $ret .= $pc->getPhpCodeCommentLine('To View', '', "\t\t");
370
        $ret .= $cc->getClassAddOptionArray('groupsCanViewCheckbox', '$groupList');
371
        $ret .= $cc->getClassAddElement('form', '$groupsCanViewCheckbox');
372
373
        return $ret;
374
    }
375
376
    /**
377
     * @private  function getValuesInObject
378
     *
379
     * @param $moduleDirname
380
     * @param $table
381
     * @param $fields
382
     * @return string
383
     * @internal param $null
384
     */
385
    private function getValuesInObject($moduleDirname, $table, $fields)
386
    {
387
        $tc               = Tdmcreate\Helper::getInstance();
388
        $pc               = Tdmcreate\Files\CreatePhpCode::getInstance();
389
        $xc               = Tdmcreate\Files\CreateXoopsCode::getInstance();
390
        $stuModuleDirname = mb_strtoupper($moduleDirname);
0 ignored issues
show
Unused Code introduced by
The assignment to $stuModuleDirname is dead and can be removed.
Loading history...
391
        $ucfTableName     = ucfirst($table->getVar('table_name'));
392
        $ret              = $pc->getPhpCodeCommentMultiLine(['Get' => 'Values', '@param null $keys' => '', '@param null $format' => '', '@param null$maxDepth' => '', '@return' => 'array'], "\t");
393
        $ucfModuleDirname = ucfirst($moduleDirname);
394
        $getValues        = $xc->getXcGetInstance((string)$moduleDirname, "{$ucfModuleDirname}Helper", "\t\t");
395
        $getValues        .= $xc->getXcEqualsOperator('$ret', '$this->getValues($keys, $format, $maxDepth)', null, false, "\t\t");
396
397
        foreach (array_keys($fields) as $f) {
398
            $fieldName    = $fields[$f]->getVar('field_name');
399
            $fieldElement = $fields[$f]->getVar('field_element');
400
            $rpFieldName  = $this->getRightString($fieldName);
401
            switch ($fieldElement) {
402
                case 3:
403
                case 4:
404
                    $getValues .= $pc->getPhpCodeStripTags("ret['{$rpFieldName}']", "\$this->getVar('{$fieldName}')", false, "\t\t");
405
                    break;
406
                case 8:
407
                    $getValues .= $xc->getXcUnameFromId("ret['{$rpFieldName}']", "\$this->getVar('{$fieldName}')", "\t\t");
408
                    break;
409
                case 15:
410
                    $getValues .= $xc->getXcFormatTimeStamp("ret['{$rpFieldName}']", "\$this->getVar('{$fieldName}')", 's', "\t\t");
411
                    break;
412
                default:
413
                    if ($fieldElement > 15) {
414
                        $fieldElements    = $tc->getHandler('fieldelements')->get($fieldElement);
415
                        $fieldElementMid  = $fieldElements->getVar('fieldelement_mid');
416
                        $fieldElementTid  = $fieldElements->getVar('fieldelement_tid');
417
                        $fieldElementName = $fieldElements->getVar('fieldelement_name');
418
                        $fieldNameDesc    = mb_substr($fieldElementName, mb_strrpos($fieldElementName, ':'), mb_strlen($fieldElementName));
0 ignored issues
show
Bug introduced by
It seems like $fieldElementName can also be of type array and array; however, parameter $str of mb_substr() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

418
                        $fieldNameDesc    = mb_substr(/** @scrutinizer ignore-type */ $fieldElementName, mb_strrpos($fieldElementName, ':'), mb_strlen($fieldElementName));
Loading history...
Bug introduced by
It seems like $fieldElementName can also be of type array and array; however, parameter $haystack of mb_strrpos() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

418
                        $fieldNameDesc    = mb_substr($fieldElementName, mb_strrpos(/** @scrutinizer ignore-type */ $fieldElementName, ':'), mb_strlen($fieldElementName));
Loading history...
Bug introduced by
It seems like $fieldElementName can also be of type array and array; however, parameter $str of mb_strlen() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

418
                        $fieldNameDesc    = mb_substr($fieldElementName, mb_strrpos($fieldElementName, ':'), mb_strlen(/** @scrutinizer ignore-type */ $fieldElementName));
Loading history...
419
                        $topicTableName   = str_replace(': ', '', mb_strtolower($fieldNameDesc));
420
                        $fieldsTopics     = $this->getTableFields($fieldElementMid, $fieldElementTid);
421
                        foreach (array_keys($fieldsTopics) as $g) {
422
                            $fieldNameTopic = $fieldsTopics[$g]->getVar('field_name');
423
                            if (1 == $fieldsTopics[$g]->getVar('field_main')) {
424
                                $fieldMainTopic = $fieldNameTopic;
425
                            }
426
                        }
427
                        $getHandlerVar = "\${$moduleDirname}->getHandler('{$topicTableName}')";
428
                        $getValues     .= $xc->getXcEqualsOperator("\${$topicTableName}", $getHandlerVar, null, false, "\t\t");
429
                        $getTopicTable = "\${$topicTableName}->get(\$this->getVar('{$fieldName}'))";
430
                        $getValues     .= $xc->getXcEqualsOperator("\${$topicTableName}Obj", $getTopicTable, null, false, "\t\t");
431
                        $fMainTopic    = "\${$topicTableName}Obj->getVar('{$fieldMainTopic}')";
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fieldMainTopic does not seem to be defined for all execution paths leading up to this point.
Loading history...
432
                        $getValues     .= $xc->getXcEqualsOperator("\$ret['{$rpFieldName}']", $fMainTopic, null, false, "\t\t");
433
                    } else {
434
                        $getValues .= $xc->getXcGetVar("ret['{$rpFieldName}']", 'this', $fieldName, false, "\t\t");
435
                    }
436
                    break;
437
            }
438
        }
439
        $getValues .= $this->getSimpleString('return $ret;', "\t\t");
440
441
        $ret .= $pc->getPhpCodeFunction('getValues' . $ucfTableName, '$keys = null, $format = null, $maxDepth = null', $getValues, 'public ', false, "\t");
442
443
        return $ret;
444
    }
445
446
    /**
447
     * @private function getToArrayInObject
448
     *
449
     * @param $table
450
     *
451
     * @return string
452
     */
453
    private function getToArrayInObject($table)
454
    {
455
        $pc           = Tdmcreate\Files\CreatePhpCode::getInstance();
456
        $xc           = Tdmcreate\Files\CreateXoopsCode::getInstance();
457
        $tableName    = $table->getVar('table_name');
458
        $ucfTableName = ucfirst($tableName);
459
        $multiLineCom = ['Returns an array representation' => 'of the object', '' => '', '@return' => 'array'];
460
        $ret          = $pc->getPhpCodeCommentMultiLine($multiLineCom, "\t");
461
462
        $getToArray = $pc->getPhpCodeArray('ret', [], false, "\t\t");
463
        $getToArray .= $xc->getXcEqualsOperator('$vars', '$this->getVars()', null, false, "\t\t");
464
        $foreach    = $xc->getXcGetVar('ret[$var]', 'this', '"{$var}"', false, "\t");
465
        $getToArray .= $pc->getPhpCodeForeach('vars', true, false, 'var', $foreach, "\t\t");
466
        $getToArray .= $this->getSimpleString('return $ret;', "\t\t");
467
468
        $ret .= $pc->getPhpCodeFunction('toArray' . $ucfTableName, '', $getToArray, 'public ', false, "\t");
469
470
        return $ret;
471
    }
472
473
    /**
474
     * @private function getOptionsCheck
475
     *
476
     * @param $table
477
     *
478
     * @return string
479
     */
480
    private function getOptionsCheck($table)
481
    {
482
        $tc           = Tdmcreate\Helper::getInstance();
483
        $pc           = Tdmcreate\Files\CreatePhpCode::getInstance();
484
        $tableName    = $table->getVar('table_name');
485
        $ucfTableName = ucfirst($tableName);
486
        $ret          = $pc->getPhpCodeCommentMultiLine(['Get' => 'Options'], "\t");
487
        $getOptions   = $pc->getPhpCodeArray('ret', [], false, "\t");
488
489
        $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
490
        foreach (array_keys($fields) as $f) {
491
            $fieldName    = $fields[$f]->getVar('field_name');
492
            $fieldElement = $fields[$f]->getVar('field_element');
493
494
            $fieldElements  = $tc->getHandler('fieldelements')->get($fieldElement);
495
            $fieldElementId = $fieldElements->getVar('fieldelement_id');
496
            $rpFieldName    = $this->getRightString($fieldName);
497
            if (5 == $fieldElementId) {
498
                $arrayPush  = $pc->getPhpCodeArrayType('ret', 'push', "'{$rpFieldName}'", null, false, "\t\t\t");
499
                $getOptions .= $pc->getPhpCodeConditions(1, ' == ', "\$this->getVar('{$fieldName}')", $arrayPush, false, "\t\t");
500
            }
501
        }
502
503
        $getOptions .= $this->getSimpleString('return $ret;', "\t\t");
504
505
        $ret .= $pc->getPhpCodeFunction('getOptions' . $ucfTableName, '', $getOptions, 'public ', false, "\t");
506
507
        return $ret;
508
    }
509
510
    /**
511
     * @public function getClassHandler
512
     *
513
     * @param string $moduleDirname
514
     * @param string $table
515
     * @param string $fieldId
516
     * @param        $fieldName
517
     * @param string $fieldMain
518
     *
519
     * @param        $fieldParent
520
     * @param        $fieldParentId
521
     * @param        $fieldElement
522
     * @return string
523
     */
524
    private function getClassObjectHandler($moduleDirname, $table, $fieldId, $fieldName, $fieldMain, $fieldParent, $fieldParentId, $fieldElement)
525
    {
526
        $pc               = Tdmcreate\Files\CreatePhpCode::getInstance();
527
        $tableName        = $table->getVar('table_name');
528
        $tableCategory    = $table->getVar('table_category');
0 ignored issues
show
Unused Code introduced by
The assignment to $tableCategory is dead and can be removed.
Loading history...
529
        $tableSoleName    = $table->getVar('table_solename');
530
        $tableFieldname   = $table->getVar('table_fieldname');
0 ignored issues
show
Unused Code introduced by
The assignment to $tableFieldname is dead and can be removed.
Loading history...
531
        $ucfModuleDirname = ucfirst($moduleDirname);
532
        $ucfTableName     = ucfirst($tableName);
533
        $ucfTableSoleName = ucfirst($tableSoleName);
0 ignored issues
show
Unused Code introduced by
The assignment to $ucfTableSoleName is dead and can be removed.
Loading history...
534
        $ucfModuleTable   = $ucfModuleDirname . $ucfTableName;
535
        $multiLineCom     = ['Class Object Handler' => $ucfModuleDirname . $ucfTableName];
536
        $ret              = $pc->getPhpCodeCommentMultiLine($multiLineCom);
537
538
        $cClh   = $pc->getPhpCodeCommentMultiLine(['Constructor' => '', '' => '', '@param' => 'null|XoopsDatabase $db'], "\t");
539
        $constr = "\t\tparent::__construct(\$db, '{$moduleDirname}_{$tableName}', '{$moduleDirname}{$tableName}', '{$fieldId}', '{$fieldMain}');\n";
540
541
        $cClh .= $pc->getPhpCodeFunction('__construct', 'XoopsDatabase $db', $constr, 'public ', false, "\t");
542
        $cClh .= $this->getClassCreate();
543
        $cClh .= $this->getClassGet();
544
        $cClh .= $this->getClassGetInsertId();
545
        $cClh .= $this->getClassCounter($tableName, $fieldId, $fieldMain);
546
        $cClh .= $this->getClassAll($tableName, $fieldId, $fieldMain);
547
        $cClh .= $this->getClassCriteria($tableName);
548
        if ($fieldElement > 15 && in_array(1, $fieldParentId)) {
549
            $cClh .= $this->getClassByCategory($moduleDirname, $tableName, $tableFieldName, $fieldId, $fieldName, $fieldMain, $fieldParent, $fieldElement);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $tableFieldName does not exist. Did you maybe mean $tableFieldname?
Loading history...
550
            $cClh .= $this->getClassGetTableSolenameById($moduleDirname, $table, $fieldMain);
551
        }
552
553
        $ret .= $pc->getPhpCodeClass("{$ucfModuleTable}Handler", $cClh, 'XoopsPersistableObjectHandler');
554
555
        return $ret;
556
    }
557
558
    /**
559
     * @public function getClassCreate
560
     *
561
     * @return string
562
     */
563
    private function getClassCreate()
564
    {
565
        $pc    = Tdmcreate\Files\CreatePhpCode::getInstance();
566
        $ret   = $pc->getPhpCodeCommentMultiLine(['@param bool' => '$isNew', '' => '', '@return' => 'object'], "\t");
567
        $cClhc = $this->getSimpleString('return parent::create($isNew);', "\t\t");
568
569
        $ret .= $pc->getPhpCodeFunction('create', '$isNew = true', $cClhc, 'public ', false, "\t");
570
571
        return $ret;
572
    }
573
574
    /**
575
     * @public function getClassGet
576
     *
577
     * @return string
578
     */
579
    private function getClassGet()
580
    {
581
        $pc    = Tdmcreate\Files\CreatePhpCode::getInstance();
582
        $ret   = $pc->getPhpCodeCommentMultiLine(['retrieve a' => 'field', '' => '', '@param int' => '$i field id', '@param null' => 'fields', '@return mixed reference to the' => '{@link Get} object'], "\t");
583
        $cClhg = $this->getSimpleString('return parent::get($i, $fields);', "\t\t");
584
585
        $ret .= $pc->getPhpCodeFunction('get', '$i = null, $fields = null', $cClhg, 'public ', false, "\t");
586
587
        return $ret;
588
    }
589
590
    /**
591
     * @public function getClassGetInsertId
592
     *
593
     * @return string
594
     */
595
    private function getClassGetInsertId()
596
    {
597
        $pc      = Tdmcreate\Files\CreatePhpCode::getInstance();
598
        $ret     = $pc->getPhpCodeCommentMultiLine(['get inserted' => 'id', '' => '', '@param' => 'null', '@return integer reference to the' => '{@link Get} object'], "\t");
599
        $cClhgid = $this->getSimpleString('return $this->db->getInsertId();', "\t\t");
600
601
        $ret .= $pc->getPhpCodeFunction('getInsertId', '', $cClhgid, 'public ', false, "\t");
602
603
        return $ret;
604
    }
605
606
    /**
607
     * @public function getClassCounter
608
     *
609
     * @param $tableName
610
     * @param $fieldId
611
     * @param $fieldMain
612
     *
613
     * @return string
614
     */
615
    private function getClassCounter($tableName, $fieldId, $fieldMain)
616
    {
617
        $pc           = Tdmcreate\Files\CreatePhpCode::getInstance();
618
        $xc           = Tdmcreate\Files\CreateXoopsCode::getInstance();
619
        $cc           = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance();
620
        $ucfTableName = ucfirst($tableName);
621
        $ret          = $pc->getPhpCodeCommentMultiLine(['Get Count ' . $ucfTableName => 'in the database', '@param int    $start' => '', '@param int    $limit' => '', '@param string $sort' => '', '@param string $order' => '', '@return' => 'int'], "\t");
622
623
        $critCount  = $cc->getClassCriteriaCompo('crCount' . $ucfTableName, "\t\t");
624
        $paramsCrit = "\$this->get{$ucfTableName}Criteria(\$crCount{$ucfTableName}, \$start, \$limit, \$sort, \$order)";
625
        $critCount  .= $xc->getXcEqualsOperator('$crCount' . $ucfTableName, $paramsCrit, null, false, "\t\t");
626
        $critCount  .= $this->getSimpleString("return parent::getCount(\$crCount{$ucfTableName});", "\t\t");
627
        $params     = "\$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC'";
628
629
        $ret .= $pc->getPhpCodeFunction('getCount' . $ucfTableName, $params, $critCount, 'public ', false, "\t");
630
631
        return $ret;
632
    }
633
634
    /**
635
     * @public function getClassAll
636
     *
637
     * @param $tableName
638
     * @param $fieldId
639
     * @param $fieldMain
640
     *
641
     * @return string
642
     */
643
    private function getClassAll($tableName, $fieldId, $fieldMain)
644
    {
645
        $pc           = Tdmcreate\Files\CreatePhpCode::getInstance();
646
        $xc           = Tdmcreate\Files\CreateXoopsCode::getInstance();
647
        $cc           = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance();
648
        $ucfTableName = ucfirst($tableName);
649
        $ret          = $pc->getPhpCodeCommentMultiLine(['Get All ' . $ucfTableName => 'in the database', '@param int    $start' => '', '@param int    $limit' => '', '@param string $sort' => '', '@param string $order' => '', '@return' => 'array'], "\t");
650
651
        $critAll    = $cc->getClassCriteriaCompo('crAll' . $ucfTableName, "\t\t");
652
        $paramsCrit = "\$this->get{$ucfTableName}Criteria(\$crAll{$ucfTableName}, \$start, \$limit, \$sort, \$order)";
653
        $critAll    .= $xc->getXcEqualsOperator('$crAll' . $ucfTableName, $paramsCrit, null, false, "\t\t");
654
        $critAll    .= $this->getSimpleString("return parent::getAll(\$crAll{$ucfTableName});", "\t\t");
655
        $params     = "\$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC'";
656
657
        $ret .= $pc->getPhpCodeFunction('getAll' . $ucfTableName, $params, $critAll, 'public ', false, "\t");
658
659
        return $ret;
660
    }
661
662
    /**
663
     * @public function getClassByCategory
664
     *
665
     * @param $moduleDirname
666
     * @param $tableName
667
     * @param $tableFieldName
668
     * @param $fieldId
669
     * @param $fieldName
670
     * @param $fieldMain
671
     * @param $fieldParent
672
     *
673
     * @param $fieldElement
674
     * @return string
675
     */
676
    private function getClassByCategory($moduleDirname, $tableName, $tableFieldName, $fieldId, $fieldName, $fieldMain, $fieldParent, $fieldElement)
0 ignored issues
show
Unused Code introduced by
The parameter $fieldParent is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

676
    private function getClassByCategory($moduleDirname, $tableName, $tableFieldName, $fieldId, $fieldName, $fieldMain, /** @scrutinizer ignore-unused */ $fieldParent, $fieldElement)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
677
    {
678
        $tc                = Tdmcreate\Helper::getInstance();
679
        $pc                = Tdmcreate\Files\CreatePhpCode::getInstance();
680
        $xc                = Tdmcreate\Files\CreateXoopsCode::getInstance();
681
        $cc                = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance();
682
        $ucfTableName      = ucfirst($tableName);
683
        $fieldElements     = $tc->getHandler('fieldelements')->get($fieldElement);
684
        $fieldElementMid   = $fieldElements->getVar('fieldelement_mid');
0 ignored issues
show
Unused Code introduced by
The assignment to $fieldElementMid is dead and can be removed.
Loading history...
685
        $fieldElementTid   = $fieldElements->getVar('fieldelement_tid');
0 ignored issues
show
Unused Code introduced by
The assignment to $fieldElementTid is dead and can be removed.
Loading history...
686
        $fieldElementName  = $fieldElements->getVar('fieldelement_name');
687
        $fieldNameDesc     = ucfirst(mb_substr($fieldElementName, mb_strrpos($fieldElementName, ':'), mb_strlen($fieldElementName)));
0 ignored issues
show
Bug introduced by
It seems like $fieldElementName can also be of type array and array; however, parameter $str of mb_substr() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

687
        $fieldNameDesc     = ucfirst(mb_substr(/** @scrutinizer ignore-type */ $fieldElementName, mb_strrpos($fieldElementName, ':'), mb_strlen($fieldElementName)));
Loading history...
Bug introduced by
It seems like $fieldElementName can also be of type array and array; however, parameter $haystack of mb_strrpos() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

687
        $fieldNameDesc     = ucfirst(mb_substr($fieldElementName, mb_strrpos(/** @scrutinizer ignore-type */ $fieldElementName, ':'), mb_strlen($fieldElementName)));
Loading history...
Bug introduced by
It seems like $fieldElementName can also be of type array and array; however, parameter $str of mb_strlen() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

687
        $fieldNameDesc     = ucfirst(mb_substr($fieldElementName, mb_strrpos($fieldElementName, ':'), mb_strlen(/** @scrutinizer ignore-type */ $fieldElementName)));
Loading history...
688
        $topicTableName    = str_replace(': ', '', $fieldNameDesc);
689
        $lcfTopicTableName = lcfirst($topicTableName);
690
691
        $ret = $pc->getPhpCodeCommentMultiLine(["Get All {$ucfTableName} By" => "{$fieldNameDesc} Id", '@param int    $start' => '', '@param int    $limit' => '', '@param string $sort' => '', '@param string $order' => '', '@return' => 'array'], "\t");
692
693
        $critAll = $xc->getXcEqualsOperator('$gpermHandler', "xoops_getHandler('groupperm')", null, true, "\t\t");
694
        $param1  = "'{$moduleDirname}_view'";
695
        $param2  = "\$GLOBALS['xoopsUser']->getGroups()";
696
        $param3  = "\$GLOBALS['xoopsModule']->getVar('mid')";
697
        $critAll .= $xc->getXcGetItemIds($lcfTopicTableName, 'gpermHandler', $param1, $param2, $param3, "\t\t");
698
        $critAll .= $cc->getClassCriteriaCompo('crAll' . $ucfTableName, "\t\t");
699
700
        if (false !== mb_strpos($fieldName, 'status')) {
701
            $crit    = $cc->getClassCriteria('', "'{$fieldName}'", '0', "'!='", true);
702
            $critAll .= $cc->getClassAdd('crAll' . $ucfTableName, $crit, "\t\t");
703
        }
704
        $paramsCritAll = "\$this->get{$ucfTableName}Criteria(\$crAll{$ucfTableName}, \$start, \$limit, \$sort, \$order)";
705
        $critAll       .= $xc->getXcEqualsOperator('$crAll' . $ucfTableName, $paramsCritAll, null, false, "\t\t");
706
707
        $critAll .= $this->getSimpleString("return parent::getAll(\$crAll{$ucfTableName});", "\t\t");
708
        $params  = "\${$tableFieldName}Id, \$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC'";
709
710
        $ret .= $pc->getPhpCodeFunction("getAll{$ucfTableName}By{$fieldNameDesc}Id" . $ucfTableName, $params, $critAll, 'public ', false, "\t");
711
712
        return $ret;
713
    }
714
715
    /**
716
     * @public function getClassCriteria
717
     *
718
     * @param $tableName
719
     * @return string
720
     */
721
    private function getClassCriteria($tableName)
722
    {
723
        $pc           = Tdmcreate\Files\CreatePhpCode::getInstance();
724
        $cc           = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance();
725
        $ucfTableName = ucfirst($tableName);
726
        $ret          = $pc->getPhpCodeCommentMultiLine(['Get' => 'Criteria ' . $ucfTableName, '@param       ' => "\$cr{$ucfTableName}", '@param int    $start' => '', '@param int    $limit' => '', '@param string $sort' => '', '@param string $order' => '', '@return' => 'int'], "\t");
727
728
        $paramsAllCriteria = "\$cr{$ucfTableName}, \$start, \$limit, \$sort, \$order";
729
730
        $critSets = $cc->getClassSetStart('cr' . $ucfTableName, 'start', "\t\t");
731
        $critSets .= $cc->getClassSetLimit('cr' . $ucfTableName, 'limit', "\t\t");
732
        $critSets .= $cc->getClassSetSort('cr' . $ucfTableName, 'sort', "\t\t");
733
        $critSets .= $cc->getClassSetOrder('cr' . $ucfTableName, 'order', "\t\t");
734
        $critSets .= $this->getSimpleString("return \$cr{$ucfTableName};", "\t\t");
735
736
        $ret .= $pc->getPhpCodeFunction("get{$ucfTableName}Criteria", $paramsAllCriteria, $critSets, 'private ', false, "\t");
737
738
        return $ret;
739
    }
740
741
    /**
742
     * @public function getClassGetTableSolenameById
743
     *
744
     * @param $moduleDirname
745
     * @param $table
746
     *
747
     * @param $fieldMain
748
     * @return string
749
     */
750
    private function getClassGetTableSolenameById($moduleDirname, $table, $fieldMain)
751
    {
752
        $pc               = Tdmcreate\Files\CreatePhpCode::getInstance();
753
        $xc               = Tdmcreate\Files\CreateXoopsCode::getInstance();
754
        $tableName        = $table->getVar('table_name');
755
        $tableSoleName    = $table->getVar('table_solename');
756
        $ucfTableSoleName = ucfirst($tableSoleName);
757
        $ccTableSoleName  = $this->getCamelCase($tableSoleName, true);
758
        $ret              = $pc->getPhpCodeCommentMultiLine(['Returns the' => $ucfTableSoleName . ' from id', '' => '', '@return' => 'string'], "\t");
759
        $soleName         = $xc->getXcEqualsOperator("\${$tableSoleName}Id", "(int)( \${$tableSoleName}Id )", null, false, "\t\t");
760
        $soleName         .= $xc->getXcEqualsOperator("\${$tableSoleName}", "''", null, false, "\t\t");
761
762
        $contentIf = $xc->getXoopsHandlerLine($moduleDirname, $tableName, "\t\t\t");
763
        $contentIf .= $xc->getXcGet($tableName, "\${$tableSoleName}Id", 'Obj', true, false, "\t\t\t");
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type string expected by parameter $handler of XoopsModules\Tdmcreate\F...teXoopsCode::getXcGet(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

763
        $contentIf .= $xc->getXcGet($tableName, "\${$tableSoleName}Id", 'Obj', /** @scrutinizer ignore-type */ true, false, "\t\t\t");
Loading history...
764
        $getVar    = $xc->getXcGetVar($ccTableSoleName, "{$tableSoleName}Obj", $fieldMain, false, "\t\t\t\t");
765
        $contentIf .= $pc->getPhpCodeConditions("is_object( \${$tableSoleName}Obj )", '', '', $getVar, false, "\t\t\t");
766
767
        $soleName .= $pc->getPhpCodeConditions("\${$tableSoleName}Id", ' > ', '0', $contentIf = null, false, "\t\t");
768
        $soleName .= $this->getSimpleString("return \${$tableSoleName};", "\t\t");
769
770
        $ret .= $pc->getPhpCodeFunction("get{$ucfTableSoleName}FromId", "\${$tableSoleName}Id", $soleName, 'public ', false, "\t");
771
772
        return $ret;
773
    }
774
775
    /**
776
     * @public function render
777
     * @param null
778
     *
779
     * @return bool|string
780
     */
781
    public function render()
782
    {
783
        $tc             = Tdmcreate\Helper::getInstance();
784
        $module         = $this->getModule();
785
        $table          = $this->getTable();
786
        $filename       = $this->getFileName();
787
        $tableName      = $table->getVar('table_name');
0 ignored issues
show
Unused Code introduced by
The assignment to $tableName is dead and can be removed.
Loading history...
788
        $tableFieldName = $table->getVar('table_fieldname');
0 ignored issues
show
Unused Code introduced by
The assignment to $tableFieldName is dead and can be removed.
Loading history...
789
        $tableCategory  = $table->getVar('table_category');
0 ignored issues
show
Unused Code introduced by
The assignment to $tableCategory is dead and can be removed.
Loading history...
790
        $moduleDirname  = $module->getVar('mod_dirname');
791
        $fields         = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
792
        $fieldInForm    = [];
793
        $fieldParentId  = [];
794
        $fieldElementId = [];
795
        $fieldParent    = null;
796
        foreach (array_keys($fields) as $f) {
797
            $fieldName       = $fields[$f]->getVar('field_name');
798
            $fieldInForm[]   = $fields[$f]->getVar('field_inform');
799
            $fieldParentId[] = $fields[$f]->getVar('field_parent');
800
            if ((0 == $f) && (1 == $table->getVar('table_autoincrement'))) {
801
                $fieldId = $fieldName; // $fieldId = fields parameter index field
802
            }
803
            if (1 == $fields[$f]->getVar('field_main')) {
804
                $fieldMain = $fieldName; // $fieldMain = fields parameter main field
805
            }
806
            if (1 == $fields[$f]->getVar('field_parent')) {
807
                $fieldParent = $fieldName; // $fieldParent = fields parameter parent field
808
            }
809
            $fieldElement = $fields[$f]->getVar('field_element');
810
811
            $fieldElements    = $tc->getHandler('fieldelements')->get($fieldElement);
812
            $fieldElementId[] = $fieldElements->getVar('fieldelement_id');
813
        }
814
        $content = $this->getHeaderFilesComments($module, $filename);
815
        $content .= $this->getClassObject($module, $table, $fields);
816
        $content .= $this->getClassObjectHandler($moduleDirname, $table, $fieldId, $fieldName, $fieldMain, $fieldParent, $fieldParentId, $fieldElement);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fieldName seems to be defined by a foreach iteration on line 796. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
Comprehensibility Best Practice introduced by
The variable $fieldElement seems to be defined by a foreach iteration on line 796. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
Comprehensibility Best Practice introduced by
The variable $fieldId does not seem to be defined for all execution paths leading up to this point.
Loading history...
Comprehensibility Best Practice introduced by
The variable $fieldMain does not seem to be defined for all execution paths leading up to this point.
Loading history...
817
818
        $this->create($moduleDirname, 'class', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
819
820
        return $this->renderFile();
821
    }
822
}
823