Completed
Pull Request — master (#81)
by Gino
03:14
created

ClassFiles::getPermissionsInForm()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 38
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 38
rs 8.8571
cc 1
eloc 32
nc 1
nop 2
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 $fe = 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->fe = ClassFormElements::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like \ClassFormElements::getInstance() of type object<ClassFormElements> is incompatible with the declared type string of property $fe.

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

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

Loading history...
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->fe->initForm($module, $table);
0 ignored issues
show
Bug introduced by
The method initForm cannot be called on $this->fe (of type string).

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

Loading history...
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->fe->renderElements();
0 ignored issues
show
Bug introduced by
The method renderElements cannot be called on $this->fe (of type string).

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

Loading history...
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
        $constr .= $this->xc->getXoopsCodeEqualsOperator('$this->db', '$db', null, false, "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeEqualsOperator cannot be called on $this->xc (of type string).

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

Loading history...
533
534
        $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...
535
536
        $cClh .= $this->getClassCreate();
537
        $cClh .= $this->getClassGet();
538
        $cClh .= $this->getClassGetInsertId();
539
        $cClh .= $this->getClassGetIds();
540
        $cClh .= $this->getClassInsert();
541
        $cClh .= $this->getClassCounter($tableName, $fieldId, $fieldMain);
542
        $cClh .= $this->getClassAll($tableName, $fieldId, $fieldMain);
543
        $cClh .= $this->getClassCriteria($tableName);
544
        if (in_array(1, $fieldParentId) && $fieldElement > 15) {
545
            $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...
546
            $cClh .= $this->getClassGetTableSolenameById($moduleDirname, $table, $fieldMain);
547
        }
548
549
        $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...
550
551
        return $ret;
552
    }
553
554
    /**
555
     *  @public function getClassCreate
556
     *
557
     *  @return string
558
     */
559
    private function getClassCreate()
560
    {
561
        $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...
562
        $cClhc = $this->getSimpleString('return parent::create($isNew);', "\t\t");
563
564
        $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...
565
566
        return $ret;
567
    }
568
569
    /**
570
     *  @public function getClassGet
571
     *
572
     *  @return string
573
     */
574
    private function getClassGet()
575
    {
576
        $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...
577
        $cClhg = $this->getSimpleString('return parent::get($i, $fields);', "\t\t");
578
579
        $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...
580
581
        return $ret;
582
    }
583
584
    /**
585
     *  @public function getClassGetInsertId
586
     *
587
     *  @return string
588
     */
589
    private function getClassGetInsertId()
590
    {
591
        $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...
592
        $cClhgid = $this->getSimpleString('return $this->db->getInsertId();', "\t\t");
593
594
        $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...
595
596
        return $ret;
597
    }
598
599
    /**
600
     *  @public function getClassGetIds
601
     *
602
     *  @return string
603
     */
604
    private function getClassGetIds()
605
    {
606
        $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...
607
                                                            '@param object \$criteria' => '{@link CriteriaElement} to match',
608
                                                            '@return array of' => 'object IDs', ), "\t");
609
        $cClhgids = $this->getSimpleString('return parent::getIds($criteria);', "\t\t");
610
611
        $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...
612
613
        return $ret;
614
    }
615
616
    /**
617
     *  @public function getClassInsert
618
     *
619
     *  @return string
620
     */
621
    private function getClassInsert()
622
    {
623
        $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...
624
                                                            '@param object \$field reference to the' => '{@link insert} object',
625
                                                            '@param bool' => '$force', 'return bool FALSE if failed,' => 'TRUE if already present and unchanged or successful', ), "\t");
626
        $cClhinsert = $this->getSimpleString('return false;', "\t\t\t");
627
628
        $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...
629
        $if .= $this->getSimpleString('return true;', "\t\t");
630
631
        $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...
632
633
        return $ret;
634
    }
635
636
    /**
637
     *  @public function getClassCounter
638
     *
639
     *  @param $tableName
640
     *  @param $fieldId
641
     *  @param $fieldMain
642
     *
643
     *  @return string
644
     */
645
    private function getClassCounter($tableName, $fieldId, $fieldMain)
646
    {
647
        $ucfTableName = ucfirst($tableName);
648
        $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...
649
650
        $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...
651
        $paramsCrit = "\$this->get{$ucfTableName}Criteria(\$criteriaCount{$ucfTableName}, \$start, \$limit, \$sort, \$order)";
652
        $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...
653
        $critCount .= $this->getSimpleString("return parent::getCount(\$criteriaCount{$ucfTableName});", "\t\t");
654
        $params = "\$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC'";
655
656
        $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...
657
658
        return $ret;
659
    }
660
661
    /**
662
     *  @public function getClassAll
663
     *
664
     *  @param $tableName
665
     *  @param $fieldId
666
     *  @param $fieldMain
667
     *
668
     *  @return string
669
     */
670
    private function getClassAll($tableName, $fieldId, $fieldMain)
671
    {
672
        $ucfTableName = ucfirst($tableName);
673
        $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...
674
675
        $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...
676
        $paramsCrit = "\$this->get{$ucfTableName}Criteria(\$criteriaAll{$ucfTableName}, \$start, \$limit, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC')";
677
        $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...
678
        $critAll .= $this->getSimpleString("return parent::getAll(\$criteriaAll{$ucfTableName});", "\t\t");
679
        $params = "\$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC'";
680
681
        $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...
682
683
        return $ret;
684
    }
685
686
    /**
687
     *  @public function getClassByCategory
688
     *
689
     *  @param $tableName
690
     *  @param $fieldId
691
     *  @param $fieldMain
692
     *  @param $fieldParent
693
     *
694
     *  @return string
695
     */
696
    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...
697
    {
698
        $ucfTableName = ucfirst($tableName);
699
        $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...
700
        $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...
701
        $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...
702
        $fieldElementName = $fieldElements->getVar('fieldelement_name');
703
        $fieldNameDesc = ucfirst(substr($fieldElementName, strrpos($fieldElementName, ':'), strlen($fieldElementName)));
704
        $topicTableName = str_replace(': ', '', $fieldNameDesc);
705
        $lcfTopicTableName = lcfirst($topicTableName);
706
707
        $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...
708
709
        $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...
710
        $param1 = "'{$moduleDirname}_view'";
711
        $param2 = "\$GLOBALS['xoopsUser']->getGroups()";
712
        $param3 = "\$GLOBALS['xoopsModule']->getVar('mid')";
713
        $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...
714
        $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...
715
716
        if (strstr($fieldName, 'status')) {
717
            $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...
718
            $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...
719
        }
720
        $paramsCritAll = "\$this->get{$ucfTableName}Criteria(\$criteriaAll{$ucfTableName}, \$start, \$limit, \$sort, \$order)";
721
        $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...
722
723
        $critAll .= $this->getSimpleString("return parent::getAll(\$criteriaAll{$ucfTableName});", "\t\t");
724
        $params = "\${$tableFieldName}Id, \$start = 0, \$limit = 0, \$sort = '{$fieldId} ASC, {$fieldMain}', \$order = 'ASC'";
725
726
        $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...
727
728
        return $ret;
729
    }
730
731
    /**
732
     *  @public function getClassCriteria
733
     *
734
     *  @param $tableName
735
     *  @param $fieldId
736
     *  @param $fieldMain
737
     *
738
     *  @return string
739
     */
740
    private function getClassCriteria($tableName)
741
    {
742
        $ucfTableName = ucfirst($tableName);
743
        $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...
744
745
        $paramsAllCriteria = "\$criteria{$ucfTableName}, \$start, \$limit, \$sort, \$order";
746
747
        $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...
748
        $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...
749
        $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...
750
        $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...
751
        $critSets .= $this->getSimpleString("return \$criteria{$ucfTableName};", "\t\t");
752
753
        $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...
754
755
        return $ret;
756
    }
757
758
    /**
759
     *  @public function getClassGetTableSolenameById
760
     *
761
     *  @param $moduleDirname
762
     *  @param $table
763
     *
764
     *  @return string
765
     */
766
    private function getClassGetTableSolenameById($moduleDirname, $table, $fieldMain)
767
    {
768
        $tableName = $table->getVar('table_name');
769
        $tableSoleName = $table->getVar('table_solename');
770
        $ucfTableSoleName = ucfirst($tableSoleName);
771
        $ccTableSoleName = $this->getCamelCase($tableSoleName, true);
772
        $ret = $this->pc->getPhpCodeCommentMultiLine(array('Returns the' => $ucfTableSoleName.' from id', '' => '', '@return' => 'string'), "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeCommentMultiLine cannot be called on $this->pc (of type string).

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

Loading history...
773
        $soleName = $this->xc->getXoopsCodeEqualsOperator("\${$tableSoleName}Id", "(int)( \${$tableSoleName}Id )", null, false, "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeEqualsOperator cannot be called on $this->xc (of type string).

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

Loading history...
774
        $soleName .= $this->xc->getXoopsCodeEqualsOperator("\${$tableSoleName}", "''", null, false, "\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeEqualsOperator cannot be called on $this->xc (of type string).

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

Loading history...
775
776
        $contentIf = $this->xc->getXoopsHandlerLine('this->'.$moduleDirname, $tableName, "\t\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsHandlerLine cannot be called on $this->xc (of type string).

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

Loading history...
777
        $contentIf .= $this->xc->getXoopsCodeGet($tableName, "\${$tableSoleName}Id", 'Obj', true, false, "\t\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeGet cannot be called on $this->xc (of type string).

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

Loading history...
778
        $getVar = $this->xc->getXoopsCodeGetVar($ccTableSoleName, "{$tableSoleName}Obj", $fieldMain, false, "\t\t\t\t");
0 ignored issues
show
Bug introduced by
The method getXoopsCodeGetVar cannot be called on $this->xc (of type string).

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

Loading history...
779
        $contentIf .= $this->pc->getPhpCodeConditions("is_object( \${$tableSoleName}Obj )", '', '', $getVar, false, "\t\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeConditions cannot be called on $this->pc (of type string).

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

Loading history...
780
781
        $soleName .= $this->pc->getPhpCodeConditions("\${$tableSoleName}Id", ' > ', '0', $contentIf = null, false, "\t\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeConditions cannot be called on $this->pc (of type string).

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

Loading history...
782
        $soleName .= $this->getSimpleString("return \${$tableSoleName};", "\t\t");
783
784
        $ret .= $this->pc->getPhpCodeFunction("get{$ucfTableSoleName}FromId", "\${$tableSoleName}Id", $soleName, 'public ', false, "\t");
0 ignored issues
show
Bug introduced by
The method getPhpCodeFunction cannot be called on $this->pc (of type string).

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

Loading history...
785
786
        return $ret;
787
    }
788
789
    /*
790
     * @public function render    
791
     * @param null
792
     *
793
     * @return bool|string
794
     */
795
    public function render()
796
    {
797
        $module = $this->getModule();
798
        $table = $this->getTable();
799
        $filename = $this->getFileName();
800
        $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...
801
        $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...
802
        $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...
803
        $moduleDirname = $module->getVar('mod_dirname');
804
        $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...
805
        $fieldInForm = array();
806
        $fieldParentId = array();
807
        $fieldElementId = array();
808
        $fieldParent = null;
809
        foreach (array_keys($fields) as $f) {
810
            $fieldName = $fields[$f]->getVar('field_name');
811
            $fieldInForm[] = $fields[$f]->getVar('field_inform');
812
            $fieldParentId[] = $fields[$f]->getVar('field_parent');
813
            if ((0 == $f) && (1 == $table->getVar('table_autoincrement'))) {
814
                $fieldId = $fieldName; // $fieldId = fields parameter index field
815
            }
816
            if (1 == $fields[$f]->getVar('field_main')) {
817
                $fieldMain = $fieldName; // $fieldMain = fields parameter main field
818
            }
819
            if (1 == $fields[$f]->getVar('field_parent')) {
820
                $fieldParent = $fieldName; // $fieldParent = fields parameter parent field
821
            }
822
            $fieldElement = $fields[$f]->getVar('field_element');
823
            //
824
            $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...
825
            $fieldElementId[] = $fieldElements->getVar('fieldelement_id');
826
        }
827
        $content = $this->getHeaderFilesComments($module, $filename);
828
        $content .= $this->getClassObject($module, $table, $fields);
829
        $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...
830
831
        $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...
832
833
        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...
834
    }
835
}
836