Completed
Pull Request — master (#48)
by Gino
03:19
created

AdminPages::renderFile()   B

Complexity

Conditions 5
Paths 10

Size

Total Lines 41
Code Lines 32

Duplication

Lines 10
Ratio 24.39 %
Metric Value
dl 10
loc 41
rs 8.439
cc 5
eloc 32
nc 10
nop 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 28 and the first side effect is on line 24.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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: AdminPages.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
defined('XOOPS_ROOT_PATH') || die('Restricted access');
25
/**
26
 * Class AdminPages.
27
 */
28
class AdminPages 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 $adminxoopscode;
34
	
35
	/*
36
    * @var string
37
    */
38
    private $t2 = "\t\t";
39
40
    /*
41
    *  @public function constructor
42
    *  @param null
43
    */
44
    /**
45
     *
46
     */
47 View Code Duplication
    public function __construct()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
    {
49
        parent::__construct();
50
        $this->tdmcfile = 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 $tdmcfile.

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...
51
        $this->phpcode = TDMCreatePhpCode::getInstance();
0 ignored issues
show
Bug introduced by
The property phpcode does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
52
		$this->xoopscode = TDMCreateXoopsCode::getInstance();
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
53
        $this->adminxoopscode = AdminXoopsCode::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like \AdminXoopsCode::getInstance() of type object<AdminXoopsCode> is incompatible with the declared type string of property $adminxoopscode.

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...
54
    }
55
56
    /*
57
    *  @static function &getInstance
58
    *  @param null
59
    */
60
    /**
61
     * @return AdminPages
62
     */
63
    public static function &getInstance()
64
    {
65
        static $instance = false;
66
        if (!$instance) {
67
            $instance = new self();
68
        }
69
70
        return $instance;
71
    }
72
73
    /*
74
    *  @public function write
75
    *  @param string $module
76
    *  @param string $table
77
    */
78
    public function write($module, $table)
79
    {
80
        $this->setModule($module);
81
        $this->setTable($table);
82
    }
83
84
    /*
85
    *  @private function getAdminPagesHeader
86
    *  @param string $moduleDirname
87
    *  @param string $tableName
88
    *  @param $fieldId
89
    *  @return string
90
    */
91
    private function getAdminPagesHeader($moduleDirname, $tableName, $fieldId)
92
    {
93
        $ucfModuleDirname = ucfirst($moduleDirname);
0 ignored issues
show
Unused Code introduced by
$ucfModuleDirname 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...
94
        $ucfTableName = ucfirst($tableName);
0 ignored issues
show
Unused Code introduced by
$ucfTableName 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...
95
        $ccFieldId = $this->getCamelCase($fieldId, false, true);
96
        $ret = $this->getInclude();
97
        $ret .= $this->getCommentLine('It recovered the value of argument op in URL$');
98
		$ret .= $this->xoopscode->getXoopsCodeXoopsRequest('op', 'op', 'list');
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
99
        $ret .= $this->getCommentLine("Request {$fieldId}");
100
		$ret .= $this->xoopscode->getXoopsCodeXoopsRequest($ccFieldId, $fieldId, '', 'Int');
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
101
        
102
        return $ret;
103
    }
104
105
    /*
106
     *  @private function getAdminPagesSwitch
107
     *  @param $cases
108
     *
109
     * @return string
110
     */
111
    private function getAdminPagesSwitch($cases = array())
112
    {
113
        $contentSwitch = $this->phpcode->getPhpCodeCaseSwitch($cases, true);
114
115
        return $this->phpcode->getPhpCodeSwitch('op', $contentSwitch);
116
    }
117
118
    /*
119
    *  @private function getAdminPagesList
120
    *  @param $moduleDirname
121
    *  @param $table
122
    *  @param $tableFieldname
123
    *  @param $language
124
    *  @param $fields
125
    *  @param $fieldId
126
    *  @param $fieldInForm
127
    *  @param $fieldMain
128
    *  @return string
129
    */
130
    private function getAdminPagesList($moduleDirname, $table, $language, $fields, $fieldId, $fieldInForm, $fieldMain)
0 ignored issues
show
Unused Code introduced by
The parameter $fields 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...
Unused Code introduced by
The parameter $fieldId 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...
Unused Code introduced by
The parameter $fieldMain 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...
131
    {
132
        $stuModuleDirname = strtoupper($moduleDirname);
133
        $tableName = $table->getVar('table_name');
134
        $tableSoleName = $table->getVar('table_solename');
135
        $tableFieldname = $table->getVar('table_fieldname');
136
        $ucfTableName = ucfirst($tableName);
137
        $stuTableName = strtoupper($tableName);
138
        $stuTableSoleName = strtoupper($tableSoleName);
139
        $stuTableFieldname = strtoupper($tableFieldname);
0 ignored issues
show
Unused Code introduced by
$stuTableFieldname 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...
140
        $tableAutoincrement = $table->getVar('table_autoincrement');
0 ignored issues
show
Unused Code introduced by
$tableAutoincrement 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...
141
        
142
		$ret = $this->xoopscode->getXoopsCodeXoopsRequest('start', 'start', '0', 'Int');
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
143
		$adminpager = $this->xoopscode->getXoopsCodeGetConfig($moduleDirname, 'adminpager');
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
144
		$ret .= $this->t2.$this->xoopscode->getXoopsCodeXoopsRequest('limit', 'limit', $adminpager, 'Int');
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
145
		$ret .= $this->t2.$this->adminxoopscode->getAdminTemplateMain($moduleDirname, $tableName);
0 ignored issues
show
Bug introduced by
The method getAdminTemplateMain cannot be called on $this->adminxoopscode (of type string).

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

Loading history...
146
		$navigation = $this->adminxoopscode->getAdminAddNavigation($tableName);
0 ignored issues
show
Bug introduced by
The method getAdminAddNavigation cannot be called on $this->adminxoopscode (of type string).

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

Loading history...
147
		$ret .= $this->t2.$this->xoopscode->getXoopsCodeTplAssign('navigation', $navigation);				
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
148
		
149 View Code Duplication
        if (1 == $fieldInForm) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
150
			$ret .= $this->t2.$this->adminxoopscode->getAdminItemButton($language, $tableName, $stuTableSoleName, '?op=new', 'add');
0 ignored issues
show
Bug introduced by
The method getAdminItemButton cannot be called on $this->adminxoopscode (of type string).

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

Loading history...
151
			$ret .= $this->t2.$this->xoopscode->getXoopsCodeTplAssign('buttons', "\$adminMenu->renderButton()");            
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
152
        }
153
		
154
        $ret .= $this->t2.$this->xoopscode->getXoopsCodeObjHandlerCount($tableName);
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
155
		$ret .= $this->t2.$this->xoopscode->getXoopsCodeObjHandlerAll($tableName, '', "\$start", "\$limit");
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
156
		$ret .= $this->t2.$this->xoopscode->getXoopsCodeTplAssign("{$tableName}_count", "\${$tableName}Count");
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
157
		$ret .= $this->t2.$this->xoopscode->getXoopsCodeTplAssign("{$moduleDirname}_url", "{$stuModuleDirname}_URL");            
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
158
		$ret .= $this->t2.$this->xoopscode->getXoopsCodeTplAssign("{$moduleDirname}_upload_url", "{$stuModuleDirname}_UPLOAD_URL");      
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
159
		
160
		$ret .= <<<EOT
161
        // Table view
162
        if (\${$tableName}Count > 0)
163
        {
164
            foreach (array_keys(\${$tableName}All) as \$i)
165
            {
166
				\${$tableSoleName} = \${$tableName}All[\$i]->getValues{$ucfTableName}();
167
                \$GLOBALS['xoopsTpl']->append('{$tableName}_list', \${$tableSoleName});
168
                unset(\${$tableSoleName});
169
            }
170
            if ( \${$tableName}Count > \$limit ) {
171
                include_once XOOPS_ROOT_PATH . '/class/pagenav.php';
172
                \$pagenav = new XoopsPageNav(\${$tableName}Count, \$limit, \$start, 'start', 'op=list&limit=' . \$limit);
173
                \$GLOBALS['xoopsTpl']->assign('pagenav', \$pagenav->renderNav(4));
174
            }
175
        } else {
176
            \$GLOBALS['xoopsTpl']->assign('error', {$language}THEREARENT_{$stuTableName});
177
        }
178
EOT;
179
180
        return $ret;
181
    }
182
183
    /*
184
    *  @private function getAdminPagesNew
185
    *  @param string $moduleDirname
186
    *  @param string $tableName
187
    *  @param string $fieldInForm
188
	*  @param string $language
189
    *  @return string
190
    */
191
    private function getAdminPagesNew($moduleDirname, $tableName, $tableSoleName, $fieldInForm, $language)
192
    {
193
        $stuTableName = strtoupper($tableName);
0 ignored issues
show
Unused Code introduced by
$stuTableName 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...
194
		$stuTableSoleName = strtoupper($tableSoleName);
195
        $ucfTableName = ucfirst($tableName);
196
		
197
		$ret = $this->t2.$this->adminxoopscode->getAdminTemplateMain($moduleDirname, $tableName);
0 ignored issues
show
Bug introduced by
The method getAdminTemplateMain cannot be called on $this->adminxoopscode (of type string).

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

Loading history...
198
		$navigation = $this->adminxoopscode->getAdminAddNavigation($tableName);
0 ignored issues
show
Bug introduced by
The method getAdminAddNavigation cannot be called on $this->adminxoopscode (of type string).

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

Loading history...
199
		$ret .= $this->t2.$this->xoopscode->getXoopsCodeTplAssign('navigation', $navigation);				
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
200
		
201 View Code Duplication
        if (1 == $fieldInForm) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
202
			$ret .= $this->t2.$this->adminxoopscode->getAdminItemButton($language, $tableName, $stuTableSoleName, '', 'list');
0 ignored issues
show
Bug introduced by
The method getAdminItemButton cannot be called on $this->adminxoopscode (of type string).

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

Loading history...
203
			$ret .= $this->t2.$this->xoopscode->getXoopsCodeTplAssign('buttons', "\$adminMenu->renderButton()");            
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
204
        }
205
        $ret .= <<<EOT
206
        // Get Form
207
        \${$tableName}Obj =& \${$tableName}Handler->create();
208
        \$form = \${$tableName}Obj->getForm{$ucfTableName}();
209
        \$GLOBALS['xoopsTpl']->assign('form', \$form->render());\n
210
EOT;
211
212
        return $ret;
213
    }
214
215
    /*
216
    *  @private function getAdminPagesSave
217
    *  @param string $moduleDirname
218
    *  @param string $tableName
219
    *  @param string $language
220
    *  @param string $fields
221
    *  @param string $fieldId
222
    *  @param string $fieldMain
223
    *  @return string
224
    */
225
    private function getAdminPagesSave($moduleDirname, $tableName, $language, $fields, $fieldId, $fieldMain)
226
    {
227
        $ccFieldId = $this->getCamelCase($fieldId, false, true);
228
        $ucfTableName = ucfirst($tableName);		
229
		
230
		$ret = $this->phpcode->getPhpCodeCommentLine('Set Vars');
231
		$xoopsSecurityCheck = $this->xoopscode->getXoopsCodeSecurityCheck();
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
232
		$securityError = $this->xoopscode->getXoopsCodeSecurityGetError();
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
233
		$implode = $this->phpcode->getPhpCodeImplode(',', $securityError);
234
		$redirectError = $this->xoopscode->getXoopsCodeRedirectHeader($tableName, '', '3', $implode);
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
235
		$ret .= $this->phpcode->getPhpCodeConditions($xoopsSecurityCheck, '', '', $redirectError, false, "\t");
236
		
237
		$isset = $this->phpcode->getPhpCodeIsset($ccFieldId);
238
		$contentIf = $this->xoopscode->getXoopsCodeGet($tableName, $ccFieldId, 'Obj', true);
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
239
		$contentElse = $this->xoopscode->getXoopsCodeObjHandlerCreate($tableName);
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
240
		$ret .= $this->phpcode->getPhpCodeConditions($isset, '', '', $contentIf, $contentElse, "\t");
241
		
242
        foreach (array_keys($fields) as $f) {
243
            $fieldName = $fields[$f]->getVar('field_name');
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $fields[$f] (of type string).

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

Loading history...
244
            $fieldType = $fields[$f]->getVar('field_type');
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $fields[$f] (of type string).

Methods can 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
            $fieldElement = $fields[$f]->getVar('field_element');
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $fields[$f] (of type string).

Methods can 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
            if ($f > 0) { // If we want to hide field id
247
                switch ($fieldElement) {
248
                    case 5:
249
                    case 6:
250
                        $ret .= $this->xoopscode->getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
251
                        break;
252
                    case 10:
253
                        $ret .= $this->xoopscode->getXoopsCodeImageListSetVar($moduleDirname, $tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
254
                        break;
255
                    case 12:
256
                        $ret .= $this->xoopscode->getXoopsCodeUrlFileSetVar($moduleDirname, $tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
257
                        break;
258
                    case 13:
259
                        if (1 == $fields[$f]->getVar('field_main')) {
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $fields[$f] (of type string).

Methods can 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
                            $fieldMain = $fieldName;
261
                        }
262
                        $ret .= $this->xoopscode->getXoopsCodeUploadImageSetVar($moduleDirname, $tableName, $fieldName, $fieldMain);
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
263
                        break;
264
                    case 14:
265
                        $ret .= $this->xoopscode->getXoopsCodeUploadFileSetVar($moduleDirname, $tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
266
                        break;
267
                    case 15:
268
                        $ret .= $this->xoopscode->getXoopsCodeTextDateSelectSetVar($tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
269
                        break;
270
                    default:
271
                        if ($fieldType == 2 || $fieldType == 7 || $fieldType == 8) {
272
                            $ret .= $this->xoopscode->getXoopsCodeSetVarNumb($tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
273
                        } else {
274
                            $ret .= $this->xoopscode->getXoopsCodeSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
275
                        }
276
                        break;
277
                }
278
            }
279
        }
280
        $ret .= <<<EOT
281
        // Insert Data
282
        if (\${$tableName}Handler->insert(\${$tableName}Obj)) {
283
			redirect_header('{$tableName}.php?op=list', 2, {$language}FORM_OK);
284
        }
285
        // Get Form
286
        \$GLOBALS['xoopsTpl']->assign('error', \${$tableName}Obj->getHtmlErrors());
287
        \$form =& \${$tableName}Obj->getForm{$ucfTableName}();
288
        \$GLOBALS['xoopsTpl']->assign('form', \$form->render());
289
EOT;
290
291
        return $ret;
292
    }
293
294
    /*
295
    *  @private function getAdminPagesEdit
296
    *  @param string $moduleDirname
297
    *  @param string $tableName
0 ignored issues
show
Bug introduced by
There is no parameter named $tableName. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
298
    *  @param string $tableFieldname
0 ignored issues
show
Bug introduced by
There is no parameter named $tableFieldname. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
299
    *  @param string $language
300
    *  @param string $fieldId
301
	*  @param string $fieldInForm
302
    *  @return string
303
    */
304
    private function getAdminPagesEdit($moduleDirname, $table, $language, $fieldId, $fieldInForm)
305
    {
306
        $tableName = $table->getVar('table_name');
307
        $tableSoleName = $table->getVar('table_solename');
308
        $tableFieldname = $table->getVar('table_fieldname');
309
        $stuTableName = strtoupper($tableName);
0 ignored issues
show
Unused Code introduced by
$stuTableName 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...
310
        $ucfTableName = ucfirst($tableName);
311
        $stuTableSoleName = strtoupper($tableSoleName);
312
        $stuTableFieldname = strtoupper($tableFieldname);
0 ignored issues
show
Unused Code introduced by
$stuTableFieldname 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...
313
        $ccFieldId = $this->getCamelCase($fieldId, false, true);
314
        
315
		$ret = $this->t2.$this->adminxoopscode->getAdminTemplateMain($moduleDirname, $tableName);
0 ignored issues
show
Bug introduced by
The method getAdminTemplateMain cannot be called on $this->adminxoopscode (of type string).

Methods can 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
		$navigation = $this->adminxoopscode->getAdminAddNavigation($tableName);
0 ignored issues
show
Bug introduced by
The method getAdminAddNavigation cannot be called on $this->adminxoopscode (of type string).

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

Loading history...
317
		$ret .= $this->t2.$this->xoopscode->getXoopsCodeTplAssign('navigation', $navigation);				
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
318
		
319
        if (1 == $fieldInForm) {
320
			$ret .= $this->t2.$this->adminxoopscode->getAdminItemButton($language, $tableName, $stuTableSoleName, '?op=new', 'add');
0 ignored issues
show
Bug introduced by
The method getAdminItemButton cannot be called on $this->adminxoopscode (of type string).

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

Loading history...
321
			$ret .= $this->t2.$this->adminxoopscode->getAdminItemButton($language, $tableName, $stuTableSoleName, '', 'list');
0 ignored issues
show
Bug introduced by
The method getAdminItemButton cannot be called on $this->adminxoopscode (of type string).

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

Loading history...
322
			$ret .= $this->t2.$this->xoopscode->getXoopsCodeTplAssign('buttons', "\$adminMenu->renderButton()");            
0 ignored issues
show
Bug introduced by
The property xoopscode does not seem to exist. Did you mean adminxoopscode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
323
        }
324
		$ret .= <<<EOT
325
        // Get Form
326
        \${$tableName}Obj = \${$tableName}Handler->get(\${$ccFieldId});
327
        \$form = \${$tableName}Obj->getForm{$ucfTableName}();
328
        \$GLOBALS['xoopsTpl']->assign('form', \$form->render());
329
EOT;
330
331
        return $ret;
332
    }
333
334
    /*
335
    *  @private function getAdminPagesDelete
336
    *  @param string $tableName
337
    *  @param string $language
338
    *  @param string $fieldId
339
    *  @param string $fieldMain
340
    *  @return string
341
    */
342
    private function getAdminPagesDelete($tableName, $language, $fieldId, $fieldMain)
343
    {
344
        $ccFieldId = $this->getCamelCase($fieldId, false, true);
345
        $ret = <<<EOT
346
        \${$tableName}Obj =& \${$tableName}Handler->get(\${$ccFieldId});
347
        if (isset(\$_REQUEST['ok']) && 1 == \$_REQUEST['ok']) {
348
            if ( !\$GLOBALS['xoopsSecurity']->check() ) {
349
                redirect_header('{$tableName}.php', 3, implode(', ', \$GLOBALS['xoopsSecurity']->getErrors()));
350
            }
351
            if (\${$tableName}Handler->delete(\${$tableName}Obj)) {
352
                redirect_header('{$tableName}.php', 3, {$language}FORM_DELETE_OK);
353
            } else {
354
                \$GLOBALS['xoopsTpl']->assign('error', \${$tableName}Obj->getHtmlErrors());
355
            }
356
        } else {
357
            xoops_confirm(array('ok' => 1, '{$fieldId}' => \${$ccFieldId}, 'op' => 'delete'), \$_SERVER['REQUEST_URI'], sprintf({$language}FORM_SURE_DELETE, \${$tableName}Obj->getVar('{$fieldMain}')));
358
        }
359
EOT;
360
361
        return $ret;
362
    }
363
364
    /*
365
    *  @private function getAdminPagesUpdate
366
    *  @param string $moduleDirname
367
    *  @param string $tableName
368
    *  @param string $fieldId
369
    *  @param string $fieldName
370
    *  @return string
371
    */
372
    private function getAdminPagesUpdate($moduleDirname, $tableName, $fieldId, $fieldName)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
373
    {
374
        $stuModuleName = strtoupper($moduleDirname);
375
        $ccFieldId = $this->getCamelCase($fieldId, false, true);
376
        $ret = <<<EOT
377
        if (isset(\${$ccFieldId})) {
378
            \${$tableName}Obj =& \${$tableName}Handler->get(\${$ccFieldId});
379
        }
380
        \${$tableName}Obj->setVar('{$fieldName}', \$_POST['{$fieldName}']);
381
        if (\${$tableName}Handler->insert(\${$tableName}Obj)) {
382
            redirect_header('{$tableName}.php', 3, _AM_{$stuModuleName}_FORM_OK);
383
        }
384
		\$GLOBALS['xoopsTpl']->assign('error', \${$tableName}Obj->getHtmlErrors());
385
EOT;
386
387
        return $ret;
388
    }
389
390
    /*
391
    *  @public function render
392
    *  @param null
393
    */
394
    /**
395
     * @param $filename
396
     *
397
     * @return bool|string
398
     */
399
    public function renderFile($filename)
400
    {
401
        $module = $this->getModule();
402
        $table = $this->getTable();
403
        $moduleDirname = $module->getVar('mod_dirname');
404
        $tableName = $table->getVar('table_name');
405
        $tableSoleName = $table->getVar('table_solename');
406
        $language = $this->getLanguage($moduleDirname, 'AM');
407
        $fields = $this->tdmcfile->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
0 ignored issues
show
Bug introduced by
The method getTableFields cannot be called on $this->tdmcfile (of type string).

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

Loading history...
408 View Code Duplication
        foreach (array_keys($fields) as $f) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
409
            $fieldName = $fields[$f]->getVar('field_name');
410
            $fieldInForm = $fields[$f]->getVar('field_inform');
411
            if (0 == $f) {
412
                $fieldId = $fieldName;
413
            }
414
            if (1 == $fields[$f]->getVar('field_main')) {
415
                $fieldMain = $fieldName;
416
            }
417
        }
418
        $content = $this->getHeaderFilesComments($module, $filename);
419
        $content .= $this->getAdminPagesHeader($moduleDirname, $tableName, $fieldId);
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...
420
        $list = $this->getAdminPagesList($moduleDirname, $table, $language, $fields, $fieldId, $fieldInForm, $fieldMain);
0 ignored issues
show
Bug introduced by
The variable $fieldInForm 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...
421
        if (1 == $fieldInForm) {
422
            $new = $this->getAdminPagesNew($moduleDirname, $tableName, $tableSoleName, $fieldInForm, $language);
423
            $save = $this->getAdminPagesSave($moduleDirname, $tableName, $language, $fields, $fieldId, $fieldMain);
424
            $edit = $this->getAdminPagesEdit($moduleDirname, $table, $language, $fieldId, $fieldInForm);
425
        }
426
        $delete = $this->getAdminPagesDelete($tableName, $language, $fieldId, $fieldMain);
427
428
		$cases = array('list' => array($list),
429
						'new' => array($new), 
0 ignored issues
show
Bug introduced by
The variable $new 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...
430
						'save' => array($save), 
0 ignored issues
show
Bug introduced by
The variable $save 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...
431
						'edit' => array($edit), 
0 ignored issues
show
Bug introduced by
The variable $edit 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...
432
						'delete' => array($delete));
433
        $content .= $this->getAdminPagesSwitch($cases);
434
        $content .= $this->getInclude('footer');
435
        //
436
        $this->tdmcfile->create($moduleDirname, 'admin', $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->tdmcfile (of type string).

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

Loading history...
437
438
        return $this->tdmcfile->renderFile();
0 ignored issues
show
Bug introduced by
The method renderFile cannot be called on $this->tdmcfile (of type string).

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

Loading history...
439
    }
440
}
441