Completed
Pull Request — master (#86)
by Gino
03:42
created

ClassFiles::getClassGetIds()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 7
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
 * tc 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 $cc = null;
34
35
    /*
36
    * @var string
37
    */
38
    private $pc = null;
39
40
    /*
41
    * @var string
42
    */
43
    private $xc = null;
44
45
    /*
46
    * @var string
47
    */
48
    private $tf = null;
49
50
    /*
51
    * @var string
52
    */
53
    private $fe = null;
54
55
    /*
56
    * @var string
57
    */
58
    private $tc = null;
59
60
    /*
61
    *  @public function constructor
62
    *  @param null
63
    */
64
    /**
65
     *
66
     */
67
    public function __construct()
68
    {
69
        parent::__construct();
70
        $this->pc = 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 $pc.

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...
71
        $this->tf = 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 $tf.

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...
72
        $this->tc = 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 $tc.

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...
73
        $this->xc = TDMCreateXoopsCode::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like \TDMCreateXoopsCode::getInstance() of type object<TDMCreateXoopsCode> is incompatible with the declared type string of property $xc.

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...
74
        $this->cc = 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 $cc.

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...
75
        $this->fe = 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 $fe.

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...
76
    }
77
78
    /*
79
    *  @static function &getInstance
80
    *  @param null
81
    */
82
    /**
83
     * @return ClassFiles
84
     */
85
    public static function &getInstance()
86
    {
87
        static $instance = false;
88
        if (!$instance) {
89
            $instance = new self();
90
        }
91
92
        return $instance;
93
    }
94
95
    /*
96
    *  @public function write
97
    *  @param string $module
98
    *  @param string $table
99
    *  @param mixed $tables
100
    */
101
    /**
102
     * @param $module
103
     * @param $table
104
     * @param $tables
105
     */
106
    public function write($module, $table, $tables, $filename)
107
    {
108
        $this->setModule($module);
109
        $this->setTable($table);
110
        $this->setTables($tables);
111
        $this->setFileName($filename);
112
    }
113
114
    /*
115
    *  @private function getInitVar
116
    *  @param string $fieldName
117
    *  @param string $type
118
    */
119
    /**
120
     * @param        $fieldName
121
     * @param string $type
122
     *
123
     * @return string
124
     */
125
    private function getInitVar($fieldName, $type = 'INT')
126
    {
127
        return $this->cc->getClassInitVar($fieldName, $type);
0 ignored issues
show
Bug introduced by
The method getClassInitVar cannot be called on $this->cc (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...
128
    }
129
130
    /*
131
    *  @private function getInitVars
132
    *  @param array $fields
133
    */
134
    /**
135
     * @param $fields
136
     *
137
     * @return string
138
     */
139
    private function getInitVars($fields)
140
    {
141
        $ret = '';
142
        // Creation of the initVar functions list
143
        foreach (array_keys($fields) as $f) {
144
            $fieldName = $fields[$f]->getVar('field_name');
145
            $fieldType = $fields[$f]->getVar('field_type');
146
            if ($fieldType > 1) {
147
                $fType = $this->tc->getHandler('fieldtype')->get($fieldType);
0 ignored issues
show
Bug introduced by
The method getHandler cannot be called on $this->tc (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...
148
                $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...
149
            } else {
150
                $fieldType = null;
151
            }
152
            switch ($fieldType) {
153
                case 2:
154
                case 3:
155
                case 4:
156
                case 5:
157
                    $ret .= $this->getInitVar($fieldName, 'INT');
158
                    break;
159
                case 6:
160
                    $ret .= $this->getInitVar($fieldName, 'FLOAT');
161
                    break;
162
                case 7:
163
                case 8:
164
                    $ret .= $this->getInitVar($fieldName, 'DECIMAL');
165
                    break;
166
                case 10:
167
                    $ret .= $this->getInitVar($fieldName, 'ENUM');
168
                    break;
169
                case 11:
170
                    $ret .= $this->getInitVar($fieldName, 'EMAIL');
171
                    break;
172
                case 12:
173
                    $ret .= $this->getInitVar($fieldName, 'URL');
174
                    break;
175
                case 13:
176
                case 14:
177
                    $ret .= $this->getInitVar($fieldName, 'TXTBOX');
178
                    break;
179
                case 15:
180
                case 16:
181
                case 17:
182
                case 18:
183
                    $ret .= $this->getInitVar($fieldName, 'TXTAREA');
184
                    break;
185
                case 19:
186
                case 20:
187
                case 21:
188
                case 22:
189
                case 23:
190
                    $ret .= $this->getInitVar($fieldName, 'LTIME');
191
                    break;
192
            }
193
        }
194
195
        return $ret;
196
    }
197
198
    /*
199
    *  @private function getClassObject
200
    *  @param $moduleDirname
201
    *  @param $tableName
202
    *  @param $fields   
203
    *
204
    *  @return string
205
    */
206
    private function getClassObject($module, $table, $fields)
207
    {
208
        $moduleDirname = $module->getVar('mod_dirname');
209
        $tableName = $table->getVar('table_name');
210
        $ucfModuleDirname = ucfirst($moduleDirname);
211
        $ucfTableName = ucfirst($tableName);
212
        $ret = $this->pc->getPhpCodeDefined();
0 ignored issues
show
Bug introduced by
The method getPhpCodeDefined cannot be called on $this->pc (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...
213
        $ret .= $this->pc->getPhpCodeCommentMultiLine(array('Class Object' => $ucfModuleDirname.$ucfTableName));
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->pc (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...
214
        $cCl = $this->pc->getPhpCodeCommentMultiLine(array('@var' => 'mixed'), "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->pc (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...
215
        $cCl .= $this->pc->getPhpCodeVariableClass('private', $moduleDirname, 'null', "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeVariableClass cannot be called on $this->pc (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
217
        $fieldInForm = array();
218
        $fieldElementId = array();
219
        $optionsFieldName = array();
220
        foreach (array_keys($fields) as $f) {
221
            $fieldName = $fields[$f]->getVar('field_name');
222
            $fieldElement = $fields[$f]->getVar('field_element');
223
            $fieldInForm[] = $fields[$f]->getVar('field_inform');
224
            $fieldElements = $this->tc->getHandler('fieldelements')->get($fieldElement);
0 ignored issues
show
Bug introduced by
The method getHandler cannot be called on $this->tc (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...
225
            $fieldElementId[] = $fieldElements->getVar('fieldelement_id');
226
            $rpFieldName = $this->getRightString($fieldName);
227
            if (in_array(5, $fieldElementId)) {
228
                if (count($rpFieldName) % 5) {
229
                    $optionsFieldName[] = "'".$rpFieldName."'";
230
                } else {
231
                    $optionsFieldName[] = "'".$rpFieldName."'\n";
232
                }
233
            }
234
            if ((0 == $f) && (1 == $table->getVar('table_autoincrement'))) {
235
                $fieldId = $fieldName;
236
            }
237
        }
238
        if (in_array(5, $fieldElementId) > 1) {
239
            $optionsElements = implode(', ', $optionsFieldName);
0 ignored issues
show
Unused Code introduced by
$optionsElements 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...
240
            $cCl .= $this->pc->getPhpCodeCommentMultiLine(array('Options' => ''));
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->pc (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...
241
            $options = $this->pc->getPhpCodeArray('', $optionsFieldName, true);
0 ignored issues
show
Bug introduced by
The method getPhpCodeArray cannot be called on $this->pc (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...
242
            $cCl .= $this->pc->getPhpCodeVariableClass('private', 'options', $options);
0 ignored issues
show
Bug introduced by
The method getPhpCodeVariableClass cannot be called on $this->pc (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...
243
        }
244
        unset($optionsFieldName);
245
246
        $cCl .= $this->pc->getPhpCodeCommentMultiLine(array('Constructor' => '', '' => '', '@param' => 'null'), "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->pc (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...
247
        $constr = $this->xc->getXoopsCodeGetInstance("this->{$moduleDirname}", "{$ucfModuleDirname}Helper", "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeGetInstance cannot be called on $this->xc (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...
248
        $constr .= $this->getInitVars($fields);
249
        $cCl .= $this->pc->getPhpCodeFunction('__construct', '', $constr, 'public ', false, "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeFunction cannot be called on $this->pc (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...
250
        $arrayGetInstance = array('@static function' => '&getInstance', '' => '', '@param' => 'null');
251
        $cCl .= $this->pc->getPhpCodeCommentMultiLine($arrayGetInstance, "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->pc (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...
252
        $getInstance = $this->pc->getPhpCodeVariableClass('static', 'instance', 'false', "\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeVariableClass cannot be called on $this->pc (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...
253
        $instance = $this->xc->getXoopsCodeEqualsOperator('$instance', 'new self()', null, false, "\t\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeEqualsOperator cannot be called on $this->xc (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...
254
        $getInstance .= $this->pc->getPhpCodeConditions('!$instance', '', '', $instance, false, "\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeConditions cannot be called on $this->pc (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...
255
        $cCl .= $this->pc->getPhpCodeFunction('getInstance', '', $getInstance, 'public static ', true, "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeFunction cannot be called on $this->pc (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...
256
257
        $cCl .= $this->getNewInsertId($table);
258
        $cCl .= $this->getFunctionForm($module, $table, $fieldId, $fieldInForm);
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...
259
        $cCl .= $this->getValuesInObject($moduleDirname, $table, $fields);
260
        $cCl .= $this->getToArrayInObject($table);
261
262
        if (in_array(5, $fieldElementId) > 1) {
263
            $cCl .= $this->getOptionsCheck($table);
264
        }
265
        unset($fieldElementId);
266
267
        $ret .= $this->pc->getPhpCodeClass($ucfModuleDirname.$ucfTableName, $cCl, 'XoopsObject');
0 ignored issues
show
Bug introduced by
The method getPhpCodeClass cannot be called on $this->pc (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...
268
269
        return $ret;
270
    }
271
272
    /*
273
     *  @private function getNewInsertId
274
     *  @param $table
275
     *
276
     * @return string
277
     */
278
    private function getNewInsertId($table)
279
    {
280
        $tableName = $table->getVar('table_name');
281
        $ucfTableName = ucfirst($tableName);
282
        $ret = $this->pc->getPhpCodeCommentMultiLine(array('The new inserted' => '$Id'), "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->pc (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...
283
        $getInsertedId = $this->xc->getXoopsCodeEqualsOperator('$newInsertedId', "\$GLOBALS['xoopsDB']->getInsertId()", null, false, "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeEqualsOperator cannot be called on $this->xc (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
        $getInsertedId .= $this->getSimpleString('return $newInsertedId;', "\t\t");
285
286
        $ret .= $this->pc->getPhpCodeFunction('getNewInsertedId'.$ucfTableName, '', $getInsertedId, 'public ', false, "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeFunction cannot be called on $this->pc (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...
287
288
        return $ret;
289
    }
290
291
    /*
292
    *  @private function getFunctionForm
293
    *  @param string $module
294
    *  @param string $table
295
    */
296
    /**
297
     * @param $module
298
     * @param $table
299
     *
300
     * @return string
301
     */
302
    private function getFunctionForm($module, $table, $fieldId, $fieldInForm)
303
    {
304
        $moduleDirname = $module->getVar('mod_dirname');
305
        $tableName = $table->getVar('table_name');
306
        $tableSoleName = $table->getVar('table_solename');
307
        $tableCategory = $table->getVar('table_category');
308
        $tablePermissions = $table->getVar('table_permissions');
0 ignored issues
show
Unused Code introduced by
$tablePermissions 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...
309
        $ucfTableName = ucfirst($tableName);
310
        $stuTableSoleName = strtoupper($tableSoleName);
311
        $language = $this->getLanguage($moduleDirname, 'AM');
312
        $this->fe->initForm($module, $table);
0 ignored issues
show
Bug introduced by
The method initForm cannot be called on $this->fe (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...
313
        $ret = $this->pc->getPhpCodeCommentMultiLine(array('Get' => 'form', '' => '', '@param mixed' => '$action'), "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->pc (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...
314
        $action = $this->xc->getXoopsCodeEqualsOperator('$action', "\$_SERVER['REQUEST_URI']", null, false, "\t\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeEqualsOperator cannot be called on $this->xc (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...
315
        $getForm = $this->pc->getPhpCodeConditions('$action', ' === ', 'false', $action, false, "\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeConditions cannot be called on $this->pc (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...
316
        $xUser = $this->pc->getPhpCodeGlobals('xoopsUser');
0 ignored issues
show
Bug introduced by
The method getPhpCodeGlobals cannot be called on $this->pc (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...
317
        $xModule = $this->pc->getPhpCodeGlobals('xoopsModule');
0 ignored issues
show
Bug introduced by
The method getPhpCodeGlobals cannot be called on $this->pc (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...
318
        if ((1 != $tableCategory)/* && (1 == $tablePermissions)*/) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
319
            $getForm .= $this->pc->getPhpCodeCommentLine('Permissions for', 'uploader', "\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentLine cannot be called on $this->pc (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...
320
            $getForm .= $this->xc->getXoopsCodeEqualsOperator('$gpermHandler', "xoops_gethandler('groupperm')", null, true, "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeEqualsOperator cannot be called on $this->xc (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...
321
            $getForm .= $this->pc->getPhpCodeTernaryOperator('groups', 'is_object('.$xUser.')', $xUser.'->getGroups()', 'XOOPS_GROUP_ANONYMOUS', "\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeTernaryOperator cannot be called on $this->pc (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...
322
            $checkRight = $this->xc->getXoopsCodeCheckRight('$gpermHandler', $permString = '', 32, '$groups', $xModule.'->getVar(\'mid\')', true);
0 ignored issues
show
Bug introduced by
The method getXoopsCodeCheckRight cannot be called on $this->xc (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...
323
            $ternaryOperator = $this->pc->getPhpCodeTernaryOperator('permissionUpload', $checkRight, 'true', 'false', "\t\t\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeTernaryOperator cannot be called on $this->pc (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...
324
            $permissionUpload = $this->xc->getXoopsCodeEqualsOperator('$permissionUpload', 'true', null, false, "\t\t\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeEqualsOperator cannot be called on $this->xc (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...
325
            $ternOperator = $this->pc->getPhpCodeRemoveCarriageReturn($ternaryOperator, '', "\r");
0 ignored issues
show
Bug introduced by
The method getPhpCodeRemoveCarriageReturn cannot be called on $this->pc (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...
326
            $if = $this->pc->getPhpCodeConditions('!'.$xUser.'->isAdmin('.$xModule.'->mid())', '', '', $ternaryOperator, $permissionUpload, "\t\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeConditions cannot be called on $this->pc (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...
327
            $getForm .= $this->pc->getPhpCodeConditions($xUser, '', '', $if, $ternOperator, "\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeConditions cannot be called on $this->pc (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...
328
        }
329
        $getForm .= $this->pc->getPhpCodeCommentLine('Title', '', "\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentLine cannot be called on $this->pc (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...
330
        $getForm .= $this->pc->getPhpCodeTernaryOperator('title', '$this->isNew()', "sprintf({$language}{$stuTableSoleName}_ADD)", "sprintf({$language}{$stuTableSoleName}_EDIT)", "\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeTernaryOperator cannot be called on $this->pc (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
        $getForm .= $this->pc->getPhpCodeCommentLine('Get Theme', 'Form', "\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentLine cannot be called on $this->pc (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...
332
        $getForm .= $this->xc->getXoopsCodeLoad('XoopsFormLoader', "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeLoad cannot be called on $this->xc (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...
333
        $getForm .= $this->cc->getClassXoopsThemeForm('form', 'title', 'form', 'action', 'post');
0 ignored issues
show
Bug introduced by
The method getClassXoopsThemeForm cannot be called on $this->cc (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...
334
        $getForm .= $this->cc->getClassSetExtra('form', "'enctype=\"multipart/form-data\"'");
0 ignored issues
show
Bug introduced by
The method getClassSetExtra cannot be called on $this->cc (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...
335
        $getForm .= $this->fe->renderElements();
0 ignored issues
show
Bug introduced by
The method renderElements cannot be called on $this->fe (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...
336
337
        if (in_array(1, $fieldInForm)) {
338
            if (1 == $table->getVar('table_permissions')) {
339
                $getForm .= $this->getPermissionsInForm($moduleDirname, $fieldId);
340
            }
341
        }
342
        $getForm .= $this->pc->getPhpCodeCommentLine('To Save', '', "\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentLine cannot be called on $this->pc (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...
343
        //$hiddenSave = $this->cc->getClassXoopsFormHidden('', "'op'", "'save'", true, false);
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
344
        $getForm .= $this->cc->getClassAddElement('form', "new XoopsFormHidden('op', 'save')");
0 ignored issues
show
Bug introduced by
The method getClassAddElement cannot be called on $this->cc (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...
345
        //$buttonSend = $this->cc->getClassXoopsFormButton('', '', 'submit', '_SUBMIT', 'submit', true);
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
346
        $getForm .= $this->cc->getClassAddElement('form', "new XoopsFormButton('', 'submit', _SUBMIT, 'submit')");
0 ignored issues
show
Bug introduced by
The method getClassAddElement cannot be called on $this->cc (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...
347
        $getForm .= $this->getSimpleString('return $form;', "\t\t");
348
349
        $ret .= $this->pc->getPhpCodeFunction('getForm'.$ucfTableName, '$action = false', $getForm, 'public ', false, "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeFunction cannot be called on $this->pc (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
351
        return $ret;
352
    }
353
354
    /*
355
    *  @private function getPermissionsInForm
356
    *  @param string $moduleDirname
357
    *  @param string $fieldId
358
    */
359
    /**
360
     * @param $moduleDirname
361
     * @param $fieldId
362
     *
363
     * @return string
364
     */
365
    private function getPermissionsInForm($moduleDirname, $fieldId)
366
    {
367
        $permissionApprove = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_APPROVE');
368
        $permissionSubmit = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_SUBMIT');
369
        $permissionView = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_VIEW');
370
        $ret = $this->pc->getPhpCodeCommentLine('Permissions', '', "\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentLine cannot be called on $this->pc (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...
371
        $ret .= $this->xc->getXoopsCodeEqualsOperator('$memberHandler', "xoops_gethandler('member')", null, true, "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeEqualsOperator cannot be called on $this->xc (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...
372
        $ret .= $this->xc->getXoopsCodeEqualsOperator('$groupList', '$memberHandler->getGroupList()', null, false, "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeEqualsOperator cannot be called on $this->xc (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...
373
        $ret .= $this->xc->getXoopsCodeEqualsOperator('$gpermHandler', "xoops_gethandler('groupperm')", null, true, "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeEqualsOperator cannot be called on $this->xc (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...
374
        $ret .= $this->pc->getPhpCodeArrayType('fullList', 'keys', 'groupList', null, false, "\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeArrayType cannot be called on $this->pc (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...
375
376
        $ifGroups = $this->xc->getXoopsCodeGetGroupIds('groupsIdsApprove', 'gpermHandler', "'{$moduleDirname}_approve'", "\$this->getVar( '{$fieldId}' )", "\$GLOBALS['xoopsModule']->getVar( 'mid' )", "\t\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeGetGroupIds cannot be called on $this->xc (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...
377
        $ifGroups .= $this->xc->getXoopsCodeGetGroupIds('groupsIdsSubmit', 'gpermHandler', "'{$moduleDirname}_submit'", "\$this->getVar( '{$fieldId}' )", "\$GLOBALS['xoopsModule']->getVar( 'mid' )", "\t\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeGetGroupIds cannot be called on $this->xc (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...
378
        $ifGroups .= $this->xc->getXoopsCodeGetGroupIds('groupsIdsView', 'gpermHandler', "'{$moduleDirname}_view'", "\$this->getVar( '{$fieldId}' )", "\$GLOBALS['xoopsModule']->getVar( 'mid' )", "\t\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeGetGroupIds cannot be called on $this->xc (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...
379
        $ifGroups .= $this->pc->getPhpCodeArrayType('groupsIdsApprove', 'values', 'groupsIdsApprove', null, false, "\t\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeArrayType cannot be called on $this->pc (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...
380
        $ifGroups .= $this->cc->getClassXoopsFormCheckBox('groupsCanApproveCheckbox', "{$permissionApprove}", 'groups_approve[]', '$groupsIdsApprove', false, "\t\t\t");
0 ignored issues
show
Bug introduced by
The method getClassXoopsFormCheckBox cannot be called on $this->cc (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...
381
        $ifGroups .= $this->pc->getPhpCodeArrayType('groupsIdsSubmit', 'values', 'groupsIdsSubmit', null, false, "\t\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeArrayType cannot be called on $this->pc (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...
382
        $ifGroups .= $this->cc->getClassXoopsFormCheckBox('groupsCanSubmitCheckbox', "{$permissionSubmit}", 'groups_submit[]', '$groupsIdsSubmit', false, "\t\t\t");
0 ignored issues
show
Bug introduced by
The method getClassXoopsFormCheckBox cannot be called on $this->cc (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...
383
        $ifGroups .= $this->pc->getPhpCodeArrayType('groupsIdsView', 'values', 'groupsIdsView', null, false, "\t\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeArrayType cannot be called on $this->pc (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...
384
        $ifGroups .= $this->cc->getClassXoopsFormCheckBox('groupsCanViewCheckbox', "{$permissionView}", 'groups_view[]', '$groupsIdsView', false, "\t\t\t");
0 ignored issues
show
Bug introduced by
The method getClassXoopsFormCheckBox cannot be called on $this->cc (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...
385
386
        $else = $this->cc->getClassXoopsFormCheckBox('groupsCanApproveCheckbox', "{$permissionApprove}", 'groups_approve[]', '$fullList', false, "\t\t\t");
0 ignored issues
show
Bug introduced by
The method getClassXoopsFormCheckBox cannot be called on $this->cc (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...
387
        $else .= $this->cc->getClassXoopsFormCheckBox('groupsCanSubmitCheckbox', "{$permissionSubmit}", 'groups_submit[]', '$fullList', false, "\t\t\t");
0 ignored issues
show
Bug introduced by
The method getClassXoopsFormCheckBox cannot be called on $this->cc (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...
388
        $else .= $this->cc->getClassXoopsFormCheckBox('groupsCanViewCheckbox', "{$permissionView}", 'groups_view[]', '$fullList', false, "\t\t\t");
0 ignored issues
show
Bug introduced by
The method getClassXoopsFormCheckBox cannot be called on $this->cc (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...
389
390
        $ret .= $this->pc->getPhpCodeConditions('!$this->isNew()', null, null, $ifGroups, $else, "\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeConditions cannot be called on $this->pc (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...
391
        $ret .= $this->pc->getPhpCodeCommentLine('To Approve', '', "\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentLine cannot be called on $this->pc (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...
392
        $ret .= $this->cc->getClassAddOptionArray('groupsCanApproveCheckbox', '$groupList');
0 ignored issues
show
Bug introduced by
The method getClassAddOptionArray cannot be called on $this->cc (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...
393
        $ret .= $this->cc->getClassAddElement('form', '$groupsCanApproveCheckbox');
0 ignored issues
show
Bug introduced by
The method getClassAddElement cannot be called on $this->cc (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...
394
        $ret .= $this->pc->getPhpCodeCommentLine('To Submit', '', "\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentLine cannot be called on $this->pc (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...
395
        $ret .= $this->cc->getClassAddOptionArray('groupsCanSubmitCheckbox', '$groupList');
0 ignored issues
show
Bug introduced by
The method getClassAddOptionArray cannot be called on $this->cc (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...
396
        $ret .= $this->cc->getClassAddElement('form', '$groupsCanSubmitCheckbox');
0 ignored issues
show
Bug introduced by
The method getClassAddElement cannot be called on $this->cc (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...
397
        $ret .= $this->pc->getPhpCodeCommentLine('To View', '', "\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentLine cannot be called on $this->pc (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...
398
        $ret .= $this->cc->getClassAddOptionArray('groupsCanViewCheckbox', '$groupList');
0 ignored issues
show
Bug introduced by
The method getClassAddOptionArray cannot be called on $this->cc (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...
399
        $ret .= $this->cc->getClassAddElement('form', '$groupsCanViewCheckbox');
0 ignored issues
show
Bug introduced by
The method getClassAddElement cannot be called on $this->cc (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...
400
401
        return $ret;
402
    }
403
404
    /*
405
    *  @private function getValuesInObject
406
    *  @param null
407
    */
408
    /**
409
     * @return string
410
     */
411
    private function getValuesInObject($moduleDirname, $table, $fields)
412
    {
413
        $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...
414
        $ucfTableName = ucfirst($table->getVar('table_name'));
415
        $ret = $this->pc->getPhpCodeCommentMultiLine(array('Get' => 'Values'), "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->pc (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...
416
        $getValues = $this->xc->getXoopsCodeEqualsOperator('$ret', 'parent::getValues($keys, $format, $maxDepth)', null, true, "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeEqualsOperator cannot be called on $this->xc (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...
417
418
        foreach (array_keys($fields) as $f) {
419
            $fieldName = $fields[$f]->getVar('field_name');
420
            $fieldElement = $fields[$f]->getVar('field_element');
421
            $rpFieldName = $this->tf->getRightString($fieldName);
0 ignored issues
show
Bug introduced by
The method getRightString cannot be called on $this->tf (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...
422
            switch ($fieldElement) {
423
                case 3:
424
                case 4:
425
                    $getValues .= $this->pc->getPhpCodeStripTags("ret['{$rpFieldName}']", "\$this->getVar('{$fieldName}')", false, "\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeStripTags cannot be called on $this->pc (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...
426
                break;
427
                case 8:
428
                    $getValues .= $this->xc->getXoopsCodeUnameFromId("ret['{$rpFieldName}']", "\$this->getVar('{$fieldName}')", "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeUnameFromId cannot be called on $this->xc (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...
429
                break;
430
                case 15:
431
                    $getValues .= $this->xc->getXoopsCodeFormatTimeStamp("ret['{$rpFieldName}']", "\$this->getVar('{$fieldName}')", 's', "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeFormatTimeStamp cannot be called on $this->xc (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...
432
                break;
433
                default:
0 ignored issues
show
Coding Style introduced by
The default body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a default statement must start on the line immediately following the statement.

switch ($expr) {
    default:
        doSomething(); //right
        break;
}


switch ($expr) {
    default:

        doSomething(); //wrong
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
434
435
                    if ($fieldElement > 15) {
436
                        $fieldElements = $this->tc->getHandler('fieldelements')->get($fieldElement);
0 ignored issues
show
Bug introduced by
The method getHandler cannot be called on $this->tc (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...
437
                        $fieldElementMid = $fieldElements->getVar('fieldelement_mid');
438
                        $fieldElementTid = $fieldElements->getVar('fieldelement_tid');
439
                        $fieldElementName = $fieldElements->getVar('fieldelement_name');
440
                        $fieldNameDesc = substr($fieldElementName, strrpos($fieldElementName, ':'), strlen($fieldElementName));
441
                        $topicTableName = str_replace(': ', '', strtolower($fieldNameDesc));
442
                        $fieldsTopics = $this->tf->getTableFields($fieldElementMid, $fieldElementTid);
0 ignored issues
show
Bug introduced by
The method getTableFields cannot be called on $this->tf (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...
443
                        foreach (array_keys($fieldsTopics) as $f) {
444
                            $fieldNameTopic = $fieldsTopics[$f]->getVar('field_name');
445
                            if (1 == $fieldsTopics[$f]->getVar('field_main')) {
446
                                $fieldMainTopic = $fieldNameTopic;
447
                            }
448
                        }
449
                        $getHandlerVar = "\$this->{$moduleDirname}->getHandler('{$topicTableName}')->get(\$this->getVar('{$fieldName}'))->getVar('{$fieldMainTopic}')";
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...
450
                        $getValues .= $this->xc->getXoopsCodeEqualsOperator("\$ret['{$rpFieldName}']", $getHandlerVar, null, false, "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeEqualsOperator cannot be called on $this->xc (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...
451
                    } else {
452
                        $getValues .= $this->xc->getXoopsCodeGetVar("ret['{$rpFieldName}']", 'this', $fieldName, false, "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeGetVar cannot be called on $this->xc (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...
453
                    }
454
                break;
455
            }
456
        }
457
        $getValues .= $this->getSimpleString('return $ret;', "\t\t");
458
459
        $ret .= $this->pc->getPhpCodeFunction('getValues'.$ucfTableName, '$keys = null, $format = null, $maxDepth = null', $getValues, 'public ', false, "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeFunction cannot be called on $this->pc (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...
460
461
        return $ret;
462
    }
463
464
    /*
465
     *  @private function getToArrayInObject
466
     *  @param $table
467
     *
468
     * @return string
469
     */
470
    private function getToArrayInObject($table)
471
    {
472
        $tableName = $table->getVar('table_name');
473
        $ucfTableName = ucfirst($tableName);
474
        $multiLineCom = array('Returns an array representation' => 'of the object', '' => '', '@return' => 'array');
475
        $ret = $this->pc->getPhpCodeCommentMultiLine($multiLineCom, "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->pc (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...
476
477
        $getToArray = $this->pc->getPhpCodeArray('ret', array(), false, "\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeArray cannot be called on $this->pc (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...
478
        $getToArray .= $this->xc->getXoopsCodeEqualsOperator('$vars', '$this->getVars()', null, false, "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeEqualsOperator cannot be called on $this->xc (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...
479
        $foreach = $this->xc->getXoopsCodeGetVar('ret[$var]', 'this', '$var', false, "\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeGetVar cannot be called on $this->xc (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...
480
        $getToArray .= $this->pc->getPhpCodeForeach('vars', true, false, 'var', $foreach, "\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeForeach cannot be called on $this->pc (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...
481
        $getToArray .= $this->getSimpleString('return $ret;', "\t\t");
482
483
        $ret .= $this->pc->getPhpCodeFunction('toArray'.$ucfTableName, '', $getToArray, 'public ', false, "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeFunction cannot be called on $this->pc (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...
484
485
        return $ret;
486
    }
487
488
    /*
489
    *  @private function getOptionsCheck
490
    *  @param $table
491
    */
492
    /**
493
     * @return string
494
     */
495
    private function getOptionsCheck($table)
496
    {
497
        $tableName = $table->getVar('table_name');
498
        $ucfTableName = ucfirst($tableName);
499
        $ret = $this->pc->getPhpCodeCommentMultiLine(array('Get' => 'Options'), "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->pc (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...
500
        $getOptions = $this->pc->getPhpCodeArray('ret', array(), false, "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeArray cannot be called on $this->pc (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...
501
502
        $fields = $this->tf->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
0 ignored issues
show
Bug introduced by
The method getTableFields cannot be called on $this->tf (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...
503
        foreach (array_keys($fields) as $f) {
504
            $fieldName = $fields[$f]->getVar('field_name');
505
            $fieldElement = $fields[$f]->getVar('field_element');
506
            //
507
            $fieldElements = $this->tc->getHandler('fieldelements')->get($fieldElement);
0 ignored issues
show
Bug introduced by
The method getHandler cannot be called on $this->tc (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...
508
            $fieldElementId = $fieldElements->getVar('fieldelement_id');
509
            $rpFieldName = $this->tf->getRightString($fieldName);
0 ignored issues
show
Bug introduced by
The method getRightString cannot be called on $this->tf (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...
510
            if (5 == $fieldElementId) {
511
                $arrayPush = $this->pc->getPhpCodeArrayType('ret', 'push', "'{$rpFieldName}'", null, false, "\t\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeArrayType cannot be called on $this->pc (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...
512
                $getOptions .= $this->pc->getPhpCodeConditions(1, ' == ', "\$this->getVar('{$fieldName}')", $arrayPush, false, "\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeConditions cannot be called on $this->pc (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...
513
            }
514
        }
515
516
        $getOptions .= $this->getSimpleString('return $ret;', "\t\t");
517
518
        $ret .= $this->pc->getPhpCodeFunction('getOptions'.$ucfTableName, '', $getOptions, 'public ', false, "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeFunction cannot be called on $this->pc (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...
519
520
        return $ret;
521
    }
522
523
    /*
524
    *  @public function getClassHandler
525
    *  @param string $moduleDirname
526
    *  @param string $tableName
527
    *  @param string $fieldId
528
    *  @param string $fieldMain
529
    */
530
    /**
531
     * @param $moduleDirname
532
     * @param $tableName
533
     * @param $tableCategory
534
     * @param $tableFieldname
535
     * @param $fieldId
536
     * @param $fieldMain
537
     *
538
     * @return string
539
     */
540
    private function getClassObjectHandler($moduleDirname, $table, $fieldId, $fieldName, $fieldMain, $fieldParent, $fieldParentId, $fieldElement)
541
    {
542
        $tableName = $table->getVar('table_name');
543
        $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...
544
        $tableSoleName = $table->getVar('table_solename');
545
        $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...
546
        $ucfModuleDirname = ucfirst($moduleDirname);
547
        $ucfTableName = ucfirst($tableName);
548
        $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...
549
        $ucfModuleTable = $ucfModuleDirname.$ucfTableName;
550
        $multiLineCom = array('Class Object Handler' => $ucfModuleDirname.$ucfTableName);
551
        $ret = $this->pc->getPhpCodeCommentMultiLine($multiLineCom);
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->pc (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...
552
553
        $cClh = $this->pc->getPhpCodeCommentMultiLine(array('@var' => 'mixed'), "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->pc (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...
554
        $cClh .= $this->pc->getPhpCodeVariableClass('private', $moduleDirname, 'null', "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeVariableClass cannot be called on $this->pc (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...
555
556
        $cClh .= $this->pc->getPhpCodeCommentMultiLine(array('Constructor' => '', '' => '', '@param' => 'string $db'), "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->pc (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...
557
        $constr = "\t\tparent::__construct(\$db, '{$moduleDirname}_{$tableName}', '{$moduleDirname}{$tableName}', '{$fieldId}', '{$fieldMain}');\n";
558
        $constr .= $this->xc->getXoopsCodeGetInstance("this->{$moduleDirname}", "{$ucfModuleDirname}Helper", "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeGetInstance cannot be called on $this->xc (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...
559
        $constr .= $this->xc->getXoopsCodeEqualsOperator('$this->db', '$db', null, false, "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeEqualsOperator cannot be called on $this->xc (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...
560
561
        $cClh .= $this->pc->getPhpCodeFunction('__construct', '$db', $constr, 'public ', false, "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeFunction cannot be called on $this->pc (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...
562
563
        $cClh .= $this->getClassCreate();
564
        $cClh .= $this->getClassGet();
565
        $cClh .= $this->getClassGetInsertId();
566
        $cClh .= $this->getClassGetIds();
567
        $cClh .= $this->getClassInsert();
568
        $cClh .= $this->getClassCounter($tableName, $fieldId, $fieldMain);
569
        $cClh .= $this->getClassAll($tableName, $fieldId, $fieldMain);
570
        $cClh .= $this->getClassCriteria($tableName);
571
        if (in_array(1, $fieldParentId) && $fieldElement > 15) {
572
            $cClh .= $this->getClassByCategory($moduleDirname, $tableName, $tableFieldName, $fieldId, $fieldName, $fieldMain, $fieldParent, $fieldElement);
0 ignored issues
show
Bug introduced by
The variable $tableFieldName does not exist. Did you mean $fieldName?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
573
            $cClh .= $this->getClassGetTableSolenameById($moduleDirname, $table, $fieldMain);
574
        }
575
576
        $ret .= $this->pc->getPhpCodeClass("{$ucfModuleTable}Handler", $cClh, 'XoopsPersistableObjectHandler');
0 ignored issues
show
Bug introduced by
The method getPhpCodeClass cannot be called on $this->pc (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...
577
578
        return $ret;
579
    }
580
581
    /**
582
     *  @public function getClassCreate
583
     *
584
     *  @return string
585
     */
586
    private function getClassCreate()
587
    {
588
        $ret = $this->pc->getPhpCodeCommentMultiLine(array('@param bool' => '$isNew', '' => '', '@return' => 'object'), "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->pc (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...
589
        $cClhc = $this->getSimpleString('return parent::create($isNew);', "\t\t");
590
591
        $ret .= $this->pc->getPhpCodeFunction('&create', '$isNew = true', $cClhc, 'public ', false, "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeFunction cannot be called on $this->pc (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...
592
593
        return $ret;
594
    }
595
596
    /**
597
     *  @public function getClassGet
598
     *
599
     *  @return string
600
     */
601
    private function getClassGet()
602
    {
603
        $ret = $this->pc->getPhpCodeCommentMultiLine(array('retrieve a' => 'field', '' => '', '@param int' => '$i field id', '@return mixed reference to the' => '{@link Get} object'), "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->pc (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...
604
        $cClhg = $this->getSimpleString('return parent::get($i, $fields);', "\t\t");
605
606
        $ret .= $this->pc->getPhpCodeFunction('&get', '$i = null, $fields = null', $cClhg, 'public ', false, "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeFunction cannot be called on $this->pc (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...
607
608
        return $ret;
609
    }
610
611
    /**
612
     *  @public function getClassGetInsertId
613
     *
614
     *  @return string
615
     */
616
    private function getClassGetInsertId()
617
    {
618
        $ret = $this->pc->getPhpCodeCommentMultiLine(array('get inserted' => 'id', '' => '', '@param' => 'null', '@return integer reference to the' => '{@link Get} object'), "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->pc (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...
619
        $cClhgid = $this->getSimpleString('return $this->db->getInsertId();', "\t\t");
620
621
        $ret .= $this->pc->getPhpCodeFunction('&getInsertId', '', $cClhgid, 'public ', false, "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeFunction cannot be called on $this->pc (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...
622
623
        return $ret;
624
    }
625
626
    /**
627
     *  @public function getClassGetIds
628
     *
629
     *  @return string
630
     */
631
    private function getClassGetIds()
632
    {
633
        $ret = $this->pc->getPhpCodeCommentMultiLine(array('get IDs of objects' => 'matching a condition', '' => '',
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->pc (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...
634
                                                            '@param object \$criteria' => '{@link CriteriaElement} to match',
635
                                                            '@return array of' => 'object IDs', ), "\t");
636
        $cClhgids = $this->getSimpleString('return parent::getIds($criteria);', "\t\t");
637
638
        $ret .= $this->pc->getPhpCodeFunction('&getIds', '$criteria', $cClhgids, 'public ', false, "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeFunction cannot be called on $this->pc (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...
639
640
        return $ret;
641
    }
642
643
    /**
644
     *  @public function getClassInsert
645
     *
646
     *  @return string
647
     */
648
    private function getClassInsert()
649
    {
650
        $ret = $this->pc->getPhpCodeCommentMultiLine(array('insert a new field' => 'in the database', '' => '',
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->pc (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...
651
                                                            '@param object \$field reference to the' => '{@link insert} object',
652
                                                            '@param bool' => '$force', 'return bool FALSE if failed,' => 'TRUE if already present and unchanged or successful', ), "\t");
653
        $cClhinsert = $this->getSimpleString('return false;', "\t\t\t");
654
655
        $if = $this->pc->getPhpCodeConditions('!parent::insert($field, $force)', '', '', $cClhinsert, false, "\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeConditions cannot be called on $this->pc (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...
656
        $if .= $this->getSimpleString('return true;', "\t\t");
657
658
        $ret .= $this->pc->getPhpCodeFunction('&insert', '&$field, $force = false', $if, 'public ', false, "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeFunction cannot be called on $this->pc (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...
659
660
        return $ret;
661
    }
662
663
    /**
664
     *  @public function getClassCounter
665
     *
666
     *  @param $tableName
667
     *  @param $fieldId
668
     *  @param $fieldMain
669
     *
670
     *  @return string
671
     */
672
    private function getClassCounter($tableName, $fieldId, $fieldMain)
673
    {
674
        $ucfTableName = ucfirst($tableName);
675
        $ret = $this->pc->getPhpCodeCommentMultiLine(array('Get Count '.$ucfTableName => 'in the database'), "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->pc (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...
676
677
        $critCount = $this->cc->getClassCriteriaCompo('criteriaCount'.$ucfTableName, "\t\t");
0 ignored issues
show
Bug introduced by
The method getClassCriteriaCompo cannot be called on $this->cc (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...
678
        $paramsCrit = "\$this->get{$ucfTableName}Criteria(\$criteriaCount{$ucfTableName}, \$start, \$limit, \$sort, \$order)";
679
        $critCount .= $this->xc->getXoopsCodeEqualsOperator('$criteriaCount'.$ucfTableName, $paramsCrit, null, false, "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeEqualsOperator cannot be called on $this->xc (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...
680
        $critCount .= $this->getSimpleString("return parent::getCount(\$criteriaCount{$ucfTableName});", "\t\t");
681
        $params = "\$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC'";
682
683
        $ret .= $this->pc->getPhpCodeFunction('getCount'.$ucfTableName, $params, $critCount, 'public ', false, "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeFunction cannot be called on $this->pc (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...
684
685
        return $ret;
686
    }
687
688
    /**
689
     *  @public function getClassAll
690
     *
691
     *  @param $tableName
692
     *  @param $fieldId
693
     *  @param $fieldMain
694
     *
695
     *  @return string
696
     */
697
    private function getClassAll($tableName, $fieldId, $fieldMain)
698
    {
699
        $ucfTableName = ucfirst($tableName);
700
        $ret = $this->pc->getPhpCodeCommentMultiLine(array('Get All '.$ucfTableName => 'in the database'), "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->pc (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...
701
702
        $critAll = $this->cc->getClassCriteriaCompo('criteriaAll'.$ucfTableName, "\t\t");
0 ignored issues
show
Bug introduced by
The method getClassCriteriaCompo cannot be called on $this->cc (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...
703
        $paramsCrit = "\$this->get{$ucfTableName}Criteria(\$criteriaAll{$ucfTableName}, \$start, \$limit, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC')";
704
        $critAll .= $this->xc->getXoopsCodeEqualsOperator('$criteriaAll'.$ucfTableName, $paramsCrit, null, false, "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeEqualsOperator cannot be called on $this->xc (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...
705
        $critAll .= $this->getSimpleString("return parent::getAll(\$criteriaAll{$ucfTableName});", "\t\t");
706
        $params = "\$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC'";
707
708
        $ret .= $this->pc->getPhpCodeFunction('getAll'.$ucfTableName, $params, $critAll, 'public ', false, "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeFunction cannot be called on $this->pc (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...
709
710
        return $ret;
711
    }
712
713
    /**
714
     *  @public function getClassByCategory
715
     *
716
     *  @param $tableName
717
     *  @param $fieldId
718
     *  @param $fieldMain
719
     *  @param $fieldParent
720
     *
721
     *  @return string
722
     */
723
    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.

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

Loading history...
724
    {
725
        $ucfTableName = ucfirst($tableName);
726
        $fieldElements = $this->tc->getHandler('fieldelements')->get($fieldElement);
0 ignored issues
show
Bug introduced by
The method getHandler cannot be called on $this->tc (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...
727
        $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...
728
        $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...
729
        $fieldElementName = $fieldElements->getVar('fieldelement_name');
730
        $fieldNameDesc = ucfirst(substr($fieldElementName, strrpos($fieldElementName, ':'), strlen($fieldElementName)));
731
        $topicTableName = str_replace(': ', '', $fieldNameDesc);
732
        $lcfTopicTableName = lcfirst($topicTableName);
733
734
        $ret = $this->pc->getPhpCodeCommentMultiLine(array("Get All {$ucfTableName} By" => "{$fieldNameDesc} Id"), "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->pc (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...
735
736
        $critAll = $this->xc->getXoopsCodeEqualsOperator('$gpermHandler', "xoops_gethandler('groupperm')", null, true, "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeEqualsOperator cannot be called on $this->xc (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...
737
        $param1 = "'{$moduleDirname}_view'";
738
        $param2 = "\$GLOBALS['xoopsUser']->getGroups()";
739
        $param3 = "\$GLOBALS['xoopsModule']->getVar('mid')";
740
        $critAll .= $this->xc->getXoopsCodeGetItemIds($lcfTopicTableName, 'gpermHandler', $param1, $param2, $param3, "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeGetItemIds cannot be called on $this->xc (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...
741
        $critAll .= $this->cc->getClassCriteriaCompo('criteriaAll'.$ucfTableName, "\t\t");
0 ignored issues
show
Bug introduced by
The method getClassCriteriaCompo cannot be called on $this->cc (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...
742
743
        if (strstr($fieldName, 'status')) {
744
            $crit = $this->cc->getClassCriteria('', "'{$fieldName}'", '0', "'!='", true);
0 ignored issues
show
Bug introduced by
The method getClassCriteria cannot be called on $this->cc (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...
745
            $critAll .= $this->cc->getClassAdd('criteriaAll'.$ucfTableName, $crit, "\t\t");
0 ignored issues
show
Bug introduced by
The method getClassAdd cannot be called on $this->cc (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...
746
        }
747
        $paramsCritAll = "\$this->get{$ucfTableName}Criteria(\$criteriaAll{$ucfTableName}, \$start, \$limit, \$sort, \$order)";
748
        $critAll .= $this->xc->getXoopsCodeEqualsOperator('$criteriaAll'.$ucfTableName, $paramsCritAll, null, false, "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeEqualsOperator cannot be called on $this->xc (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...
749
750
        $critAll .= $this->getSimpleString("return parent::getAll(\$criteriaAll{$ucfTableName});", "\t\t");
751
        $params = "\${$tableFieldName}Id, \$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC'";
752
753
        $ret .= $this->pc->getPhpCodeFunction("getAll{$ucfTableName}By{$fieldNameDesc}Id".$ucfTableName, $params, $critAll, 'public ', false, "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeFunction cannot be called on $this->pc (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...
754
755
        return $ret;
756
    }
757
758
    /**
759
     *  @public function getClassCriteria
760
     *
761
     *  @param $tableName
762
     *  @param $fieldId
763
     *  @param $fieldMain
764
     *
765
     *  @return string
766
     */
767
    private function getClassCriteria($tableName)
768
    {
769
        $ucfTableName = ucfirst($tableName);
770
        $ret = $this->pc->getPhpCodeCommentMultiLine(array('Get' => 'Criteria '.$ucfTableName), "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->pc (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...
771
772
        $paramsAllCriteria = "\$criteria{$ucfTableName}, \$start, \$limit, \$sort, \$order";
773
774
        $critSets = $this->cc->getClassSetStart('criteria'.$ucfTableName, 'start', "\t\t");
0 ignored issues
show
Bug introduced by
The method getClassSetStart cannot be called on $this->cc (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...
775
        $critSets .= $this->cc->getClassSetLimit('criteria'.$ucfTableName, 'limit', "\t\t");
0 ignored issues
show
Bug introduced by
The method getClassSetLimit cannot be called on $this->cc (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...
776
        $critSets .= $this->cc->getClassSetSort('criteria'.$ucfTableName, 'sort', "\t\t");
0 ignored issues
show
Bug introduced by
The method getClassSetSort cannot be called on $this->cc (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...
777
        $critSets .= $this->cc->getClassSetOrder('criteria'.$ucfTableName, 'order', "\t\t");
0 ignored issues
show
Bug introduced by
The method getClassSetOrder cannot be called on $this->cc (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...
778
        $critSets .= $this->getSimpleString("return \$criteria{$ucfTableName};", "\t\t");
779
780
        $ret .= $this->pc->getPhpCodeFunction("get{$ucfTableName}Criteria", $paramsAllCriteria, $critSets, 'private ', false, "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeFunction cannot be called on $this->pc (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...
781
782
        return $ret;
783
    }
784
785
    /**
786
     *  @public function getClassGetTableSolenameById
787
     *
788
     *  @param $moduleDirname
789
     *  @param $table
790
     *
791
     *  @return string
792
     */
793
    private function getClassGetTableSolenameById($moduleDirname, $table, $fieldMain)
794
    {
795
        $tableName = $table->getVar('table_name');
796
        $tableSoleName = $table->getVar('table_solename');
797
        $ucfTableSoleName = ucfirst($tableSoleName);
798
        $ccTableSoleName = $this->getCamelCase($tableSoleName, true);
799
        $ret = $this->pc->getPhpCodeCommentMultiLine(array('Returns the' => $ucfTableSoleName.' from id', '' => '', '@return' => 'string'), "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->pc (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...
800
        $soleName = $this->xc->getXoopsCodeEqualsOperator("\${$tableSoleName}Id", "(int)( \${$tableSoleName}Id )", null, false, "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeEqualsOperator cannot be called on $this->xc (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...
801
        $soleName .= $this->xc->getXoopsCodeEqualsOperator("\${$tableSoleName}", "''", null, false, "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeEqualsOperator cannot be called on $this->xc (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...
802
803
        $contentIf = $this->xc->getXoopsHandlerLine('this->'.$moduleDirname, $tableName, "\t\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsHandlerLine cannot be called on $this->xc (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...
804
        $contentIf .= $this->xc->getXoopsCodeGet($tableName, "\${$tableSoleName}Id", 'Obj', true, false, "\t\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeGet cannot be called on $this->xc (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...
805
        $getVar = $this->xc->getXoopsCodeGetVar($ccTableSoleName, "{$tableSoleName}Obj", $fieldMain, false, "\t\t\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeGetVar cannot be called on $this->xc (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...
806
        $contentIf .= $this->pc->getPhpCodeConditions("is_object( \${$tableSoleName}Obj )", '', '', $getVar, false, "\t\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeConditions cannot be called on $this->pc (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
808
        $soleName .= $this->pc->getPhpCodeConditions("\${$tableSoleName}Id", ' > ', '0', $contentIf = null, false, "\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeConditions cannot be called on $this->pc (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...
809
        $soleName .= $this->getSimpleString("return \${$tableSoleName};", "\t\t");
810
811
        $ret .= $this->pc->getPhpCodeFunction("get{$ucfTableSoleName}FromId", "\${$tableSoleName}Id", $soleName, 'public ', false, "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeFunction cannot be called on $this->pc (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...
812
813
        return $ret;
814
    }
815
816
    /*
817
     * @public function render    
818
     * @param null
819
     *
820
     * @return bool|string
821
     */
822
    public function render()
823
    {
824
        $module = $this->getModule();
825
        $table = $this->getTable();
826
        $filename = $this->getFileName();
827
        $tableName = $table->getVar('table_name');
0 ignored issues
show
Unused Code introduced by
$tableName 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...
828
        $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...
829
        $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...
830
        $moduleDirname = $module->getVar('mod_dirname');
831
        $fields = $this->tf->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
0 ignored issues
show
Bug introduced by
The method getTableFields cannot be called on $this->tf (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...
832
        $fieldInForm = array();
833
        $fieldParentId = array();
834
        $fieldElementId = array();
835
        $fieldParent = null;
836
        foreach (array_keys($fields) as $f) {
837
            $fieldName = $fields[$f]->getVar('field_name');
838
            $fieldInForm[] = $fields[$f]->getVar('field_inform');
839
            $fieldParentId[] = $fields[$f]->getVar('field_parent');
840
            if ((0 == $f) && (1 == $table->getVar('table_autoincrement'))) {
841
                $fieldId = $fieldName; // $fieldId = fields parameter index field
842
            }
843
            if (1 == $fields[$f]->getVar('field_main')) {
844
                $fieldMain = $fieldName; // $fieldMain = fields parameter main field
845
            }
846
            if (1 == $fields[$f]->getVar('field_parent')) {
847
                $fieldParent = $fieldName; // $fieldParent = fields parameter parent field
848
            }
849
            $fieldElement = $fields[$f]->getVar('field_element');
850
            //
851
            $fieldElements = $this->tc->getHandler('fieldelements')->get($fieldElement);
0 ignored issues
show
Bug introduced by
The method getHandler cannot be called on $this->tc (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...
852
            $fieldElementId[] = $fieldElements->getVar('fieldelement_id');
853
        }
854
        $content = $this->getHeaderFilesComments($module, $filename);
855
        $content .= $this->getClassObject($module, $table, $fields);
856
        $content .= $this->getClassObjectHandler($moduleDirname, $table, $fieldId, $fieldName, $fieldMain, $fieldParent, $fieldParentId, $fieldElement);
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...
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 $fieldMain does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The 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...
857
858
        $this->tf->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->tf (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...
859
860
        return $this->tf->renderFile();
0 ignored issues
show
Bug introduced by
The method renderFile cannot be called on $this->tf (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...
861
    }
862
}
863