Completed
Push — master ( 4170e1...0758ef )
by Gino
04:19
created

UserXoopsVersion   C

Complexity

Total Complexity 77

Size/Duplication

Total Lines 880
Duplicated Lines 5.45 %

Coupling/Cohesion

Components 1
Dependencies 4
Metric Value
wmc 77
lcom 1
cbo 4
dl 48
loc 880
rs 5

23 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getInstance() 0 9 2
A write() 0 11 2
A setKeywords() 0 8 2
A getKeywords() 0 4 1
B getXoopsVersionHeader() 0 29 3
A getXoopsVersionMySQL() 0 19 3
A getXoopsVersionSearch() 0 9 1
A getXoopsVersionComments() 0 12 1
A getXoopsVersionTemplatesAdmin() 5 21 3
A getXoopsVersionTemplatesLine() 0 17 3
D getXoopsVersionTemplatesUser() 0 57 10
B getXoopsVersionSubmenu() 0 24 4
A getXoopsVersionBlocks() 0 21 3
A getXoopsVersionTypeBlocks() 0 14 1
D getXoopsVersionConfig() 21 137 9
B getNotificationsType() 0 25 3
F getXoopsVersionNotifications() 0 80 12
A getXoopsVersionNotificationGlobal() 0 11 1
A getXoopsVersionNotificationCategory() 11 11 1
A getXoopsVersionNotificationTableName() 11 11 1
A getXoopsVersionNotificationCodeComplete() 0 13 1
F render() 0 49 9

How to fix   Duplicated Code    Complexity   

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:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like UserXoopsVersion often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use UserXoopsVersion, and based on these observations, apply Extract Interface, too.

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 29 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: UserXoopsVersion.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
defined('XOOPS_ROOT_PATH') || die('Restricted access');
25
26
/**
27
 * Class UserXoopsVersion.
28
 */
29
class UserXoopsVersion 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...
30
{
31
    /*
32
    * @var mixed
33
    */
34
    private $phpcode = null;
35
36
    /*
37
    * @var mixed
38
    */
39
    private $xoopscode = null;
40
41
    /*
42
    * @var mixed
43
    */
44
    private $usercode = null;
45
46
    /*
47
    * @var array
48
    */
49
    private $keywords = array();
50
51
    /*
52
    *  @public function constructor
53
    *  @param null
54
    */
55
    /**
56
     *
57
     */
58
    public function __construct()
59
    {
60
        parent::__construct();
61
        $this->phpcode = TDMCreatePhpCode::getInstance();
62
        $this->xoopscode = TDMCreateXoopsCode::getInstance();
63
        $this->usercode = UserXoopsCode::getInstance();
64
    }
65
66
    /*
67
    *  @static function &getInstance
68
    *  @param null
69
    */
70
    /**
71
     * @return UserXoopsVersion
72
     */
73
    public static function &getInstance()
74
    {
75
        static $instance = false;
76
        if (!$instance) {
77
            $instance = new self();
78
        }
79
80
        return $instance;
81
    }
82
83
    /*
84
    *  @public function write
85
    *  @param $module
86
    *  @param mixed $table
87
    *  @param mixed $tables
88
    *  @param $filename
89
    */
90
    /**
91
     * @param $module
92
     * @param $table
93
     * @param $tables
94
     * @param $filename
95
     */
96
    public function write($module, $table, $tables, $filename)
97
    {
98
        $this->setModule($module);
99
        $this->setTable($table);
100
        $this->setTables($tables);
101
        $this->setFileName($filename);
102
        foreach (array_keys($tables) as $t) {
103
            $tableName = $tables[$t]->getVar('table_name');
104
            $this->setKeywords($tableName);
105
        }
106
    }
107
108
    /*
109
    *  @public function setKeywords
110
    *  @param mixed $keywords
111
    */
112
    /**
113
     * @param $keywords
114
     */
115
    public function setKeywords($keywords)
116
    {
117
        if (is_array($keywords)) {
118
            $this->keywords = $keywords;
119
        } else {
120
            $this->keywords[] = $keywords;
121
        }
122
    }
123
124
    /*
125
    *  @public function getKeywords
126
    *  @param null
127
    */
128
    /**
129
     * @return array
130
     */
131
    public function getKeywords()
132
    {
133
        return $this->keywords;
134
    }
135
136
    /*
137
     * @private function getXoopsVersionHeader
138
     * @param $module
139
     * @param $language
140
     *
141
     * @return string
142
     */
143
    private function getXoopsVersionHeader($module, $language)
144
    {
145
        $date = date(_DBDATESTRING);
146
        $ret = $this->getSimpleString("defined('XOOPS_ROOT_PATH') || die('Restricted access');");
147
        $ret .= $this->getCommentLine();
148
        $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$dirname ', 'basename(__DIR__)');
149
        $ret .= $this->getHeaderComment('Informations');
150
        $ha = (1 == $module->getVar('mod_admin')) ? 1 : 0;
151
        $hm = (1 == $module->getVar('mod_user')) ? 1 : 0;
152
153
        $descriptions = array('name' => "{$language}NAME", 'version' => "{$module->getVar('mod_version')}", 'description' => "{$language}DESC",
154
                            'author' => "'{$module->getVar('mod_author')}'", 'author_mail' => "'{$module->getVar('mod_author_mail')}'", 'author_website_url' => "'{$module->getVar('mod_author_website_url')}'",
155
                            'author_website_name' => "'{$module->getVar('mod_author_website_name')}'",'credits' => "'{$module->getVar('mod_credits')}'",'license' => "'{$module->getVar('mod_license')}'",
156
                            'license_url' => "'www.gnu.org/licenses/gpl-2.0.html/'", 'help' => "'page=help'", 'release_info' => "'{$module->getVar('mod_release_info')}'",
157
                            'release_file' => "XOOPS_URL . '/modules/{$module->getVar('mod_dirname')}/docs/{$module->getVar('mod_release_file')}'", 'release_date' => "'{$date}'",
158
                            'manual' => "'{$module->getVar('mod_manual')}'", 'manual_file' => "XOOPS_URL . '/modules/{$module->getVar('mod_dirname')}/docs/{$module->getVar('mod_manual_file')}'",
159
                            'min_php' => "'{$module->getVar('mod_min_php')}'", 'min_xoops' => "'{$module->getVar('mod_min_xoops')}'", 'min_admin' => "'{$module->getVar('mod_min_admin')}'",
160
                            'min_db' => "array('mysql' => '{$module->getVar('mod_min_mysql')}', 'mysqli' => '{$module->getVar('mod_min_mysql')}')", 'image' => "'assets/images/{$module->getVar('mod_image')}'",
161
                            'dirname' => 'basename(__DIR__)', 'dirmoduleadmin' => "'Frameworks/moduleclasses/moduleadmin'", 'sysicons16' => "'../../Frameworks/moduleclasses/icons/16'",
162
                            'sysicons32' => "'../../Frameworks/moduleclasses/icons/32'", 'modicons16' => "'assets/icons/16'", 'modicons32' => "'assets/icons/32'",
163
                            'demo_site_url' => "'{$module->getVar('mod_demo_site_url')}'", 'demo_site_name' => "'{$module->getVar('mod_demo_site_name')}'", 'support_url' => "'{$module->getVar('mod_support_url')}'",
164
                            'support_name' => "'{$module->getVar('mod_support_name')}'", 'module_website_url' => "'{$module->getVar('mod_website_url')}'", 'module_website_name' => "'{$module->getVar('mod_website_name')}'", 'release' => "'{$module->getVar('mod_release')}'", 'module_status' => "'{$module->getVar('mod_status')}'",
165
                            'system_menu' => '1', 'hasAdmin' => $ha, 'hasMain' => $hm, 'adminindex' => "'admin/index.php'", 'adminmenu' => "'admin/menu.php'",
166
                            'onInstall' => "'include/install.php'", 'onUpdate' => "'include/update.php'", );
167
168
        $ret .= $this->usercode->getUserModVersion(1, $descriptions);
169
170
        return $ret;
171
    }
172
173
    /*
174
    *  @private function getXoopsVersionMySQL
175
    *  @param $moduleDirname
176
    *  @param $table
177
    */
178
    /**
179
     * @param $moduleDirname
180
     * @param $table
181
     *
182
     * @return string
183
     */
184
    private function getXoopsVersionMySQL($moduleDirname, $table, $tables)
185
    {
186
        $tableName = $table->getVar('table_name');
187
        $n = 1;
188
        $ret = '';
189
        if (!empty($tableName)) {
190
            $ret .= $this->getHeaderComment('Mysql');
191
            $ret .= $this->usercode->getUserModVersion(2, "'sql/mysql.sql'", 'sqlfile', "'mysql'");
192
            $ret .= $this->getCommentLine('Tables');
193
194
            foreach (array_keys($tables) as $t) {
195
                $ret .= $this->usercode->getUserModVersion(2, "'{$moduleDirname}_{$tables[$t]->getVar('table_name')}'", 'tables', $n);
196
                ++$n;
197
            }
198
            unset($n);
199
        }
200
201
        return $ret;
202
    }
203
204
    /*
205
    *  @private function getXoopsVersionSearch
206
    *  @param $moduleDirname
207
    */
208
    /**
209
     * @param $moduleDirname
210
     *
211
     * @return string
212
     */
213
    private function getXoopsVersionSearch($moduleDirname)
214
    {
215
        $ret = $this->getHeaderComment('Search');
216
        $ret .= $this->usercode->getUserModVersion(1, 1, 'hasSearch');
217
        $ret .= $this->usercode->getUserModVersion(2, "'include/search.inc.php'", 'search', "'file'");
218
        $ret .= $this->usercode->getUserModVersion(2, "'{$moduleDirname}_search'", 'search', "'func'");
219
220
        return $ret;
221
    }
222
223
    /*
224
    *  @private function getXoopsVersionComments
225
    *  @param $moduleDirname
226
    */
227
    /**
228
     * @param $moduleDirname
229
     *
230
     * @return string
231
     */
232
    private function getXoopsVersionComments($moduleDirname)
233
    {
234
        $ret = $this->getHeaderComment('Comments');
235
        $ret .= $this->usercode->getUserModVersion(2, "'comments.php'", 'comments', "'pageName'");
236
        $ret .= $this->usercode->getUserModVersion(2, "'com_id'", 'comments', "'itemName'");
237
        $ret .= $this->getCommentLine('Comment callback functions');
238
        $ret .= $this->usercode->getUserModVersion(2, "'include/comment_functions.php'", 'comments', "'callbackFile'");
239
        $descriptions = array('approve' => "'{$moduleDirname}CommentsApprove'", 'update' => "'{$moduleDirname}CommentsUpdate'");
240
        $ret .= $this->usercode->getUserModVersion(3, $descriptions, 'comments', "'callback'");
241
242
        return $ret;
243
    }
244
245
    /*
246
    *  @private function getXoopsVersionTemplatesAdmin
247
    *  @param $moduleDirname
248
    */
249
    /**
250
     * @param $moduleDirname
251
     * @param $tables
252
     *
253
     * @return string
254
     */
255
    private function getXoopsVersionTemplatesAdmin($moduleDirname, $tables)
256
    {
257
        $ret = $this->getHeaderComment('Templates');
258
        $ret .= $this->getCommentLine('Admin');
259
260
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'about', false, true);
261
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'header', false, true);
262
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'index', false, true);
263
        $tablePermissions = array();
264 View Code Duplication
        foreach (array_keys($tables) as $t) {
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...
265
            $tableName = $tables[$t]->getVar('table_name');
266
            $tablePermissions[] = $tables[$t]->getVar('table_permissions');
267
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, $tableName, false, true);
268
        }
269
        if (in_array(1, $tablePermissions)) {
270
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'permissions', false, true);
271
        }
272
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'footer', false, true);
273
274
        return $ret;
275
    }
276
277
    /*
278
    *  @private function getXoopsVersionTemplatesLine
279
    *  @param $moduleDirname
280
    */
281
    /**
282
     * @param $moduleDirname
283
     *
284
     * @return string
285
     */
286
    private function getXoopsVersionTemplatesLine($moduleDirname, $type, $extra = false, $isAdmin = false)
287
    {
288
        $ret = '';
289
        $desc = "'description' => ''";
290
        $arrayFile = "array('file' =>";
291
        if ($isAdmin) {
292
            $ret .= $this->usercode->getUserModVersion(2, "{$arrayFile} '{$moduleDirname}_admin_{$type}.tpl', {$desc}, 'type' => 'admin')", 'templates', '');
293
        } else {
294
            if ($extra === false) {
295
                $ret .= $this->usercode->getUserModVersion(2, "{$arrayFile} '{$moduleDirname}_{$type}.tpl', {$desc})", 'templates', '');
296
            } else {
297
                $ret .= $this->usercode->getUserModVersion(2, "{$arrayFile} '{$moduleDirname}_{$type}_{$extra}.tpl', {$desc})", 'templates', '');
298
            }
299
        }
300
301
        return $ret;
302
    }
303
304
    /*
305
    *  @private function getXoopsVersionTemplatesUser
306
    *  @param $moduleDirname
307
    */
308
    /**
309
     * @param $moduleDirname
310
     *
311
     * @return string
312
     */
313
    private function getXoopsVersionTemplatesUser($moduleDirname, $tables)
314
    {
315
        $table = $this->getTable();
0 ignored issues
show
Unused Code introduced by
$table 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...
316
        $ret = $this->getCommentLine('User');
317
318
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'header');
319
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'index');
320
        $tableBroken = array();
321
        $tablePdf = array();
322
        $tablePrint = array();
323
        $tableRate = array();
324
        $tableRss = array();
325
        $tableSearch = array();
326
        $tableSingle = array();
327
        $tableSubmit = array();
328
        foreach (array_keys($tables) as $t) {
329
            $tableName = $tables[$t]->getVar('table_name');
330
            $tableBroken[] = $tables[$t]->getVar('table_broken');
331
            $tablePdf[] = $tables[$t]->getVar('table_pdf');
332
            $tablePrint[] = $tables[$t]->getVar('table_print');
333
            $tableRate[] = $tables[$t]->getVar('table_rate');
334
            $tableRss[] = $tables[$t]->getVar('table_rss');
335
            $tableSearch[] = $tables[$t]->getVar('table_search');
336
            $tableSingle[] = $tables[$t]->getVar('table_single');
337
            $tableSubmit[] = $tables[$t]->getVar('table_submit');
338
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, $tableName);
339
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, $tableName, 'list');
0 ignored issues
show
Documentation introduced by
'list' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
340
        }
341
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'breadcrumbs');
342
        if (in_array(1, $tableBroken)) {
343
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'broken');
344
        }
345
        if (in_array(1, $tablePdf)) {
346
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'pdf');
347
        }
348
        if (in_array(1, $tablePrint)) {
349
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'print');
350
        }
351
        if (in_array(1, $tableRate)) {
352
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'rate');
353
        }
354
        if (in_array(1, $tableRss)) {
355
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'rss');
356
        }
357
        if (in_array(1, $tableSearch)) {
358
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'search');
359
        }
360
        if (in_array(1, $tableSingle)) {
361
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'single');
362
        }
363
        if (in_array(1, $tableSubmit)) {
364
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'submit');
365
        }
366
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'footer');
367
368
        return $ret;
369
    }
370
371
    /*
372
    *  @private function getXoopsVersionSubmenu
373
    *  @param $language
374
    */
375
    /**
376
     * @param $language
377
     *
378
     * @return string
379
     */
380
    private function getXoopsVersionSubmenu($language, $tables)
381
    {
382
        $ret = $this->getHeaderComment('Submenu');
383
        $i = 1;
384
        $tableSubmit = array();
385
        foreach (array_keys($tables) as $t) {
386
            $tableName = $tables[$t]->getVar('table_name');
387
            $tableSubmit[] = $tables[$t]->getVar('table_submit');
388
            if (1 == $tables[$t]->getVar('table_submenu')) {
389
                $ret .= $this->getCommentLine('Sub', $tableName);
390
                $tname = array('name' => "{$language}SMNAME{$i}", 'url' => "'{$tableName}.php'");
391
                $ret .= $this->usercode->getUserModVersion(3, $tname, 'sub', $i);
392
            }
393
            ++$i;
394
        }
395
        if (in_array(1, $tableSubmit)) {
396
            $ret .= $this->getCommentLine('Sub', 'Submit');
397
            $submit = array('name' => "{$language}SMNAME{$i}", 'url' => "'submit.php'");
398
            $ret .= $this->usercode->getUserModVersion(3, $submit, 'sub', $i);
399
        }
400
        unset($i);
401
402
        return $ret;
403
    }
404
405
    /*
406
    *  @private function getXoopsVersionBlocks
407
    *  @param $moduleDirname
408
    *  @param $language
409
    */
410
    /**
411
     * @param $moduleDirname
412
     * @param $language
413
     *
414
     * @return string
415
     */
416
    private function getXoopsVersionBlocks($moduleDirname, $table, $tables, $language)
0 ignored issues
show
Unused Code introduced by
The parameter $table 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...
417
    {
418
        $ret = $this->getHeaderComment('Blocks');
419
        $ret .= $this->getSimpleString('$b = 1;');
420
        foreach (array_keys($tables) as $i) {
421
            $tableName = $tables[$i]->getVar('table_name');
422
            $tableFieldName = $tables[$i]->getVar('table_fieldname');
423
            if (1 == $tables[$i]->getVar('table_category')) {
424
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, $language, $tableFieldName);
425
            } else {
426
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, $language, 'last');
427
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, $language, 'new');
428
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, $language, 'hits');
429
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, $language, 'top');
430
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, $language, 'random');
431
            }
432
        }
433
        $ret .= $this->getSimpleString('unset($b);');
434
435
        return $ret;
436
    }
437
438
    /*
439
    *  @private function getXoopsVersionTypeBlocks
440
    *  @param $moduleDirname
441
    *  @param $language
442
    */
443
    /**
444
     * @param $moduleDirname
445
     * @param $language
446
     *
447
     * @return string
448
     */
449
    private function getXoopsVersionTypeBlocks($moduleDirname, $tableName, $language, $type)
450
    {
451
        $stuTableName = strtoupper($tableName);
452
        $stuType = strtoupper($type);
453
        $ucfType = ucfirst($type);
454
        $ret = $this->getCommentLine("{$ucfType}");
455
        $blocks = array('file' => "'{$tableName}.php'", 'name' => "{$language}{$stuTableName}_BLOCK_{$stuType}", 'description' => "{$language}{$stuTableName}_BLOCK_{$stuType}_DESC",
456
                        'show_func' => "'b_{$moduleDirname}_{$tableName}_show'", 'edit_func' => "'b_{$moduleDirname}_{$tableName}_edit'",
457
                        'template' => "'{$moduleDirname}_block_{$tableName}.tpl'", 'options' => "'{$type}|5|25|0'", );
458
        $ret .= $this->usercode->getUserModVersion(3, $blocks, 'blocks', '$b');
459
        $ret .= $this->getSimpleString('++$b;');
460
461
        return $ret;
462
    }
463
464
    /*
465
    *  @private function getXoopsVersionConfig
466
    *  @param $moduleDirname
467
    *  @param $language
468
    */
469
    /**
470
     * @param $module
471
     * @param $table
472
     * @param $language
473
     *
474
     * @return string
475
     */
476
    private function getXoopsVersionConfig($module, $table, $language)
477
    {
478
        $moduleDirname = $module->getVar('mod_dirname');
479
        $ret = $this->getHeaderComment('Config');
480
        $ret .= $this->getSimpleString('$c = 1;');
481
        $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
482
        $fieldName = array();
483
        $fieldElement = array();
484
        foreach (array_keys($fields) as $f) {
485
            $fieldName[] = $fields[$f]->getVar('field_name');
486
            $fieldElement[] = $fields[$f]->getVar('field_element');
487
        }
488
        if (in_array(4, $fieldElement)) {
489
            $rpFieldName = $this->getRightString($fieldName);
490
            $ucfFieldName = ucfirst($rpFieldName);
491
            $ret .= $this->getCommentLine('Editor', $rpFieldName);
492
            $ret .= $this->xoopscode->getXoopsCodeLoad('xoopseditorhandler');
493
            $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('editorHandler ', 'XoopsEditorHandler::getInstance()');
494
            $editor = array('name' => "'{$moduleDirname}_editor_{$rpFieldName}'", 'title' => "'{$language}EDITOR_{$ucfFieldName}'", 'description' => "'{$language}EDITOR_{$ucfFieldName}_DESC'",
495
                    'formtype' => "'select'", 'valuetype' => "'text'", 'default' => "'dhtml'", 'options' => 'array_flip($editorHandler->getList())', );
496
            $ret .= $this->usercode->getUserModVersion(3, $editor, 'config', '$c');
497
            $ret .= $this->getSimpleString('++$c;');
498
        }
499
        if (1 == $table->getVar('table_permissions')) {
500
            $ret .= $this->getCommentLine('Get groups');
501
            $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$memberHandler ', "xoops_gethandler('member')", true);
502
            $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$xoopsGroups ', '$memberHandler->getGroupList()');
503
            $group = $this->xoopscode->getXoopsCodeEqualsOperator('$groups[$group] ', '$key');
504
            $ret .= $this->phpcode->getPhpCodeForeach('xoopsGroups', false, 'key', 'group', $group);
505
            $groups = array('name' => "'groups'", 'title' => "'{$language}GROUPS'", 'description' => "'{$language}GROUPS_DESC'",
506
                        'formtype' => "'select_multi'", 'valuetype' => "'array'", 'default' => '$groups', 'options' => '$groups', );
507
            $ret .= $this->usercode->getUserModVersion(3, $groups, 'config', '$c');
508
            $ret .= $this->getSimpleString('++$c;');
509
            $ret .= $this->getCommentLine('Get Admin groups');
510
            $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$criteria ', 'new CriteriaCompo()');
511
            $ret .= $this->getSimpleString("\$criteria->add( new Criteria( 'group_type', 'Admin' ) );");
512
            $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$memberHandler ', "xoops_gethandler('member')", true);
513
            $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$adminXoopsGroups ', '$memberHandler->getGroupList($criteria)');
514
            $adminGroup = $this->xoopscode->getXoopsCodeEqualsOperator('$adminGroups[$adminGroup] ', '$key');
515
            $ret .= $this->phpcode->getPhpCodeForeach('adminXoopsGroups', false, 'key', 'adminGroup', $adminGroup);
516
            $adminGroups = array('name' => "'admin_groups'", 'title' => "'{$language}GROUPS'", 'description' => "'{$language}GROUPS_DESC'",
517
                        'formtype' => "'select_multi'", 'valuetype' => "'array'", 'default' => '$adminGroups', 'options' => '$adminGroups', );
518
            $ret .= $this->usercode->getUserModVersion(3, $adminGroups, 'config', '$c');
519
            $ret .= $this->getSimpleString('++$c;');
520
        }
521
        $keyword = implode(', ', $this->getKeywords());
522
        $ret .= $this->getCommentLine('Keywords');
523
        $arrayKeyword = array('name' => "'keywords'", 'title' => "'{$language}KEYWORDS'", 'description' => "'{$language}KEYWORDS_DESC'",
524
                        'formtype' => "'textbox'", 'valuetype' => "'text'", 'default' => "'{$moduleDirname}, {$keyword}'", );
525
        $ret .= $this->usercode->getUserModVersion(3, $arrayKeyword, 'config', '$c');
526
        $ret .= $this->getSimpleString('++$c;');
527
        unset($this->keywords);
528
        if (is_object($table)) {
529
            if (in_array(array(10, 11, 12, 13, 14), $fieldElement)) {
530
                $ret .= $this->getCommentLine('Uploads : maxsize of image');
531
                $maxsize = array('name' => "'maxsize'", 'title' => "'{$language}MAXSIZE'", 'description' => "'{$language}MAXSIZE_DESC'",
532
                    'formtype' => "'textbox'", 'valuetype' => "'int'", 'default' => '5000000', );
533
                $ret .= $this->usercode->getUserModVersion(3, $maxsize, 'config', '$c');
534
                $ret .= $this->getCommentLine('Uploads : mimetypes of image');
535
                $ret .= $this->getSimpleString('++$c;');
536
                $mimetypes = array('name' => "'mimetypes'", 'title' => "'{$language}MIMETYPES'", 'description' => "'{$language}MIMETYPES_DESC'",
537
                    'formtype' => "'select_multi'", 'valuetype' => "'array'", 'default' => "array('image/gif', 'image/jpeg', 'image/png')", 'options' => "array('bmp' => 'image/bmp','gif' => 'image/gif','pjpeg' => 'image/pjpeg',
538
				   'jpeg' => 'image/jpeg','jpg' => 'image/jpg','jpe' => 'image/jpe',
539
				   'png' => 'image/png')", );
540
                $ret .= $this->usercode->getUserModVersion(3, $mimetypes, 'config', '$c');
541
                $ret .= $this->getSimpleString('++$c;');
542
            }
543 View Code Duplication
            if (1 == $table->getVar('table_admin')) {
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...
544
                $ret .= $this->getCommentLine('Admin pager');
545
                $adminPager = array('name' => "'adminpager'", 'title' => "'{$language}ADMIN_PAGER'", 'description' => "'{$language}ADMIN_PAGER_DESC'",
546
                        'formtype' => "'textbox'", 'valuetype' => "'int'", 'default' => '10', );
547
                $ret .= $this->usercode->getUserModVersion(3, $adminPager, 'config', '$c');
548
                $ret .= $this->getSimpleString('++$c;');
549
            }
550 View Code Duplication
            if (1 == $table->getVar('table_user')) {
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...
551
                $ret .= $this->getCommentLine('User pager');
552
                $userPager = array('name' => "'userpager'", 'title' => "'{$language}USER_PAGER'", 'description' => "'{$language}USER_PAGER_DESC'",
553
                        'formtype' => "'textbox'", 'valuetype' => "'int'", 'default' => '10', );
554
                $ret .= $this->usercode->getUserModVersion(3, $userPager, 'config', '$c');
555
                $ret .= $this->getSimpleString('++$c;');
556
            }
557 View Code Duplication
            if (1 == $table->getVar('table_tag')) {
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...
558
                $ret .= $this->getCommentLine('Use tag');
559
                $useTag = array('name' => "'usetag'", 'title' => "'{$language}USE_TAG'", 'description' => "'{$language}USE_TAG_DESC'",
560
                        'formtype' => "'yesno'", 'valuetype' => "'int'", 'default' => '0', );
561
                $ret .= $this->usercode->getUserModVersion(3, $useTag, 'config', '$c');
562
                $ret .= $this->getSimpleString('++$c;');
563
            }
564
        }
565
        $ret .= $this->getCommentLine('Number column');
566
        $numbCol = array('name' => "'numb_col'", 'title' => "'{$language}NUMB_COL'", 'description' => "'{$language}NUMB_COL_DESC'",
567
                        'formtype' => "'select'", 'valuetype' => "'int'", 'default' => '1', 'options' => "array(1 => '1', 2 => '2', 3 => '3', 4 => '4')", );
568
        $ret .= $this->usercode->getUserModVersion(3, $numbCol, 'config', '$c');
569
        $ret .= $this->getSimpleString('++$c;');
570
        $ret .= $this->getCommentLine('Divide by');
571
        $divideby = array('name' => "'divideby'", 'title' => "'{$language}DIVIDEBY'", 'description' => "'{$language}DIVIDEBY_DESC'",
572
                        'formtype' => "'select'", 'valuetype' => "'int'", 'default' => '1', 'options' => "array(1 => '1', 2 => '2', 3 => '3', 4 => '4')", );
573
        $ret .= $this->usercode->getUserModVersion(3, $divideby, 'config', '$c');
574
        $ret .= $this->getSimpleString('++$c;');
575
        $ret .= $this->getCommentLine('Table type');
576
        $tableType = array('name' => "'table_type'", 'title' => "'{$language}DIVIDEBY'", 'description' => "'{$language}DIVIDEBY_DESC'",
577
                        'formtype' => "'select'", 'valuetype' => "'int'", 'default' => "'bordered'", 'options' => "array('bordered' => 'bordered', 'striped' => 'striped', 'hover' => 'hover', 'condensed' => 'condensed')", );
578
        $ret .= $this->usercode->getUserModVersion(3, $tableType, 'config', '$c');
579
        $ret .= $this->getSimpleString('++$c;');
580
        $ret .= $this->getCommentLine('Panel by');
581
        $panelType = array('name' => "'panel_type'", 'title' => "'{$language}PANEL_TYPE'", 'description' => "'{$language}PANEL_TYPE_DESC'",
582
                        'formtype' => "'select'", 'valuetype' => "'text'", 'default' => "'default'", 'options' => "array('default' => 'default', 'primary' => 'primary', 'success' => 'success', 'info' => 'info', 'warning' => 'warning', 'danger' => 'danger')", );
583
        $ret .= $this->usercode->getUserModVersion(3, $panelType, 'config', '$c');
584
        $ret .= $this->getSimpleString('++$c;');
585
        $ret .= $this->getCommentLine('Panel by');
586
        $advertise = array('name' => "'advertise'", 'title' => "'{$language}ADVERTISE'", 'description' => "'{$language}ADVERTISE_DESC'",
587
                        'formtype' => "'textarea'", 'valuetype' => "'text'", 'default' => "''", );
588
        $ret .= $this->usercode->getUserModVersion(3, $advertise, 'config', '$c');
589
        $ret .= $this->getSimpleString('++$c;');
590
        $ret .= $this->getCommentLine('Panel by');
591
        $bookmarks = array('name' => "'bookmarks'", 'title' => "'{$language}BOOKMARKS'", 'description' => "'{$language}BOOKMARKS_DESC'",
592
                        'formtype' => "'yesno'", 'valuetype' => "'int'", 'default' => '0', );
593
        $ret .= $this->usercode->getUserModVersion(3, $bookmarks, 'config', '$c');
594
        $ret .= $this->getSimpleString('++$c;');
595
        $ret .= $this->getCommentLine('Facebook Comments');
596
        $facebookComments = array('name' => "'facebook_comments'", 'title' => "'{$language}FACEBOOK_COMMENTS'", 'description' => "'{$language}FACEBOOK_COMMENTS_DESC'",
597
                        'formtype' => "'yesno'", 'valuetype' => "'int'", 'default' => '0', );
598
        $ret .= $this->usercode->getUserModVersion(3, $facebookComments, 'config', '$c');
599
        $ret .= $this->getSimpleString('++$c;');
600
        $ret .= $this->getCommentLine('Disqus Comments');
601
        $disqusComments = array('name' => "'disqus_comments'", 'title' => "'{$language}DISQUS_COMMENTS'", 'description' => "'{$language}DISQUS_COMMENTS_DESC'",
602
                        'formtype' => "'yesno'", 'valuetype' => "'int'", 'default' => '0', );
603
        $ret .= $this->usercode->getUserModVersion(3, $disqusComments, 'config', '$c');
604
        $ret .= $this->getSimpleString('++$c;');
605
        $ret .= $this->getCommentLine('Maintained by');
606
        $maintainedby = array('name' => "'maintainedby'", 'title' => "'{$language}MAINTAINEDBY'", 'description' => "'{$language}MAINTAINEDBY_DESC'",
607
                        'formtype' => "'yesno'", 'valuetype' => "'int'", 'default' => "'{$module->getVar('mod_support_url')}'", );
608
        $ret .= $this->usercode->getUserModVersion(3, $maintainedby, 'config', '$c');
609
        $ret .= $this->getSimpleString('unset($c);');
610
611
        return $ret;
612
    }
613
614
    /*
615
    *  @private function getNotificationsType
616
    *  @param $language
617
    *  @param $type
618
    *  @param $tableName
619
    *  @param $item
620
    *  @param $typeOfNotify
621
    */
622
    /**
623
     * @param $language
624
     * @param $type
625
     * @param $tableName
626
     * @param $notifyFile
627
     * @param $item
628
     * @param $typeOfNotify
629
     *
630
     * @return string
631
     */
632
    private function getNotificationsType($language, $type = 'category', $tableName, $notifyFile, $item, $typeOfNotify)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
633
    {
634
        $stuTableName = strtoupper($tableName);
635
        $stuTypeOfNotify = strtoupper($typeOfNotify);
636
        $notifyFile = explode(', ', $notifyFile);
637
        $notifyFile = implode(', ', $notifyFile);
638
        $ret = '';
639
        switch ($type) {
640
            case 'category':
641
                $ret .= $this->getCommentLine('Category Notify');
642
                $category = array('name' => "'category'", 'title' => "'{$language}{$stuTableName}_NOTIFY'", 'description' => "'{$language}{$stuTableName}_NOTIFY_DESC'",
643
                                    'subscribe_from' => "array('index.php',{$notifyFile})", 'item_name' => "'{$item}'", "'allow_bookmark'" => '1', );
644
                $ret .= $this->usercode->getUserModVersion(3, $category, 'notification', "'{$type}'");
645
                break;
646
            case 'event':
647
                $ret .= $this->getCommentLine('Event Notify');
648
                $event = array('name' => "'{$typeOfNotify}'", 'category' => "'{$tableName}'", 'admin_only' => '1', "'title'" => "'{$language}{$stuTableName}_{$stuTypeOfNotify}_NOTIFY'",
649
                                'caption' => "'{$language}{$stuTableName}_{$stuTypeOfNotify}_NOTIFY_CAPTION'", 'description' => "'{$language}{$stuTableName}_{$stuTypeOfNotify}_NOTIFY_DESC'",
650
                                'mail_template' => "'{$tableName}_{$typeOfNotify}_notify'", 'mail_subject' => "'{$language}{$stuTableName}_{$stuTypeOfNotify}_NOTIFY_SUBJECT'", );
651
                $ret .= $this->usercode->getUserModVersion(3, $event, 'notification', "'{$type}'");
652
                break;
653
        }
654
655
        return $ret;
656
    }
657
658
    /*
659
    *  @private function getXoopsVersionNotifications
660
    *  @param $moduleDirname
661
    *  @param $language
662
    */
663
    /**
664
     * @param $moduleDirname
665
     * @param $language
666
     *
667
     * @return string
668
     */
669
    private function getXoopsVersionNotifications($module, $language)
670
    {
671
        $moduleDirname = $module->getVar('mod_dirname');
672
        $ret = $this->getHeaderComment('Notifications');
673
        $ret .= $this->usercode->getUserModVersion(1, 1, 'hasNotification');
674
        $notifications = array("'lookup_file'" => "'include/notification.inc.php'", "'lookup_func'" => "'{$moduleDirname}_notify_iteminfo'");
675
        $ret .= $this->usercode->getUserModVersion(2, $notifications, 'notification');
676
677
        $notifyFiles = array();
678
        $single = 'single';
679
        $tables = $this->getTableTables($module->getVar('mod_id'), 'table_order');
680
        $tableCategory = array();
681
        $tableBroken = array();
682
        $tableSubmit = array();
683
        foreach (array_keys($tables) as $t) {
684
            $tableId = $tables[$t]->getVar('table_id');
685
            $tableMid = $tables[$t]->getVar('table_mid');
686
            $tableName = $tables[$t]->getVar('table_name');
687
            $tableCategory[] = $tables[$t]->getVar('table_category');
688
            $tableBroken[] = $tables[$t]->getVar('table_broken');
689
            $tableSubmit[] = $tables[$t]->getVar('table_submit');
690
            if (1 == $tables[$t]->getVar('table_notifications')) {
691
                if ($t <= count($tableName)) {
692
                    $notifyFiles[] = $tables[$t]->getVar('table_name');
693
                }
694
            }
695
            if (1 == $tables[$t]->getVar('table_single')) {
696
                $single = $tableName;
697
            }
698
        }
699
        $fields = $this->getTableFields($tableMid, $tableId);
0 ignored issues
show
Bug introduced by
The variable $tableMid 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 $tableId 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...
700
        $fieldParent = null;
701
        foreach (array_keys($fields) as $f) {
702
            $fieldMid = $fields[$f]->getVar('field_mid');
0 ignored issues
show
Unused Code introduced by
$fieldMid 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...
703
            $fieldTid = $fields[$f]->getVar('field_tid');
0 ignored issues
show
Unused Code introduced by
$fieldTid 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...
704
            $fieldName = $fields[$f]->getVar('field_name');
705
            $fieldElement = $fields[$f]->getVar('field_element');
706
            if (0 == $f) {
707
                $fieldId = $fieldName;
708
            }
709
            if ($fieldElement > 15) {
710
                $fieldParent = $fieldName;
711
            }
712
        }
713
714
        $num = 1;
715
        $ret .= $this->getXoopsVersionNotificationGlobal($language, 'category', 'global', 'global', $notifyFiles, $num);
716
        ++$num;
717
        $ret .= $this->getXoopsVersionNotificationCategory($language, 'category', 'category', 'category', $notifyFiles, $fieldParent, '1', $num);
718
        ++$num;
719
        $ret .= $this->getXoopsVersionNotificationTableName($language, 'category', 'file', 'file', $single, $fieldId, 1, $num);
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...
720
        unset($num);
721
        $num = 1;
722
        if (in_array(1, $tableCategory)) {
723
            ++$num;
724
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'new_category', 'global', 0, 'global', 'newcategory', 'global_newcategory_notify', $num);
725
        }
726
        $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'file_modify', 'global', 1, 'global', 'filemodify', 'global_filemodify_notify', $num);
727
        if (in_array(1, $tableBroken)) {
728
            ++$num;
729
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'file_broken', 'global', 1, 'global', 'filebroken', 'global_filebroken_notify', $num);
730
        }
731
        if (in_array(1, $tableSubmit)) {
732
            ++$num;
733
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'file_submit', 'global', 1, 'global', 'filesubmit', 'global_filesubmit_notify', $num);
734
        }
735
        ++$num;
736
        $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'new_file', 'global', 0, 'global', 'newfile', 'global_newfile_notify', $num);
737
        if (in_array(1, $tableCategory)) {
738
            ++$num;
739
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'file_submit', 'category', 1, 'category', 'filesubmit', 'category_filesubmit_notify', $num);
740
            ++$num;
741
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'new_file', 'category', 0, 'category', 'newfile', 'category_newfile_notify', $num);
742
        }
743
        ++$num;
744
        $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'approve', 'file', 1, 'file', 'approve', 'file_approve_notify', $num);
745
        unset($num);
746
747
        return $ret;
748
    }
749
750
    /*
751
    *  @private function getXoopsVersionNotificationGlobal
752
    */
753
    /**
754
     * @param $language
755
     * @param $type
756
     * @param $name
757
     * @param $title
758
     * @param $from
759
     *
760
     * @return string
761
     */
762
    private function getXoopsVersionNotificationGlobal($language, $type, $name, $title, $from, $num)
763
    {
764
        $title = strtoupper($title);
765
        $implodeFrom = implode(".php', '", $from);
766
        $ret = $this->getCommentLine('Global Notify');
767
        $global = array('name' => "'{$name}'", 'title' => "{$language}{$title}_NOTIFY", 'description' => "{$language}{$title}_NOTIFY_DESC",
768
                        'subscribe_from' => "array('index.php', '{$implodeFrom}.php')", );
769
        $ret .= $this->usercode->getUserModVersion(4, $global, 'notification', "'{$type}'", $num);
770
771
        return $ret;
772
    }
773
774
    /*
775
    *  @private function getXoopsVersionNotificationCategory
776
    */
777
    /**
778
     * @param $language
779
     * @param $type
780
     * @param $name
781
     * @param $title
782
     * @param $from
783
     *
784
     * @return string
785
     */
786 View Code Duplication
    private function getXoopsVersionNotificationCategory($language, $type, $name, $title, $from, $item, $allow, $num)
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...
787
    {
788
        $title = strtoupper($title);//{$from}
789
        $implodeFrom = implode(".php', '", $from);
790
        $ret = $this->getCommentLine('Category Notify');
791
        $global = array('name' => "'{$name}'", 'title' => "{$language}{$title}_NOTIFY", 'description' => "{$language}{$title}_NOTIFY_DESC",
792
                        'subscribe_from' => "array('{$implodeFrom}.php')", 'item_name' => "'{$item}'", 'allow_bookmark' => "{$allow}", );
793
        $ret .= $this->usercode->getUserModVersion(4, $global, 'notification', "'{$type}'", $num);
794
795
        return $ret;
796
    }
797
798
    /*
799
    *  @private function getXoopsVersionNotificationTableName
800
    */
801
    /**
802
     * @param $language
803
     * @param $type
804
     * @param $name
805
     * @param $title
806
     * @param $from
807
     * @param $item
808
     * @param $allow
809
     *
810
     * @return string
811
     */
812 View Code Duplication
    private function getXoopsVersionNotificationTableName($language, $type, $name, $title, $from, $item = 'cid', $allow = 1, $num)
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...
813
    {
814
        $stuTitle = strtoupper($title);
815
        $ucfTitle = ucfirst($title);
816
        $ret = $this->getCommentLine($ucfTitle.' Notify');
817
        $global = array('name' => "'{$name}'", 'title' => "{$language}{$stuTitle}_NOTIFY", 'description' => "{$language}{$stuTitle}_NOTIFY_DESC",
818
                        'subscribe_from' => "'{$from}.php'", 'item_name' => "'{$item}'", 'allow_bookmark' => "{$allow}", );
819
        $ret .= $this->usercode->getUserModVersion(4, $global, 'notification', "'{$type}'", $num);
820
821
        return $ret;
822
    }
823
824
    /*
825
    *  @private function getXoopsVersionNotifications
826
    */
827
    /**
828
     * @param $language
829
     * @param $type
830
     * @param $name
831
     * @param $title
832
     * @param $from
833
     * @param $item
834
     * @param $mail
835
     *
836
     * @return string
837
     */
838
    private function getXoopsVersionNotificationCodeComplete($language, $type, $name, $category, $admin = 1, $title, $table, $mail, $num)
839
    {
840
        $title = strtoupper($title);
841
        $table = strtoupper($table);
842
        $ucfTitle = ucfirst($title);
843
        $ret = $this->getCommentLine($ucfTitle.' Notify');
844
        $event = array('name' => "'{$name}'", 'category' => "'{$category}'", 'admin_only' => "{$admin}", 'title' => "{$language}{$title}_{$table}_NOTIFY",
845
                        'caption' => "{$language}{$title}_{$table}_NOTIFY_CAPTION", 'description' => "{$language}{$title}_{$table}_NOTIFY_DESC",
846
                        'mail_template' => "'{$mail}'", 'mail_subject' => "{$language}{$title}_{$table}_NOTIFY_SUBJECT", );
847
        $ret .= $this->usercode->getUserModVersion(4, $event, 'notification', "'{$type}'", $num);
848
849
        return $ret;
850
    }
851
852
    /*
853
    *  @public function render
854
    *  @param null
855
    */
856
    /**
857
     * @return bool|string
858
     */
859
    public function render()
860
    {
861
        $module = $this->getModule();
862
        $table = $this->getTable();
863
        $tables = $this->getTables();
864
        $filename = $this->getFileName();
865
        $moduleDirname = $module->getVar('mod_dirname');
866
        $language = $this->getLanguage($moduleDirname, 'MI');
867
        $content = $this->getHeaderFilesComments($module, $filename);
868
        $content .= $this->getXoopsVersionHeader($module, $language);
869
        if (1 == $module->getVar('mod_admin')) {
870
            $content .= $this->getXoopsVersionTemplatesAdmin($moduleDirname, $tables);
871
        }
872
        if (1 == $module->getVar('mod_user')) {
873
            $content .= $this->getXoopsVersionTemplatesUser($moduleDirname, $tables);
874
        }
875
        $content .= $this->getXoopsVersionMySQL($moduleDirname, $table, $tables);
876
        $tableSearch = array();
877
        $tableComments = array();
878
        $tableSubmenu = array();
879
        $tableBlocks = array();
880
        $tableNotifications = array();
881
        foreach (array_keys($tables) as $t) {
882
            $tableSearch[] = $tables[$t]->getVar('table_search');
883
            $tableComments[] = $tables[$t]->getVar('table_comments');
884
            $tableSubmenu[] = $tables[$t]->getVar('table_submenu');
885
            $tableBlocks[] = $tables[$t]->getVar('table_blocks');
886
            $tableNotifications[] = $tables[$t]->getVar('table_notifications');
887
        }
888
        if (in_array(1, $tableSearch)) {
889
            $content .= $this->getXoopsVersionSearch($moduleDirname);
890
        }
891
        if (in_array(1, $tableComments)) {
892
            $content .= $this->getXoopsVersionComments($moduleDirname);
893
        }
894
        if (in_array(1, $tableSubmenu)) {
895
            $content .= $this->getXoopsVersionSubmenu($language, $tables);
896
        }
897
        if (in_array(1, $tableBlocks)) {
898
            $content .= $this->getXoopsVersionBlocks($moduleDirname, $table, $tables, $language);
899
        }
900
        $content .= $this->getXoopsVersionConfig($module, $table, $language);
901
        if (in_array(1, $tableNotifications)) {
902
            $content .= $this->getXoopsVersionNotifications($module, $language, $filename);
0 ignored issues
show
Unused Code introduced by
The call to UserXoopsVersion::getXoopsVersionNotifications() has too many arguments starting with $filename.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
903
        }
904
        $this->create($moduleDirname, '/', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
905
906
        return $this->renderFile();
907
    }
908
}
909