Completed
Push — master ( aeaa5d...9fb24b )
by Gino
23:28 queued 09:34
created

AdminPages   A

Complexity

Total Complexity 34

Size/Duplication

Total Lines 409
Duplicated Lines 17.36 %

Coupling/Cohesion

Components 2
Dependencies 3
Metric Value
wmc 34
lcom 2
cbo 3
dl 71
loc 409
rs 9.2

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getInstance() 0 9 2
A write() 0 5 1
A getAdminPagesHeader() 0 19 1
A getAdminPagesSwitch() 0 8 1
A getAdminPagesList() 0 53 2
A getAdminPagesNew() 19 20 1
C getAdminPagesSave() 0 68 14
B getAdminPagesEdit() 0 26 1
A getAdminPagesDelete() 23 23 1
A getAdminPagesUpdate() 19 19 1
C renderFile() 10 37 8

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 AdminObjects
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 $adminobjects;
34
35
    /*
36
    *  @public function constructor
37
    *  @param null
38
    */
39
    /**
40
     *
41
     */
42
    public function __construct()
43
    {
44
        parent::__construct();
45
        $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...
46
        $this->xoopscode = TDMCreateXoopsCode::getInstance();
0 ignored issues
show
Bug introduced by
The property xoopscode 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...
47
        $this->adminobjects = AdminObjects::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like \AdminObjects::getInstance() of type object<AdminObjects> is incompatible with the declared type string of property $adminobjects.

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...
48
    }
49
50
    /*
51
    *  @static function &getInstance
52
    *  @param null
53
    */
54
    /**
55
     * @return AdminPages
56
     */
57
    public static function &getInstance()
58
    {
59
        static $instance = false;
60
        if (!$instance) {
61
            $instance = new self();
62
        }
63
64
        return $instance;
65
    }
66
67
    /*
68
    *  @public function write
69
    *  @param string $module
70
    *  @param string $table
71
    */
72
    public function write($module, $table)
73
    {
74
        $this->setModule($module);
75
        $this->setTable($table);
76
    }
77
78
    /*
79
    *  @private function getAdminPagesHeader
80
    *  @param string $moduleDirname
81
    *  @param string $tableName
82
    *  @param $fieldId
83
    *  @return string
84
    */
85
    private function getAdminPagesHeader($moduleDirname, $tableName, $fieldId)
86
    {
87
        $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...
88
        $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...
89
        $ccFieldId = $this->tdmcfile->getCamelCase($fieldId, false, true);
0 ignored issues
show
Bug introduced by
The method getCamelCase 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...
90
        $ret = $this->getInclude();
91
        $ret .= $this->getCommentLine('It recovered the value of argument op in URL$');
92
        $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$op', "XoopsRequest::getString('op', 'list')");
93
        $ret .= $this->getCommentLine("Request {$fieldId}");
94
        $ret .= $this->xoopscode->getXoopsCodeEqualsOperator("\${$ccFieldId}", "XoopsRequest::getInt('{$fieldId}')");
95
        
96
        
97
		// This must be removed
98
		$ret .= $this->getCommentLine('Switch options');
99
		$ret .= $this->getSimpleString('switch($op)');
100
        $ret .= $this->getSimpleString('{');
101
102
        return $ret;
103
    }
104
	
105
	/*
106
     *  @private function getAdminPagesSwitch
107
     *  @param $moduleDirname
108
     *  @param $language
109
     *
110
     * @return string
111
     */
112
    private function getAdminPagesSwitch($moduleDirname, $language)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
Unused Code introduced by
The parameter $moduleDirname 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 $language 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...
113
    {        		
114
		$cases = array('list' => array(), 'new' => array(),	'save' => array(), 'edit' => array(), 'update' => array());
115
		
116
		$contentSwitch = $this->phpcode->getPhpCodeCaseSwitch($cases, true);
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...
117
        
118
		return $this->phpcode->getPhpCodeSwitch('op', $contentSwitch);
119
    }
120
121
    /*
122
    *  @private function getAdminPagesList
123
    *  @param $moduleDirname
124
    *  @param $table
125
    *  @param $tableFieldname
126
    *  @param $language
127
    *  @param $fields
128
    *  @param $fieldId
129
    *  @param $fieldInForm
130
    *  @param $fieldMain
131
    *  @return string
132
    */
133
    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...
134
    {
135
        $stuModuleDirname = strtoupper($moduleDirname);
136
        $tableName = $table->getVar('table_name');
137
        $tableSoleName = $table->getVar('table_solename');
138
        $tableFieldname = $table->getVar('table_fieldname');
139
        $ucfTableName = ucfirst($tableName);
140
        $stuTableName = strtoupper($tableName);
141
        $stuTableSoleName = strtoupper($tableSoleName);
142
        $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...
143
        $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...
144
        $ret = <<<EOT
145
    case 'list':
146
    default:
147
        \$start = XoopsRequest::getInt('start', 0);
148
        \$limit = XoopsRequest::getInt('limit', \${$moduleDirname}->getConfig('adminpager'));
149
        \$templateMain = '{$moduleDirname}_admin_{$tableName}.tpl';
150
        \$GLOBALS['xoopsTpl']->assign('navigation', \$adminMenu->addNavigation('{$tableName}.php'));\n
151
EOT;
152
        if (1 == $fieldInForm) {
153
            $ret .= <<<EOT
154
        \$adminMenu->addItemButton({$language}ADD_{$stuTableSoleName}, '{$tableName}.php?op=new', 'add');
155
        \$GLOBALS['xoopsTpl']->assign('buttons', \$adminMenu->renderButton());\n
156
EOT;
157
        }
158
        $ret .= <<<EOT
159
        \${$tableName}Count = \${$tableName}Handler->getCount{$ucfTableName}();
160
        \${$tableName}All = \${$tableName}Handler->getAll{$ucfTableName}(\$start, \$limit);
161
		\$GLOBALS['xoopsTpl']->assign('{$tableName}_count', \${$tableName}Count);
162
        \$GLOBALS['xoopsTpl']->assign('{$moduleDirname}_url', {$stuModuleDirname}_URL);
163
        \$GLOBALS['xoopsTpl']->assign('{$moduleDirname}_upload_url', {$stuModuleDirname}_UPLOAD_URL);
164
        // Table view
165
        if (\${$tableName}Count > 0)
166
        {
167
            foreach (array_keys(\${$tableName}All) as \$i)
168
            {
169
				\${$tableSoleName} = \${$tableName}All[\$i]->getValues{$ucfTableName}();
170
                \$GLOBALS['xoopsTpl']->append('{$tableName}_list', \${$tableSoleName});
171
                unset(\${$tableSoleName});
172
            }
173
            if ( \${$tableName}Count > \$limit ) {
174
                include_once XOOPS_ROOT_PATH . '/class/pagenav.php';
175
                \$pagenav = new XoopsPageNav(\${$tableName}Count, \$limit, \$start, 'start', 'op=list&limit=' . \$limit);
176
                \$GLOBALS['xoopsTpl']->assign('pagenav', \$pagenav->renderNav(4));
177
            }
178
        } else {
179
            \$GLOBALS['xoopsTpl']->assign('error', {$language}THEREARENT_{$stuTableName});
180
        }
181
    break;\n
182
EOT;
183
184
        return $ret;
185
    }
186
187
    /*
188
    *  @private function getAdminPagesNew
189
    *  @param string $moduleDirname
190
    *  @param string $tableName
191
    *  @param string $language
192
    *  @return string
193
    */
194 View Code Duplication
    private function getAdminPagesNew($moduleDirname, $tableName, $language)
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...
195
    {
196
        $stuTableName = strtoupper($tableName);
197
        $ucfTableName = ucfirst($tableName);
198
199
        $ret = <<<EOT
200
    case 'new':
201
        \$templateMain = '{$moduleDirname}_admin_{$tableName}.tpl';
202
        \$adminMenu->addItemButton({$language}{$stuTableName}_LIST, '{$tableName}.php', 'list');
203
        \$GLOBALS['xoopsTpl']->assign('navigation', \$adminMenu->addNavigation('{$tableName}.php'));
204
        \$GLOBALS['xoopsTpl']->assign('buttons', \$adminMenu->renderButton());
205
        // Get Form
206
        \${$tableName}Obj =& \${$tableName}Handler->create();
207
        \$form = \${$tableName}Obj->getForm{$ucfTableName}();
208
        \$GLOBALS['xoopsTpl']->assign('form', \$form->render());
209
    break;\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->tdmcfile->getCamelCase($fieldId, false, true);
0 ignored issues
show
Bug introduced by
The method getCamelCase 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...
228
        $ucfTableName = ucfirst($tableName);
229
        $ret = <<<EOT
230
    case 'save':
231
        if ( !\$GLOBALS['xoopsSecurity']->check() ) {
232
			redirect_header('{$tableName}.php', 3, implode(',', \$GLOBALS['xoopsSecurity']->getErrors()));
233
        }
234
        if (isset(\${$ccFieldId})) {
235
           \${$tableName}Obj =& \${$tableName}Handler->get(\${$ccFieldId});
236
        } else {
237
           \${$tableName}Obj =& \${$tableName}Handler->create();
238
        }
239
        // Set Vars\n
240
EOT;
241
        foreach (array_keys($fields) as $f) {
242
            $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...
243
            $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...
244
            $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...
245
            if ($f > 0) { // If we want to hide field id
246
                switch ($fieldElement) {
247
                    case 5:
248
                    case 6:
249
                        $ret .= $this->adminobjects->getCheckBoxOrRadioYNSetVar($tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The method getCheckBoxOrRadioYNSetVar cannot be called on $this->adminobjects (of type string).

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

Loading history...
250
                        break;
251
                    case 10:
252
                        $ret .= $this->adminobjects->getImageListSetVar($moduleDirname, $tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The method getImageListSetVar cannot be called on $this->adminobjects (of type string).

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

Loading history...
253
                        break;
254
                    case 12:
255
                        $ret .= $this->adminobjects->getUrlFileSetVar($moduleDirname, $tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The method getUrlFileSetVar cannot be called on $this->adminobjects (of type string).

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

Loading history...
256
                        break;
257
                    case 13:
258
                        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...
259
                            $fieldMain = $fieldName;
260
                        }
261
                        $ret .= $this->adminobjects->getUploadImageSetVar($moduleDirname, $tableName, $fieldName, $fieldMain);
0 ignored issues
show
Bug introduced by
The method getUploadImageSetVar cannot be called on $this->adminobjects (of type string).

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

Loading history...
262
                        break;
263
                    case 14:
264
                        $ret .= $this->adminobjects->getUploadFileSetVar($moduleDirname, $tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The method getUploadFileSetVar cannot be called on $this->adminobjects (of type string).

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

Loading history...
265
                        break;
266
                    case 15:
267
                        $ret .= $this->adminobjects->getTextDateSelectSetVar($tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The method getTextDateSelectSetVar cannot be called on $this->adminobjects (of type string).

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

Loading history...
268
                        break;
269
                    default:
270
                        if ($fieldType == 2 || $fieldType == 7 || $fieldType == 8) {
271
                            $ret .= $this->adminobjects->getSetVarNumb($tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The method getSetVarNumb cannot be called on $this->adminobjects (of type string).

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

Loading history...
272
                        } else {
273
                            $ret .= $this->adminobjects->getSimpleSetVar($tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The method getSimpleSetVar cannot be called on $this->adminobjects (of type string).

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

Loading history...
274
                        }
275
                        break;
276
                }
277
            }
278
        }
279
        $ret .= <<<EOT
280
        // Insert Data
281
        if (\${$tableName}Handler->insert(\${$tableName}Obj)) {
282
			redirect_header('{$tableName}.php?op=list', 2, {$language}FORM_OK);
283
        }
284
        // Get Form
285
        \$GLOBALS['xoopsTpl']->assign('error', \${$tableName}Obj->getHtmlErrors());
286
        \$form =& \${$tableName}Obj->getForm{$ucfTableName}();
287
        \$GLOBALS['xoopsTpl']->assign('form', \$form->render());
288
    break;\n
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
    *  @return string
302
    */
303
    private function getAdminPagesEdit($moduleDirname, $table, $language, $fieldId)
304
    {
305
        $tableName = $table->getVar('table_name');
306
        $tableSoleName = $table->getVar('table_solename');
307
        $tableFieldname = $table->getVar('table_fieldname');
308
        $stuTableName = strtoupper($tableName);
309
        $ucfTableName = ucfirst($tableName);
310
        $stuTableSoleName = strtoupper($tableSoleName);
311
        $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...
312
        $ccFieldId = $this->tdmcfile->getCamelCase($fieldId, false, true);
0 ignored issues
show
Bug introduced by
The method getCamelCase 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...
313
        $ret = <<<EOT
314
    case 'edit':
315
        \$templateMain = '{$moduleDirname}_admin_{$tableName}.tpl';
316
        \$adminMenu->addItemButton({$language}ADD_{$stuTableSoleName}, '{$tableName}.php?op=new', 'add');
317
        \$adminMenu->addItemButton({$language}{$stuTableName}_LIST, '{$tableName}.php', 'list');
318
        \$GLOBALS['xoopsTpl']->assign('navigation', \$adminMenu->addNavigation('{$tableName}.php'));
319
        \$GLOBALS['xoopsTpl']->assign('buttons', \$adminMenu->renderButton());
320
        // Get Form
321
        \${$tableName}Obj = \${$tableName}Handler->get(\${$ccFieldId});
322
        \$form = \${$tableName}Obj->getForm{$ucfTableName}();
323
        \$GLOBALS['xoopsTpl']->assign('form', \$form->render());
324
    break;\n
325
EOT;
326
327
        return $ret;
328
    }
329
330
    /*
331
    *  @private function getAdminPagesDelete
332
    *  @param string $tableName
333
    *  @param string $language
334
    *  @param string $fieldId
335
    *  @param string $fieldMain
336
    *  @return string
337
    */
338 View Code Duplication
    private function getAdminPagesDelete($tableName, $language, $fieldId, $fieldMain)
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...
339
    {
340
        $ccFieldId = $this->tdmcfile->getCamelCase($fieldId, false, true);
0 ignored issues
show
Bug introduced by
The method getCamelCase 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...
341
        $ret = $this->getSimpleString("case 'delete':");
342
        $ret .= <<<EOT
343
        \${$tableName}Obj =& \${$tableName}Handler->get(\${$ccFieldId});
344
        if (isset(\$_REQUEST['ok']) && 1 == \$_REQUEST['ok']) {
345
            if ( !\$GLOBALS['xoopsSecurity']->check() ) {
346
                redirect_header('{$tableName}.php', 3, implode(', ', \$GLOBALS['xoopsSecurity']->getErrors()));
347
            }
348
            if (\${$tableName}Handler->delete(\${$tableName}Obj)) {
349
                redirect_header('{$tableName}.php', 3, {$language}FORM_DELETE_OK);
350
            } else {
351
                \$GLOBALS['xoopsTpl']->assign('error', \${$tableName}Obj->getHtmlErrors());
352
            }
353
        } else {
354
            xoops_confirm(array('ok' => 1, '{$fieldId}' => \${$ccFieldId}, 'op' => 'delete'), \$_SERVER['REQUEST_URI'], sprintf({$language}FORM_SURE_DELETE, \${$tableName}Obj->getVar('{$fieldMain}')));
355
        }
356
    break;\n
357
EOT;
358
359
        return $ret;
360
    }
361
362
    /*
363
    *  @private function getAdminPagesUpdate
364
    *  @param string $moduleDirname
365
    *  @param string $tableName
366
    *  @param string $fieldId
367
    *  @param string $fieldName
368
    *  @return string
369
    */
370 View Code Duplication
    private function getAdminPagesUpdate($moduleDirname, $tableName, $fieldId, $fieldName)
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...
371
    {
372
        $stuModuleName = strtoupper($moduleDirname);
373
        $ccFieldId = $this->tdmcfile->getCamelCase($fieldId, false, true);
0 ignored issues
show
Bug introduced by
The method getCamelCase 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...
374
        $ret = $this->getSimpleString("case 'update':");
375
        $ret .= <<<EOT
376
        if (isset(\${$ccFieldId})) {
377
            \${$tableName}Obj =& \${$tableName}Handler->get(\${$ccFieldId});
378
        }
379
        \${$tableName}Obj->setVar('{$fieldName}', \$_POST['{$fieldName}']);
380
        if (\${$tableName}Handler->insert(\${$tableName}Obj)) {
381
            redirect_header('{$tableName}.php', 3, _AM_{$stuModuleName}_FORM_OK);
382
        }
383
		\$GLOBALS['xoopsTpl']->assign('error', \${$tableName}Obj->getHtmlErrors());
384
    break;\n
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');
0 ignored issues
show
Unused Code introduced by
$tableSoleName 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...
406
        $language = $this->tdmcfile->getLanguage($moduleDirname, 'AM');
0 ignored issues
show
Bug introduced by
The method getLanguage 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...
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
        $content .= $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
            $content .= $this->getAdminPagesNew($moduleDirname, $tableName, $language);
423
            $content .= $this->getAdminPagesSave($moduleDirname, $tableName, $language, $fields, $fieldId, $fieldMain);
424
            $content .= $this->getAdminPagesEdit($moduleDirname, $table, $language, $fieldId);
425
        }
426
        $content .= $this->getAdminPagesDelete($tableName, $language, $fieldId, $fieldMain);
427
        if (strstr($fieldName, 'update') || strstr($fieldName, 'online') || strstr($fieldName, 'display')) {
428
            $content .= $this->getAdminPagesUpdate($moduleDirname, $tableName, $fieldId, $fieldName);
0 ignored issues
show
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...
429
        }
430
        $content .= $this->tdmcfile->getInclude('footer');
0 ignored issues
show
Bug introduced by
The method getInclude 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...
431
        //
432
        $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...
433
434
        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...
435
    }
436
}
437