Completed
Push — master ( a8ea98...cecb98 )
by Gino
06:23 queued 03:11
created

ClassFiles::getOptionsCheck()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 27
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
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
 * tdmcreate module.
14
 *
15
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 *
18
 * @since           2.5.0
19
 *
20
 * @author          Txmod Xoops http://www.txmodxoops.org
21
 *
22
 * @version         $Id: ClassFiles.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
25
/**
26
 * Class ClassFiles.
27
 */
28
class ClassFiles extends TDMCreateFile
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

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

namespace YourVendor;

class YourClass { }

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

Loading history...
29
{
30
    /*
31
    * @var string
32
    */
33
    private $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 $formelements = null;
54
55
    /*
56
    *  @public function constructor
57
    *  @param null
58
    */
59
    /**
60
     *
61
     */
62
    public function __construct()
63
    {
64
        parent::__construct();
65
        $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...
66
        $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...
67
        $this->tdmcreate = TDMCreateHelper::getInstance();
0 ignored issues
show
Bug introduced by
The property tdmcreate cannot be accessed from this context as it is declared private in class TDMCreateFile.

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

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

Loading history...
Documentation Bug introduced by
It seems like \TDMCreateHelper::getInstance() of type object<TDMCreateHelper> is incompatible with the declared type string of property $tdmcreate.

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

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

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

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

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

Loading history...
71
    }
72
73
    /*
74
    *  @static function &getInstance
75
    *  @param null
76
    */
77
    /**
78
     * @return ClassFiles
79
     */
80
    public static function &getInstance()
81
    {
82
        static $instance = false;
83
        if (!$instance) {
84
            $instance = new self();
85
        }
86
87
        return $instance;
88
    }
89
90
    /*
91
    *  @public function write
92
    *  @param string $module
93
    *  @param string $table
94
    *  @param mixed $tables
95
    */
96
    /**
97
     * @param $module
98
     * @param $table
99
     * @param $tables
100
     */
101
    public function write($module, $table, $tables, $filename)
102
    {
103
        $this->setModule($module);
104
        $this->setTable($table);
105
        $this->setTables($tables);
106
        $this->setFileName($filename);
107
    }
108
109
    /*
110
    *  @private function getInitVar
111
    *  @param string $fieldName
112
    *  @param string $type
113
    */
114
    /**
115
     * @param        $fieldName
116
     * @param string $type
117
     *
118
     * @return string
119
     */
120
    private function getInitVar($fieldName, $type = 'INT')
121
    {
122
        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...
123
    }
124
125
    /*
126
    *  @private function getInitVars
127
    *  @param array $fields
128
    */
129
    /**
130
     * @param $fields
131
     *
132
     * @return string
133
     */
134
    private function getInitVars($fields)
135
    {
136
        $ret = '';
137
        // Creation of the initVar functions list
138
        foreach (array_keys($fields) as $f) {
139
            $fieldName = $fields[$f]->getVar('field_name');
140
            $fieldType = $fields[$f]->getVar('field_type');
141
            if ($fieldType > 1) {
142
                $fType = $this->tdmcreate->getHandler('fieldtype')->get($fieldType);
0 ignored issues
show
Bug introduced by
The property tdmcreate cannot be accessed from this context as it is declared private in class TDMCreateFile.

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

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

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

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

Loading history...
143
                $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...
144
            } else {
145
                $fieldType = null;
146
            }
147
            switch ($fieldType) {
148
                case 2:
149
                case 3:
150
                case 4:
151
                case 5:
152
                    $ret .= $this->getInitVar($fieldName, 'INT');
153
                    break;
154
                case 6:
155
                    $ret .= $this->getInitVar($fieldName, 'FLOAT');
156
                    break;
157
                case 7:
158
                case 8:
159
                    $ret .= $this->getInitVar($fieldName, 'DECIMAL');
160
                    break;
161
                case 10:
162
                    $ret .= $this->getInitVar($fieldName, 'ENUM');
163
                    break;
164
                case 11:
165
                    $ret .= $this->getInitVar($fieldName, 'EMAIL');
166
                    break;
167
                case 12:
168
                    $ret .= $this->getInitVar($fieldName, 'URL');
169
                    break;
170
                case 13:
171
                case 14:
172
                    $ret .= $this->getInitVar($fieldName, 'TXTBOX');
173
                    break;
174
                case 15:
175
                case 16:
176
                case 17:
177
                case 18:
178
                    $ret .= $this->getInitVar($fieldName, 'TXTAREA');
179
                    break;
180
                case 19:
181
                case 20:
182
                case 21:
183
                case 22:
184
                case 23:
185
                    $ret .= $this->getInitVar($fieldName, 'LTIME');
186
                    break;
187
            }
188
        }
189
190
        return $ret;
191
    }
192
193
    /*
194
    *  @private function getClassObject
195
    *  @param $moduleDirname
196
    *  @param $tableName
197
    *  @param $fields   
198
    *
199
    *  @return string
200
    */
201
    private function getClassObject($module, $table, $fields)
202
    {
203
        $moduleDirname = $module->getVar('mod_dirname');
204
        $tableName = $table->getVar('table_name');
205
        $ucfModuleDirname = ucfirst($moduleDirname);
206
        $ucfTableName = ucfirst($tableName);
207
        $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...
208
        $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...
209
        $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...
210
        $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...
211
212
        $fieldInForm = array();
213
        $fieldElementId = array();
214
        $optionsFieldName = array();
215
        foreach (array_keys($fields) as $f) {
216
            $fieldId = $fields[$f]->getVar('field_id');
217
            $fieldName = $fields[$f]->getVar('field_name');
218
            $fieldElement = $fields[$f]->getVar('field_element');
219
            $fieldInForm[] = $fields[$f]->getVar('field_inform');
220
            $fieldElements = $this->tdmcreate->getHandler('fieldelements')->get($fieldElement);
0 ignored issues
show
Bug introduced by
The property tdmcreate cannot be accessed from this context as it is declared private in class TDMCreateFile.

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

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

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

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

Loading history...
221
            $fieldElementId[] = $fieldElements->getVar('fieldelement_id');
222
            $rpFieldName = $this->getRightString($fieldName);
223
            if (in_array(5, $fieldElementId)) {
224
                if (count($rpFieldName) % 5) {
225
                    $optionsFieldName[] = "'".$rpFieldName."'";
226
                } else {
227
                    $optionsFieldName[] = "'".$rpFieldName."'\n";
228
                }
229
            }
230
        }
231
        if (in_array(5, $fieldElementId) > 1) {
232
            $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...
233
            $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...
234
            $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...
235
            $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...
236
        }
237
        unset($optionsFieldName);
238
239
        $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...
240
        $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...
241
        $constr .= $this->getInitVars($fields);
242
        $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...
243
        $arrayGetInstance = array('@static function' => '&getInstance', '' => '', '@param' => 'null');
244
        $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...
245
        $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...
246
        $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...
247
        $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...
248
        $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...
249
250
        $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...
251
        $cCl .= $this->getValuesInObject($moduleDirname, $table, $fields);
252
        $cCl .= $this->getToArrayInObject($table);
253
254
        if (in_array(5, $fieldElementId) > 1) {
255
            $cCl .= $this->getOptionsCheck($table);
256
        }
257
        unset($fieldElementId);
258
259
        $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...
260
261
        return $ret;
262
    }
263
264
    /*
265
    *  @private function getFunctionForm
266
    *  @param string $module
267
    *  @param string $table
268
    */
269
    /**
270
     * @param $module
271
     * @param $table
272
     *
273
     * @return string
274
     */
275
    private function getFunctionForm($module, $table, $fieldId, $fieldInForm)
276
    {
277
        $moduleDirname = $module->getVar('mod_dirname');
278
        $tableName = $table->getVar('table_name');
279
        $tableSoleName = $table->getVar('table_solename');
280
        $tableCategory = $table->getVar('table_category');
281
        $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...
282
        $ucfTableName = ucfirst($tableName);
283
        $stuTableSoleName = strtoupper($tableSoleName);
284
        $language = $this->getLanguage($moduleDirname, 'AM');
285
        $this->formelements->initForm($module, $table);
0 ignored issues
show
Bug introduced by
The method initForm cannot be called on $this->formelements (of type string).

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

Loading history...
286
        $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...
287
        $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...
288
        $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...
289
        $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...
290
        $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...
291
        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...
292
            $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...
293
            $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...
294
            $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...
295
            $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...
296
            $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...
297
            $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...
298
            $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...
299
            $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...
300
            $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...
301
        }
302
        $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...
303
        $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...
304
        $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...
305
        $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...
306
        $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...
307
        $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...
308
        $getForm .= $this->formelements->renderElements();
0 ignored issues
show
Bug introduced by
The method renderElements cannot be called on $this->formelements (of type string).

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

Loading history...
309
310
        if (in_array(1, $fieldInForm)) {
311
            if (1 == $table->getVar('table_permissions')) {
312
                $getForm .= $this->getPermissionsInForm($moduleDirname, $fieldId);
313
            }
314
        }
315
        $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...
316
        //$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...
317
        $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...
318
        //$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...
319
        $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...
320
        $getForm .= $this->getSimpleString('return $form;', "\t\t");
321
322
        $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...
323
324
        return $ret;
325
    }
326
327
    /*
328
    *  @private function getPermissionsInForm
329
    *  @param string $moduleDirname
330
    *  @param string $fieldId
331
    */
332
    /**
333
     * @param $moduleDirname
334
     * @param $fieldId
335
     *
336
     * @return string
337
     */
338
    private function getPermissionsInForm($moduleDirname, $fieldId)
339
    {
340
        $permissionApprove = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_APPROVE');
341
        $permissionSubmit = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_SUBMIT');
342
        $permissionView = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_VIEW');
343
        $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...
344
        $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...
345
        $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...
346
        $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...
347
        $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...
348
349
        $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...
350
        $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...
351
        $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...
352
        $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...
353
        $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...
354
        $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...
355
        $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...
356
        $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...
357
        $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...
358
359
        $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...
360
        $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...
361
        $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...
362
363
        $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...
364
        $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...
365
        $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...
366
        $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...
367
        $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...
368
        $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...
369
        $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...
370
        $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...
371
        $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...
372
        $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...
373
374
        return $ret;
375
    }
376
377
    /*
378
    *  @private function getValuesInObject
379
    *  @param null
380
    */
381
    /**
382
     * @return string
383
     */
384
    private function getValuesInObject($moduleDirname, $table, $fields)
385
    {
386
        $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...
387
        $ucfTableName = ucfirst($table->getVar('table_name'));
388
        $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...
389
        $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...
390
391
        foreach (array_keys($fields) as $f) {
392
            $fieldName = $fields[$f]->getVar('field_name');
393
            $fieldElement = $fields[$f]->getVar('field_element');
394
            $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...
395
            switch ($fieldElement) {
396
                case 3:
397
                case 4:
398
                    $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...
399
                break;
400
                case 8:
401
                    $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...
402
                break;
403
                case 15:
404
                    $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...
405
                break;
406
                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...
407
408
                    if ($fieldElement > 15) {
409
                        $fieldElements = $this->tdmcreate->getHandler('fieldelements')->get($fieldElement);
0 ignored issues
show
Bug introduced by
The property tdmcreate cannot be accessed from this context as it is declared private in class TDMCreateFile.

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

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

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

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

Loading history...
410
                        $fieldElementMid = $fieldElements->getVar('fieldelement_mid');
411
                        $fieldElementTid = $fieldElements->getVar('fieldelement_tid');
412
                        $fieldElementName = $fieldElements->getVar('fieldelement_name');
413
                        $fieldNameDesc = substr($fieldElementName, strrpos($fieldElementName, ':'), strlen($fieldElementName));
414
                        $topicTableName = str_replace(': ', '', strtolower($fieldNameDesc));
415
                        $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...
416
                        foreach (array_keys($fieldsTopics) as $f) {
417
                            $fieldNameTopic = $fieldsTopics[$f]->getVar('field_name');
418
                            if (1 == $fieldsTopics[$f]->getVar('field_main')) {
419
                                $fieldMainTopic = $fieldNameTopic;
420
                            }
421
                        }
422
                        $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...
423
                        $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...
424
                    } else {
425
                        $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...
426
                    }
427
                break;
428
            }
429
        }
430
        $getValues .= $this->getSimpleString('return $ret;', "\t\t");
431
432
        $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...
433
434
        return $ret;
435
    }
436
437
    /*
438
     *  @private function getToArrayInObject
439
     *  @param $table
440
     *
441
     * @return string
442
     */
443
    private function getToArrayInObject($table)
444
    {
445
        $tableName = $table->getVar('table_name');
446
        $ucfTableName = ucfirst($tableName);
447
        $multiLineCom = array('Returns an array representation' => 'of the object', '' => '', '@return' => 'array');
448
        $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...
449
450
        $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...
451
        $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...
452
        $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...
453
        $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...
454
        $getToArray .= $this->getSimpleString('return $ret;', "\t\t");
455
456
        $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...
457
458
        return $ret;
459
    }
460
461
    /*
462
    *  @private function getOptionsCheck
463
    *  @param $table
464
    */
465
    /**
466
     * @return string
467
     */
468
    private function getOptionsCheck($table)
469
    {
470
        $tableName = $table->getVar('table_name');
471
        $ucfTableName = ucfirst($tableName);
472
        $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...
473
        $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...
474
475
        $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...
476
        foreach (array_keys($fields) as $f) {
477
            $fieldName = $fields[$f]->getVar('field_name');
478
            $fieldElement = $fields[$f]->getVar('field_element');
479
            //
480
            $fieldElements = $this->tdmcreate->getHandler('fieldelements')->get($fieldElement);
0 ignored issues
show
Bug introduced by
The property tdmcreate cannot be accessed from this context as it is declared private in class TDMCreateFile.

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

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

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

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

Loading history...
481
            $fieldElementId = $fieldElements->getVar('fieldelement_id');
482
            $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...
483
            if (5 == $fieldElementId) {
484
                $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...
485
                $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...
486
            }
487
        }
488
489
        $getOptions .= $this->getSimpleString('return $ret;', "\t\t");
490
491
        $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...
492
493
        return $ret;
494
    }
495
496
    /*
497
    *  @public function getClassHandler
498
    *  @param string $moduleDirname
499
    *  @param string $tableName
500
    *  @param string $fieldId
501
    *  @param string $fieldMain
502
    */
503
    /**
504
     * @param $moduleDirname
505
     * @param $tableName
506
     * @param $tableCategory
507
     * @param $tableFieldname
508
     * @param $fieldId
509
     * @param $fieldMain
510
     *
511
     * @return string
512
     */
513
    private function getClassObjectHandler($moduleDirname, $table, $fieldId, $fieldName, $fieldMain, $fieldParent, $fieldParentId, $fieldElement)
514
    {
515
        $tableName = $table->getVar('table_name');
516
        $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...
517
        $tableSoleName = $table->getVar('table_solename');
518
        $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...
519
        $ucfModuleDirname = ucfirst($moduleDirname);
520
        $ucfTableName = ucfirst($tableName);
521
        $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...
522
        $ucfModuleTable = $ucfModuleDirname.$ucfTableName;
523
        $multiLineCom = array('Class Object Handler' => $ucfModuleDirname.$ucfTableName);
524
        $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...
525
526
        $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...
527
        $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...
528
529
        $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...
530
        $constr = "\t\tparent::__construct(\$db, '{$moduleDirname}_{$tableName}', '{$moduleDirname}{$tableName}', '{$fieldId}', '{$fieldMain}');\n";
531
        $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...
532
533
        $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...
534
535
        $cClh .= $this->getClassCreate();
536
        $cClh .= $this->getClassGet();
537
        $cClh .= $this->getClassGetInsertId();
538
        $cClh .= $this->getClassGetIds();
539
        $cClh .= $this->getClassInsert();
540
        $cClh .= $this->getClassCounter($tableName, $fieldId, $fieldMain);
541
        $cClh .= $this->getClassAll($tableName, $fieldId, $fieldMain);
542
        $cClh .= $this->getClassCriteria($tableName);
543
        if (in_array(1, $fieldParentId) && $fieldElement > 15) {
544
            $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...
545
            $cClh .= $this->getClassGetTableSolenameById($moduleDirname, $table, $fieldMain);
546
        }
547
548
        $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...
549
550
        return $ret;
551
    }
552
553
    /**
554
     *  @public function getClassCreate
555
     *
556
     *  @return string
557
     */
558
    private function getClassCreate()
559
    {
560
        $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...
561
        $cClhc = $this->getSimpleString('return parent::create($isNew);', "\t\t");
562
563
        $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...
564
565
        return $ret;
566
    }
567
568
    /**
569
     *  @public function getClassGet
570
     *
571
     *  @return string
572
     */
573
    private function getClassGet()
574
    {
575
        $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...
576
        $cClhg = $this->getSimpleString('return parent::get($i, $fields);', "\t\t");
577
578
        $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...
579
580
        return $ret;
581
    }
582
583
    /**
584
     *  @public function getClassGetInsertId
585
     *
586
     *  @return string
587
     */
588
    private function getClassGetInsertId()
589
    {
590
        $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...
591
        $cClhgid = $this->getSimpleString('return $this->db->getInsertId();', "\t\t");
592
593
        $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...
594
595
        return $ret;
596
    }
597
598
    /**
599
     *  @public function getClassGetIds
600
     *
601
     *  @return string
602
     */
603
    private function getClassGetIds()
604
    {
605
        $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...
606
                                                            '@param object \$criteria' => '{@link CriteriaElement} to match',
607
                                                            '@return array of' => 'object IDs', ), "\t");
608
        $cClhgids = $this->getSimpleString('return parent::getIds($criteria);', "\t\t");
609
610
        $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...
611
612
        return $ret;
613
    }
614
615
    /**
616
     *  @public function getClassInsert
617
     *
618
     *  @return string
619
     */
620
    private function getClassInsert()
621
    {
622
        $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...
623
                                                            '@param object \$field reference to the' => '{@link insert} object',
624
                                                            '@param bool' => '$force', 'return bool FALSE if failed,' => 'TRUE if already present and unchanged or successful', ), "\t");
625
        $cClhinsert = $this->getSimpleString('return false;', "\t\t\t");
626
627
        $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...
628
        $if .= $this->getSimpleString('return true;', "\t\t");
629
630
        $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...
631
632
        return $ret;
633
    }
634
635
    /**
636
     *  @public function getClassCounter
637
     *
638
     *  @param $tableName
639
     *  @param $fieldId
640
     *  @param $fieldMain
641
     *
642
     *  @return string
643
     */
644
    private function getClassCounter($tableName, $fieldId, $fieldMain)
645
    {
646
        $ucfTableName = ucfirst($tableName);
647
        $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...
648
649
        $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...
650
        $paramsCrit = "\$this->get{$ucfTableName}Criteria(\$criteriaCount{$ucfTableName}, \$start, \$limit, \$sort, \$order)";
651
        $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...
652
        $critCount .= $this->getSimpleString("return parent::getCount(\$criteriaCount{$ucfTableName});", "\t\t");
653
        $params = "\$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC'";
654
655
        $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...
656
657
        return $ret;
658
    }
659
660
    /**
661
     *  @public function getClassAll
662
     *
663
     *  @param $tableName
664
     *  @param $fieldId
665
     *  @param $fieldMain
666
     *
667
     *  @return string
668
     */
669
    private function getClassAll($tableName, $fieldId, $fieldMain)
670
    {
671
        $ucfTableName = ucfirst($tableName);
672
        $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...
673
674
        $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...
675
        $paramsCrit = "\$this->get{$ucfTableName}Criteria(\$criteriaAll{$ucfTableName}, \$start, \$limit, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC')";
676
        $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...
677
        $critAll .= $this->getSimpleString("return parent::getAll(\$criteriaAll{$ucfTableName});", "\t\t");
678
        $params = "\$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC'";
679
680
        $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...
681
682
        return $ret;
683
    }
684
685
    /**
686
     *  @public function getClassByCategory
687
     *
688
     *  @param $tableName
689
     *  @param $fieldId
690
     *  @param $fieldMain
691
     *  @param $fieldParent
692
     *
693
     *  @return string
694
     */
695
    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...
696
    {
697
        $ucfTableName = ucfirst($tableName);
698
        $fieldElements = $this->tdmcreate->getHandler('fieldelements')->get($fieldElement);
0 ignored issues
show
Bug introduced by
The property tdmcreate cannot be accessed from this context as it is declared private in class TDMCreateFile.

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

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

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

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

Loading history...
699
        $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...
700
        $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...
701
        $fieldElementName = $fieldElements->getVar('fieldelement_name');
702
        $fieldNameDesc = ucfirst(substr($fieldElementName, strrpos($fieldElementName, ':'), strlen($fieldElementName)));
703
        $topicTableName = str_replace(': ', '', $fieldNameDesc);
704
        $lcfTopicTableName = lcfirst($topicTableName);
705
706
        $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...
707
708
        $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...
709
        $param1 = "'{$moduleDirname}_view'";
710
        $param2 = "\$GLOBALS['xoopsUser']->getGroups()";
711
        $param3 = "\$GLOBALS['xoopsModule']->getVar('mid')";
712
        $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...
713
        $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...
714
715
        if (strstr($fieldName, 'status')) {
716
            $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...
717
            $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...
718
        }
719
        $paramsCritAll = "\$this->get{$ucfTableName}Criteria(\$criteriaAll{$ucfTableName}, \$start, \$limit, \$sort, \$order)";
720
        $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...
721
722
        $critAll .= $this->getSimpleString("return parent::getAll(\$criteriaAll{$ucfTableName});", "\t\t");
723
        $params = "\${$tableFieldName}Id, \$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC'";
724
725
        $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...
726
727
        return $ret;
728
    }
729
730
    /**
731
     *  @public function getClassCriteria
732
     *
733
     *  @param $tableName
734
     *  @param $fieldId
735
     *  @param $fieldMain
736
     *
737
     *  @return string
738
     */
739
    private function getClassCriteria($tableName)
740
    {
741
        $ucfTableName = ucfirst($tableName);
742
        $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...
743
744
        $paramsAllCriteria = "\$criteria{$ucfTableName}, \$start, \$limit, \$sort, \$order";
745
746
        $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...
747
        $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...
748
        $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...
749
        $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...
750
        $critSets .= $this->getSimpleString("return \$criteria{$ucfTableName};", "\t\t");
751
752
        $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...
753
754
        return $ret;
755
    }
756
757
    /**
758
     *  @public function getClassGetTableSolenameById
759
     *
760
     *  @param $moduleDirname
761
     *  @param $table
762
     *
763
     *  @return string
764
     */
765
    private function getClassGetTableSolenameById($moduleDirname, $table, $fieldMain)
766
    {
767
        $tableName = $table->getVar('table_name');
768
        $tableSoleName = $table->getVar('table_solename');
769
        $ucfTableSoleName = ucfirst($tableSoleName);
770
        $ret = <<<EOT
771
	/**
772
     * Returns the {$ucfTableSoleName} from id
773
     *
774
     * @return string
775
     **/
776
    public function get{$ucfTableSoleName}FromId(\${$tableSoleName}Id)
777
    {
778
        \${$tableSoleName}Id = (int) ( \${$tableSoleName}Id );
779
        \${$tableSoleName} = '';
780
        if(\${$tableSoleName}Id > 0) {
781
            \${$tableName}Handler = \$this->{$moduleDirname}->getHandler( '{$tableName}' );
782
            \${$tableSoleName}Obj = & \${$tableName}Handler->get( \${$tableSoleName}Id );
783
            if(is_object( \${$tableSoleName}Obj )) {
784
                \${$tableSoleName} = \${$tableSoleName}Obj->getVar( '{$fieldMain}' );
785
            }
786
        }
787
        return \${$tableSoleName};
788
    }\n
789
EOT;
790
791
        return $ret;
792
    }
793
794
    /*
795
     * @public function render    
796
     * @param null
797
     *
798
     * @return bool|string
799
     */
800
    public function render()
801
    {
802
        $module = $this->getModule();
803
        $table = $this->getTable();
804
        $filename = $this->getFileName();
805
        $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...
806
        $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...
807
        $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...
808
        $moduleDirname = $module->getVar('mod_dirname');
809
        $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...
810
        $fieldInForm = array();
811
        $fieldParentId = array();
812
        $fieldElementId = array();
813
        $fieldParent = null;
814
        foreach (array_keys($fields) as $f) {
815
            $fieldName = $fields[$f]->getVar('field_name');
816
            $fieldInForm[] = $fields[$f]->getVar('field_inform');
817
            $fieldParentId[] = $fields[$f]->getVar('field_parent');
818
            if ((0 == $f) && (1 == $table->getVar('table_autoincrement'))) {
819
                $fieldId = $fieldName; // $fieldId = fields parameter index field
820
            }
821
            if (1 == $fields[$f]->getVar('field_main')) {
822
                $fieldMain = $fieldName; // $fieldMain = fields parameter main field
823
            }
824
            if (1 == $fields[$f]->getVar('field_parent')) {
825
                $fieldParent = $fieldName; // $fieldParent = fields parameter parent field
826
            }
827
            $fieldElement = $fields[$f]->getVar('field_element');
828
            //
829
            $fieldElements = $this->tdmcreate->getHandler('fieldelements')->get($fieldElement);
0 ignored issues
show
Bug introduced by
The property tdmcreate cannot be accessed from this context as it is declared private in class TDMCreateFile.

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

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

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

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

Loading history...
830
            $fieldElementId[] = $fieldElements->getVar('fieldelement_id');
831
        }
832
        $content = $this->getHeaderFilesComments($module, $filename);
833
        $content .= $this->getClassObject($module, $table, $fields);
834
        $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...
835
836
        $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...
837
838
        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...
839
    }
840
}
841