Completed
Push — master ( 2ee26c...778493 )
by Gino
06:21 queued 02:34
created

ClassFiles::getOptionsCheck()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 27
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 27
rs 8.8571
cc 3
eloc 18
nc 3
nop 1
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
            $fieldId = $fields[$f]->getVar('field_id');
222
            $fieldName = $fields[$f]->getVar('field_name');
223
            $fieldElement = $fields[$f]->getVar('field_element');
224
            $fieldInForm[] = $fields[$f]->getVar('field_inform');
225
            $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...
226
            $fieldElementId[] = $fieldElements->getVar('fieldelement_id');
227
            $rpFieldName = $this->getRightString($fieldName);
228
            if (in_array(5, $fieldElementId)) {
229
                if (count($rpFieldName) % 5) {
230
                    $optionsFieldName[] = "'".$rpFieldName."'";
231
                } else {
232
                    $optionsFieldName[] = "'".$rpFieldName."'\n";
233
                }
234
            }
235
        }
236
        if (in_array(5, $fieldElementId) > 1) {
237
            $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...
238
            $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...
239
            $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...
240
            $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...
241
        }
242
        unset($optionsFieldName);
243
244
        $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...
245
        $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...
246
        $constr .= $this->getInitVars($fields);
247
        $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...
248
        $arrayGetInstance = array('@static function' => '&getInstance', '' => '', '@param' => 'null');
249
        $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...
250
        $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...
251
        $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...
252
        $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...
253
        $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...
254
255
        $cCl .= $this->getNewInsertId($table);
256
        $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...
257
        $cCl .= $this->getValuesInObject($moduleDirname, $table, $fields);
258
        $cCl .= $this->getToArrayInObject($table);
259
260
        if (in_array(5, $fieldElementId) > 1) {
261
            $cCl .= $this->getOptionsCheck($table);
262
        }
263
        unset($fieldElementId);
264
265
        $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...
266
267
        return $ret;
268
    }
269
270
    /*
271
     *  @private function getNewInsertId
272
     *  @param $table
273
     *
274
     * @return string
275
     */
276
    private function getNewInsertId($table)
277
    {
278
        $tableName = $table->getVar('table_name');
279
        $ucfTableName = ucfirst($tableName);
280
        $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...
281
        $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...
282
        $getInsertedId .= $this->getSimpleString('return $newInsertedId;', "\t\t");
283
284
        $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...
285
286
        return $ret;
287
    }
288
289
    /*
290
    *  @private function getFunctionForm
291
    *  @param string $module
292
    *  @param string $table
293
    */
294
    /**
295
     * @param $module
296
     * @param $table
297
     *
298
     * @return string
299
     */
300
    private function getFunctionForm($module, $table, $fieldId, $fieldInForm)
301
    {
302
        $moduleDirname = $module->getVar('mod_dirname');
303
        $tableName = $table->getVar('table_name');
304
        $tableSoleName = $table->getVar('table_solename');
305
        $tableCategory = $table->getVar('table_category');
306
        $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...
307
        $ucfTableName = ucfirst($tableName);
308
        $stuTableSoleName = strtoupper($tableSoleName);
309
        $language = $this->getLanguage($moduleDirname, 'AM');
310
        $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...
311
        $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...
312
        $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...
313
        $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...
314
        $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...
315
        $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...
316
        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...
317
            $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...
318
            $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...
319
            $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...
320
            $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...
321
            $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...
322
            $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...
323
            $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...
324
            $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...
325
            $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...
326
        }
327
        $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...
328
        $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...
329
        $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...
330
        $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...
331
        $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...
332
        $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...
333
        $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...
334
335
        if (in_array(1, $fieldInForm)) {
336
            if (1 == $table->getVar('table_permissions')) {
337
                $getForm .= $this->getPermissionsInForm($moduleDirname, $fieldId);
338
            }
339
        }
340
        $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...
341
        //$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...
342
        $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...
343
        //$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...
344
        $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...
345
        $getForm .= $this->getSimpleString('return $form;', "\t\t");
346
347
        $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...
348
349
        return $ret;
350
    }
351
352
    /*
353
    *  @private function getPermissionsInForm
354
    *  @param string $moduleDirname
355
    *  @param string $fieldId
356
    */
357
    /**
358
     * @param $moduleDirname
359
     * @param $fieldId
360
     *
361
     * @return string
362
     */
363
    private function getPermissionsInForm($moduleDirname, $fieldId)
364
    {
365
        $permissionApprove = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_APPROVE');
366
        $permissionSubmit = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_SUBMIT');
367
        $permissionView = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_VIEW');
368
        $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...
369
        $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...
370
        $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...
371
        $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...
372
        $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...
373
374
        $if = $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...
375
        $if .= $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...
376
        $if .= $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...
377
        $if .= $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...
378
        $if .= $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...
379
        $if .= $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...
380
        $if .= $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...
381
        $if .= $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...
382
        $if .= $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...
383
384
        $else = $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...
385
        $else .= $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...
386
        $else .= $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...
387
388
        $ret .= $this->pc->getPhpCodeConditions('!$this->isNew()', null, null, $if, $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...
389
        $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...
390
        $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...
391
        $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...
392
        $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...
393
        $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...
394
        $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...
395
        $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...
396
        $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...
397
        $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...
398
399
        return $ret;
400
    }
401
402
    /*
403
    *  @private function getValuesInObject
404
    *  @param null
405
    */
406
    /**
407
     * @return string
408
     */
409
    private function getValuesInObject($moduleDirname, $table, $fields)
410
    {
411
        $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...
412
        $ucfTableName = ucfirst($table->getVar('table_name'));
413
        $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...
414
        $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...
415
416
        foreach (array_keys($fields) as $f) {
417
            $fieldName = $fields[$f]->getVar('field_name');
418
            $fieldElement = $fields[$f]->getVar('field_element');
419
            $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...
420
            switch ($fieldElement) {
421
                case 3:
422
                case 4:
423
                    $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...
424
                break;
425
                case 8:
426
                    $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...
427
                break;
428
                case 15:
429
                    $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...
430
                break;
431
                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...
432
433
                    if ($fieldElement > 15) {
434
                        $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...
435
                        $fieldElementMid = $fieldElements->getVar('fieldelement_mid');
436
                        $fieldElementTid = $fieldElements->getVar('fieldelement_tid');
437
                        $fieldElementName = $fieldElements->getVar('fieldelement_name');
438
                        $fieldNameDesc = substr($fieldElementName, strrpos($fieldElementName, ':'), strlen($fieldElementName));
439
                        $topicTableName = str_replace(': ', '', strtolower($fieldNameDesc));
440
                        $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...
441
                        foreach (array_keys($fieldsTopics) as $f) {
442
                            $fieldNameTopic = $fieldsTopics[$f]->getVar('field_name');
443
                            if (1 == $fieldsTopics[$f]->getVar('field_main')) {
444
                                $fieldMainTopic = $fieldNameTopic;
445
                            }
446
                        }
447
                        $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...
448
                        $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...
449
                    } else {
450
                        $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...
451
                    }
452
                break;
453
            }
454
        }
455
        $getValues .= $this->getSimpleString('return $ret;', "\t\t");
456
457
        $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...
458
459
        return $ret;
460
    }
461
462
    /*
463
     *  @private function getToArrayInObject
464
     *  @param $table
465
     *
466
     * @return string
467
     */
468
    private function getToArrayInObject($table)
469
    {
470
        $tableName = $table->getVar('table_name');
471
        $ucfTableName = ucfirst($tableName);
472
        $multiLineCom = array('Returns an array representation' => 'of the object', '' => '', '@return' => 'array');
473
        $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...
474
475
        $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...
476
        $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...
477
        $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...
478
        $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...
479
        $getToArray .= $this->getSimpleString('return $ret;', "\t\t");
480
481
        $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...
482
483
        return $ret;
484
    }
485
486
    /*
487
    *  @private function getOptionsCheck
488
    *  @param $table
489
    */
490
    /**
491
     * @return string
492
     */
493
    private function getOptionsCheck($table)
494
    {
495
        $tableName = $table->getVar('table_name');
496
        $ucfTableName = ucfirst($tableName);
497
        $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...
498
        $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...
499
500
        $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...
501
        foreach (array_keys($fields) as $f) {
502
            $fieldName = $fields[$f]->getVar('field_name');
503
            $fieldElement = $fields[$f]->getVar('field_element');
504
            //
505
            $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...
506
            $fieldElementId = $fieldElements->getVar('fieldelement_id');
507
            $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...
508
            if (5 == $fieldElementId) {
509
                $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...
510
                $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...
511
            }
512
        }
513
514
        $getOptions .= $this->getSimpleString('return $ret;', "\t\t");
515
516
        $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...
517
518
        return $ret;
519
    }
520
521
    /*
522
    *  @public function getClassHandler
523
    *  @param string $moduleDirname
524
    *  @param string $tableName
525
    *  @param string $fieldId
526
    *  @param string $fieldMain
527
    */
528
    /**
529
     * @param $moduleDirname
530
     * @param $tableName
531
     * @param $tableCategory
532
     * @param $tableFieldname
533
     * @param $fieldId
534
     * @param $fieldMain
535
     *
536
     * @return string
537
     */
538
    private function getClassObjectHandler($moduleDirname, $table, $fieldId, $fieldName, $fieldMain, $fieldParent, $fieldParentId, $fieldElement)
539
    {
540
        $tableName = $table->getVar('table_name');
541
        $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...
542
        $tableSoleName = $table->getVar('table_solename');
543
        $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...
544
        $ucfModuleDirname = ucfirst($moduleDirname);
545
        $ucfTableName = ucfirst($tableName);
546
        $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...
547
        $ucfModuleTable = $ucfModuleDirname.$ucfTableName;
548
        $multiLineCom = array('Class Object Handler' => $ucfModuleDirname.$ucfTableName);
549
        $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...
550
551
        $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...
552
        $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...
553
554
        $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...
555
        $constr = "\t\tparent::__construct(\$db, '{$moduleDirname}_{$tableName}', '{$moduleDirname}{$tableName}', '{$fieldId}', '{$fieldMain}');\n";
556
        $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...
557
        $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...
558
559
        $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...
560
561
        $cClh .= $this->getClassCreate();
562
        $cClh .= $this->getClassGet();
563
        $cClh .= $this->getClassGetInsertId();
564
        $cClh .= $this->getClassGetIds();
565
        $cClh .= $this->getClassInsert();
566
        $cClh .= $this->getClassCounter($tableName, $fieldId, $fieldMain);
567
        $cClh .= $this->getClassAll($tableName, $fieldId, $fieldMain);
568
        $cClh .= $this->getClassCriteria($tableName);
569
        if (in_array(1, $fieldParentId) && $fieldElement > 15) {
570
            $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...
571
            $cClh .= $this->getClassGetTableSolenameById($moduleDirname, $table, $fieldMain);
572
        }
573
574
        $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...
575
576
        return $ret;
577
    }
578
579
    /**
580
     *  @public function getClassCreate
581
     *
582
     *  @return string
583
     */
584
    private function getClassCreate()
585
    {
586
        $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...
587
        $cClhc = $this->getSimpleString('return parent::create($isNew);', "\t\t");
588
589
        $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...
590
591
        return $ret;
592
    }
593
594
    /**
595
     *  @public function getClassGet
596
     *
597
     *  @return string
598
     */
599
    private function getClassGet()
600
    {
601
        $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...
602
        $cClhg = $this->getSimpleString('return parent::get($i, $fields);', "\t\t");
603
604
        $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...
605
606
        return $ret;
607
    }
608
609
    /**
610
     *  @public function getClassGetInsertId
611
     *
612
     *  @return string
613
     */
614
    private function getClassGetInsertId()
615
    {
616
        $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...
617
        $cClhgid = $this->getSimpleString('return $this->db->getInsertId();', "\t\t");
618
619
        $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...
620
621
        return $ret;
622
    }
623
624
    /**
625
     *  @public function getClassGetIds
626
     *
627
     *  @return string
628
     */
629
    private function getClassGetIds()
630
    {
631
        $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...
632
                                                            '@param object \$criteria' => '{@link CriteriaElement} to match',
633
                                                            '@return array of' => 'object IDs', ), "\t");
634
        $cClhgids = $this->getSimpleString('return parent::getIds($criteria);', "\t\t");
635
636
        $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...
637
638
        return $ret;
639
    }
640
641
    /**
642
     *  @public function getClassInsert
643
     *
644
     *  @return string
645
     */
646
    private function getClassInsert()
647
    {
648
        $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...
649
                                                            '@param object \$field reference to the' => '{@link insert} object',
650
                                                            '@param bool' => '$force', 'return bool FALSE if failed,' => 'TRUE if already present and unchanged or successful', ), "\t");
651
        $cClhinsert = $this->getSimpleString('return false;', "\t\t\t");
652
653
        $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...
654
        $if .= $this->getSimpleString('return true;', "\t\t");
655
656
        $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...
657
658
        return $ret;
659
    }
660
661
    /**
662
     *  @public function getClassCounter
663
     *
664
     *  @param $tableName
665
     *  @param $fieldId
666
     *  @param $fieldMain
667
     *
668
     *  @return string
669
     */
670
    private function getClassCounter($tableName, $fieldId, $fieldMain)
671
    {
672
        $ucfTableName = ucfirst($tableName);
673
        $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...
674
675
        $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...
676
        $paramsCrit = "\$this->get{$ucfTableName}Criteria(\$criteriaCount{$ucfTableName}, \$start, \$limit, \$sort, \$order)";
677
        $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...
678
        $critCount .= $this->getSimpleString("return parent::getCount(\$criteriaCount{$ucfTableName});", "\t\t");
679
        $params = "\$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC'";
680
681
        $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...
682
683
        return $ret;
684
    }
685
686
    /**
687
     *  @public function getClassAll
688
     *
689
     *  @param $tableName
690
     *  @param $fieldId
691
     *  @param $fieldMain
692
     *
693
     *  @return string
694
     */
695
    private function getClassAll($tableName, $fieldId, $fieldMain)
696
    {
697
        $ucfTableName = ucfirst($tableName);
698
        $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...
699
700
        $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...
701
        $paramsCrit = "\$this->get{$ucfTableName}Criteria(\$criteriaAll{$ucfTableName}, \$start, \$limit, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC')";
702
        $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...
703
        $critAll .= $this->getSimpleString("return parent::getAll(\$criteriaAll{$ucfTableName});", "\t\t");
704
        $params = "\$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC'";
705
706
        $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...
707
708
        return $ret;
709
    }
710
711
    /**
712
     *  @public function getClassByCategory
713
     *
714
     *  @param $tableName
715
     *  @param $fieldId
716
     *  @param $fieldMain
717
     *  @param $fieldParent
718
     *
719
     *  @return string
720
     */
721
    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...
722
    {
723
        $ucfTableName = ucfirst($tableName);
724
        $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...
725
        $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...
726
        $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...
727
        $fieldElementName = $fieldElements->getVar('fieldelement_name');
728
        $fieldNameDesc = ucfirst(substr($fieldElementName, strrpos($fieldElementName, ':'), strlen($fieldElementName)));
729
        $topicTableName = str_replace(': ', '', $fieldNameDesc);
730
        $lcfTopicTableName = lcfirst($topicTableName);
731
732
        $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...
733
734
        $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...
735
        $param1 = "'{$moduleDirname}_view'";
736
        $param2 = "\$GLOBALS['xoopsUser']->getGroups()";
737
        $param3 = "\$GLOBALS['xoopsModule']->getVar('mid')";
738
        $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...
739
        $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...
740
741
        if (strstr($fieldName, 'status')) {
742
            $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...
743
            $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...
744
        }
745
        $paramsCritAll = "\$this->get{$ucfTableName}Criteria(\$criteriaAll{$ucfTableName}, \$start, \$limit, \$sort, \$order)";
746
        $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...
747
748
        $critAll .= $this->getSimpleString("return parent::getAll(\$criteriaAll{$ucfTableName});", "\t\t");
749
        $params = "\${$tableFieldName}Id, \$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC'";
750
751
        $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...
752
753
        return $ret;
754
    }
755
756
    /**
757
     *  @public function getClassCriteria
758
     *
759
     *  @param $tableName
760
     *  @param $fieldId
761
     *  @param $fieldMain
762
     *
763
     *  @return string
764
     */
765
    private function getClassCriteria($tableName)
766
    {
767
        $ucfTableName = ucfirst($tableName);
768
        $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...
769
770
        $paramsAllCriteria = "\$criteria{$ucfTableName}, \$start, \$limit, \$sort, \$order";
771
772
        $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...
773
        $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...
774
        $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...
775
        $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...
776
        $critSets .= $this->getSimpleString("return \$criteria{$ucfTableName};", "\t\t");
777
778
        $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...
779
780
        return $ret;
781
    }
782
783
    /**
784
     *  @public function getClassGetTableSolenameById
785
     *
786
     *  @param $moduleDirname
787
     *  @param $table
788
     *
789
     *  @return string
790
     */
791
    private function getClassGetTableSolenameById($moduleDirname, $table, $fieldMain)
792
    {
793
        $tableName = $table->getVar('table_name');
794
        $tableSoleName = $table->getVar('table_solename');
795
        $ucfTableSoleName = ucfirst($tableSoleName);
796
        $ccTableSoleName = $this->getCamelCase($tableSoleName, true);
797
        $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...
798
        $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...
799
        $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...
800
801
        $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...
802
        $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...
803
        $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...
804
        $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...
805
806
        $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...
807
        $soleName .= $this->getSimpleString("return \${$tableSoleName};", "\t\t");
808
809
        $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...
810
811
        return $ret;
812
    }
813
814
    /*
815
     * @public function render    
816
     * @param null
817
     *
818
     * @return bool|string
819
     */
820
    public function render()
821
    {
822
        $module = $this->getModule();
823
        $table = $this->getTable();
824
        $filename = $this->getFileName();
825
        $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...
826
        $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...
827
        $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...
828
        $moduleDirname = $module->getVar('mod_dirname');
829
        $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...
830
        $fieldInForm = array();
831
        $fieldParentId = array();
832
        $fieldElementId = array();
833
        $fieldParent = null;
834
        foreach (array_keys($fields) as $f) {
835
            $fieldName = $fields[$f]->getVar('field_name');
836
            $fieldInForm[] = $fields[$f]->getVar('field_inform');
837
            $fieldParentId[] = $fields[$f]->getVar('field_parent');
838
            if ((0 == $f) && (1 == $table->getVar('table_autoincrement'))) {
839
                $fieldId = $fieldName; // $fieldId = fields parameter index field
840
            }
841
            if (1 == $fields[$f]->getVar('field_main')) {
842
                $fieldMain = $fieldName; // $fieldMain = fields parameter main field
843
            }
844
            if (1 == $fields[$f]->getVar('field_parent')) {
845
                $fieldParent = $fieldName; // $fieldParent = fields parameter parent field
846
            }
847
            $fieldElement = $fields[$f]->getVar('field_element');
848
            //
849
            $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...
850
            $fieldElementId[] = $fieldElements->getVar('fieldelement_id');
851
        }
852
        $content = $this->getHeaderFilesComments($module, $filename);
853
        $content .= $this->getClassObject($module, $table, $fields);
854
        $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...
855
856
        $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...
857
858
        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...
859
    }
860
}
861