Completed
Pull Request — master (#52)
by Gino
04:52
created

UserXoopsVersion::getXoopsVersionSearch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 11
rs 9.4285
cc 1
eloc 6
nc 1
nop 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 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: xoopsversion_file.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 array
33
    */
34
    private $keywords = array();
35
36
    /*
37
    *  @public function constructor
38
    *  @param null
39
    */
40
    /**
41
     *
42
     */
43
    public function __construct()
44
    {
45
        parent::__construct();
46
    }
47
48
    /*
49
    *  @static function &getInstance
50
    *  @param null
51
    */
52
    /**
53
     * @return UserXoopsVersion
54
     */
55
    public static function &getInstance()
56
    {
57
        static $instance = false;
58
        if (!$instance) {
59
            $instance = new self();
60
        }
61
62
        return $instance;
63
    }
64
65
    /*
66
    *  @public function write
67
    *  @param $module
68
    *  @param mixed $table
69
    *  @param mixed $tables
70
    *  @param $filename
71
    */
72
    /**
73
     * @param $module
74
     * @param $table
75
     * @param $tables
76
     * @param $filename
77
     */
78
    public function write($module, $table, $tables, $filename)
79
    {
80
        $this->setModule($module);
81
        $this->setTable($table);
82
        $this->setTables($tables);
83
        $this->setFileName($filename);
84
        foreach (array_keys($tables) as $t) {
85
            $tableName = $tables[$t]->getVar('table_name');
86
            $this->setKeywords($tableName);
87
        }
88
    }
89
90
    /*
91
    *  @public function setKeywords
92
    *  @param mixed $keywords
93
    */
94
    /**
95
     * @param $keywords
96
     */
97
    public function setKeywords($keywords)
98
    {
99
        if (is_array($keywords)) {
100
            $this->keywords = $keywords;
101
        } else {
102
            $this->keywords[] = $keywords;
103
        }
104
    }
105
106
    /*
107
    *  @public function getKeywords
108
    *  @param null
109
    */
110
    /**
111
     * @return array
112
     */
113
    public function getKeywords()
114
    {
115
        return $this->keywords;
116
    }
117
118
    /**
119
     * @private function getModVersionHeaderComment
120
     *
121
     * @param $comment
122
     *
123
     * @return string
124
     */
125
    private function getModVersionHeaderComment($comment)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
126
    {
127
        return "// ------------------- {$comment} ------------------- //";
128
    }
129
130
    /*
131
    *  @private function getXoopsVersionHeader
132
    *  @param $language
133
    */
134
    /**
135
     * @param $module
136
     * @param $table
137
     * @param $language
138
     *
139
     * @return string
140
     */
141
    private function getXoopsVersionHeader($module, $table, $language)
142
    {
143
        //$dateString = preg_replace('/[^0-9]/', '/', _DBDATESTRING);
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
144
        $date = date(_DBDATESTRING); // _DBDATESTRING
145
        $ret = <<<EOT
146
defined('XOOPS_ROOT_PATH') || die('Restricted access');
147
//
148
//\$dirname = basename(__DIR__);
149
// ------------------- Informations ------------------- //
150
\$modversion = array(
151
    'name' => {$language}NAME,
152
    'version' => {$module->getVar('mod_version')},
153
    'description' => {$language}DESC,
154
    'author' => '{$module->getVar('mod_author')}',
155
    'author_mail' => '{$module->getVar('mod_author_mail')}',
156
    'author_website_url' => '{$module->getVar('mod_author_website_url')}',
157
    'author_website_name' => '{$module->getVar('mod_author_website_name')}',
158
    'credits' => '{$module->getVar('mod_credits')}',
159
    'license' => '{$module->getVar('mod_license')}',
160
    'license_url' => 'www.gnu.org/licenses/gpl-2.0.html/',
161
	'help' => 'page=help',
162
    //
163
    'release_info' => '{$module->getVar('mod_release_info')}',
164
    'release_file' => XOOPS_URL . '/modules/{$module->getVar('mod_dirname')}/docs/{$module->getVar('mod_release_file')}',
165
    'release_date' => '{$date}',
166
    //
167
    'manual' => '{$module->getVar('mod_manual')}',
168
    'manual_file' => XOOPS_URL . '/modules/{$module->getVar('mod_dirname')}/docs/{$module->getVar('mod_manual_file')}',
169
    'min_php' => '{$module->getVar('mod_min_php')}',
170
    'min_xoops' => '{$module->getVar('mod_min_xoops')}',
171
    'min_admin' => '{$module->getVar('mod_min_admin')}',
172
    'min_db' => array('mysql' => '{$module->getVar('mod_min_mysql')}', 'mysqli' => '{$module->getVar('mod_min_mysql')}'),
173
    'image' => 'assets/images/{$module->getVar('mod_image')}',
174
    'dirname' => '{$module->getVar('mod_dirname')}',
175
    // Frameworks
176
    'dirmoduleadmin' => 'Frameworks/moduleclasses/moduleadmin',
177
    'sysicons16' => '../../Frameworks/moduleclasses/icons/16',
178
    'sysicons32' => '../../Frameworks/moduleclasses/icons/32',
179
    // Local path icons
180
    'modicons16' => 'assets/icons/16',
181
    'modicons32' => 'assets/icons/32',
182
    //About
183
    'demo_site_url' => '{$module->getVar('mod_demo_site_url')}',
184
    'demo_site_name' => '{$module->getVar('mod_demo_site_name')}',
185
    'support_url' => '{$module->getVar('mod_support_url')}',
186
    'support_name' => '{$module->getVar('mod_support_name')}',
187
    'module_website_url' => '{$module->getVar('mod_website_url')}',
188
    'module_website_name' => '{$module->getVar('mod_website_name')}',
189
    'release' => '{$module->getVar('mod_release')}',
190
    'module_status' => '{$module->getVar('mod_status')}',
191
    // Admin system menu
192
    'system_menu' => 1,
193
    // Admin things
194
    'hasAdmin' => 1,
195
    'adminindex' => 'admin/index.php',
196
    'adminmenu' => 'admin/menu.php',\n
197
EOT;
198
        if (1 == $module->getVar('mod_user')) {
199
            $ret .= <<<EOT
200
    // Main things
201
    'hasMain' => 1,\n
202
EOT;
203
        } else {
204
            $ret .= <<<EOT
205
    // Main things
206
    'hasMain' => 0,\n
207
EOT;
208
        }
209
        $ret .= <<<EOT
210
    // Install/Update
211
    'onInstall' => 'include/install.php',\n
212
EOT;
213
        if (is_object($table) && $table->getVar('table_name') != null) {
214
            $ret .= <<<EOT
215
    'onUpdate' => 'include/update.php'\n
216
EOT;
217
        }
218
        $ret .= <<<EOT
219
);\n
220
EOT;
221
222
        return $ret;
223
    }
224
225
    /*
226
    *  @private function getXoopsVersionMySQL
227
    *  @param $moduleDirname
228
    *  @param $table
229
    */
230
    /**
231
     * @param $moduleDirname
232
     * @param $table
233
     *
234
     * @return string
235
     */
236
    private function getXoopsVersionMySQL($moduleDirname, $table, $tables)
237
    {
238
        $tableName = $table->getVar('table_name');
239
        $n = 1;
240
        $ret = '';
241
        if (!empty($tableName)) {
242
            $ret .= <<<EOT
243
// ------------------- Mysql ------------------- //
244
\$modversion['sqlfile']['mysql'] = 'sql/mysql.sql';
245
// Tables\n
246
EOT;
247
            foreach (array_keys($tables) as $t) {
248
                $ret .= <<<EOT
249
\$modversion['tables'][{$n}] = '{$moduleDirname}_{$tables[$t]->getVar('table_name')}';\n
250
EOT;
251
                ++$n;
252
            }
253
            unset($n);
254
        }
255
        $ret .= <<<EOT
256
\n
257
EOT;
258
259
        return $ret;
260
    }
261
262
    /*
263
    *  @private function getXoopsVersionSearch
264
    *  @param $moduleDirname
265
    */
266
    /**
267
     * @param $moduleDirname
268
     *
269
     * @return string
270
     */
271
    private function getXoopsVersionSearch($moduleDirname)
272
    {
273
        $ret = <<<EOT
274
// ------------------- Search ------------------- //
275
\$modversion['hasSearch'] = 1;
276
\$modversion['search']['file'] = 'include/search.inc.php';
277
\$modversion['search']['func'] = '{$moduleDirname}_search';\n\n
278
EOT;
279
280
        return $ret;
281
    }
282
283
    /*
284
    *  @private function getXoopsVersionComments
285
    *  @param $moduleDirname
286
    */
287
    /**
288
     * @param $moduleDirname
289
     *
290
     * @return string
291
     */
292
    private function getXoopsVersionComments($moduleDirname)
293
    {
294
        $ret = <<<EOT
295
// ------------------- Comments ------------------- //
296
\$modversion['comments']['pageName'] = 'comments.php';
297
\$modversion['comments']['itemName'] = 'com_id';
298
// Comment callback functions
299
\$modversion['comments']['callbackFile'] = 'include/comment_functions.php';
300
\$modversion['comments']['callback']['approve'] = '{$moduleDirname}CommentsApprove';
301
\$modversion['comments']['callback']['update'] = '{$moduleDirname}CommentsUpdate';\n\n
302
EOT;
303
304
        return $ret;
305
    }
306
307
    /*
308
    *  @private function getXoopsVersionTemplatesAdmin
309
    *  @param $moduleDirname
310
    */
311
    /**
312
     * @param $moduleDirname
313
     * @param $table
314
     *
315
     * @return string
316
     */
317
    private function getXoopsVersionTemplatesAdmin($moduleDirname, $table, $tables)
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...
318
    {
319
        $ret = <<<EOT
320
// ------------------- Templates ------------------- //
321
// Admin\n
322
EOT;
323
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'about', false, true);
324
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'header', false, true);
325
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'index', false, true);
326 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...
327
            $tableName = $tables[$t]->getVar('table_name');
328
            $tablePermissions[] = $tables[$t]->getVar('table_permissions');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$tablePermissions was never initialized. Although not strictly required by PHP, it is generally a good practice to add $tablePermissions = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
329
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, $tableName, false, true);
330
        }
331
        if (in_array(1, $tablePermissions)) {
0 ignored issues
show
Bug introduced by
The variable $tablePermissions 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...
332
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'permissions', false, true);
333
        }
334
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'footer', false, true);
335
336
        return $ret;
337
    }
338
339
    /*
340
    *  @private function getXoopsVersionTemplatesLine
341
    *  @param $moduleDirname
342
    */
343
    /**
344
     * @param $moduleDirname
345
     *
346
     * @return string
347
     */
348
    private function getXoopsVersionTemplatesLine($moduleDirname, $type, $extra = false, $isAdmin = false)
349
    {
350
        if ($isAdmin) {
351
            $ret = <<<EOT
352
\$modversion['templates'][] = array('file' => '{$moduleDirname}_admin_{$type}.tpl', 'description' => '', 'type' => 'admin');\n
353
EOT;
354
        } else {
355
            if (!$extra) {
356
                $ret = <<<EOT
357
\$modversion['templates'][] = array('file' => '{$moduleDirname}_{$type}.tpl', 'description' => '');\n
358
EOT;
359
            } else {
360
                $ret = <<<EOT
361
\$modversion['templates'][] = array('file' => '{$moduleDirname}_{$type}_{$extra}.tpl', 'description' => '');\n
362
EOT;
363
            }
364
        }
365
366
        return $ret;
367
    }
368
369
    /*
370
    *  @private function getXoopsVersionTemplatesUser
371
    *  @param $moduleDirname
372
    */
373
    /**
374
     * @param $moduleDirname
375
     *
376
     * @return string
377
     */
378
    private function getXoopsVersionTemplatesUser($moduleDirname, $tables)
379
    {
380
        $table = $this->getTable();
381
        $ret = <<<EOT
382
// User\n
383
EOT;
384
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'header');
385
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'index');
386
        foreach (array_keys($tables) as $t) {
387
            $tableName = $tables[$t]->getVar('table_name');
388
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, $tableName);
389
            $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...
390
        }
391
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'breadcrumbs');
392
        if (1 == $table->getVar('table_broken')) {
393
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'broken');
394
        }
395
        if (1 == $table->getVar('table_pdf')) {
396
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'pdf');
397
        }
398
        if (1 == $table->getVar('table_print')) {
399
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'print');
400
        }
401
        if (1 == $table->getVar('table_rate')) {
402
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'rate');
403
        }
404
        if (1 == $table->getVar('table_rss')) {
405
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'rss');
406
        }
407
        if (1 == $table->getVar('table_search')) {
408
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'search');
409
        }
410
        if (1 == $table->getVar('table_single')) {
411
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'single');
412
        }
413
        if (1 == $table->getVar('table_submit')) {
414
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'submit');
415
        }
416
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'footer');
417
418
        return $ret;
419
    }
420
421
    /*
422
    *  @private function getXoopsVersionSubmenu
423
    *  @param $language
424
    */
425
    /**
426
     * @param $language
427
     *
428
     * @return string
429
     */
430
    private function getXoopsVersionSubmenu($language, $tables)
431
    {
432
        $ret = <<<EOT
433
// ------------------- Submenu ------------------- //\n
434
EOT;
435
        $i = 1;
436
        foreach (array_keys($tables) as $t) {
437
            $tableName = $tables[$t]->getVar('table_name');
438
            $tableSubmit[] = $tables[$t]->getVar('table_submit');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$tableSubmit was never initialized. Although not strictly required by PHP, it is generally a good practice to add $tableSubmit = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
439
            if (1 == $tables[$t]->getVar('table_submenu')) {
440
                $ret .= <<<EOT
441
// Sub {$tableName}
442
\$modversion['sub'][{$i}]['name'] = {$language}SMNAME{$i};
443
\$modversion['sub'][{$i}]['url'] = '{$tableName}.php';\n
444
EOT;
445
            }
446
            ++$i;
447
        }
448
        if (in_array(1, $tableSubmit)) {
0 ignored issues
show
Bug introduced by
The variable $tableSubmit 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...
449
            $ret .= <<<EOT
450
// Sub Submit
451
\$modversion['sub'][{$i}]['name'] = {$language}SMNAME{$i};
452
\$modversion['sub'][{$i}]['url'] = 'submit.php';\n
453
EOT;
454
        }
455
        unset($i);
456
        $ret .= <<<EOT
457
\n
458
EOT;
459
460
        return $ret;
461
    }
462
463
    /*
464
    *  @private function getXoopsVersionBlocks
465
    *  @param $moduleDirname
466
    *  @param $language
467
    */
468
    /**
469
     * @param $moduleDirname
470
     * @param $language
471
     *
472
     * @return string
473
     */
474
    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...
475
    {
476
        $ret = <<<EOT
477
// ------------------- Blocks ------------------- //\n
478
EOT;
479
480
        foreach (array_keys($tables) as $i) {
481
            $tableName = $tables[$i]->getVar('table_name');
482
            $tableFieldName = $tables[$i]->getVar('table_fieldname');
483
            if (1 == $tables[$i]->getVar('table_blocks')) {
484
                if (1 == $tables[$i]->getVar('table_category')) {
485
                    $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, $language, $tableFieldName);
486
                } else {
487
                    $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, $language, 'last');
488
                    $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, $language, 'new');
489
                    $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, $language, 'hits');
490
                    $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, $language, 'top');
491
                    $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, $language, 'random');
492
                }
493
            }
494
        }
495
496
        return $ret;
497
    }
498
499
    /*
500
    *  @private function getXoopsVersionTypeBlocks
501
    *  @param $moduleDirname
502
    *  @param $language
503
    */
504
    /**
505
     * @param $moduleDirname
506
     * @param $language
507
     *
508
     * @return string
509
     */
510 View Code Duplication
    private function getXoopsVersionTypeBlocks($moduleDirname, $tableName, $language, $type)
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...
511
    {
512
        $stuTableName = strtoupper($tableName);
513
        $ret = <<<EOT
514
\$modversion['blocks'][] = array(
515
    'file' => '{$tableName}.php',
516
    'name' => {$language}{$stuTableName}_BLOCK,
517
    'description' => {$language}{$stuTableName}_BLOCK_DESC,
518
    'show_func' => 'b_{$moduleDirname}_{$tableName}_show',
519
    'edit_func' => 'b_{$moduleDirname}_{$tableName}_edit',
520
    'options' => '{$type}|5|25|0',
521
    'template' => '{$moduleDirname}_block_{$tableName}.tpl');\n\n
522
EOT;
523
524
        return $ret;
525
    }
526
527
    /*
528
    *  @private function getXoopsVersionConfig
529
    *  @param $moduleDirname
530
    *  @param $language
531
    */
532
    /**
533
     * @param $module
534
     * @param $table
535
     * @param $language
536
     *
537
     * @return string
538
     */
539
    private function getXoopsVersionConfig($module, $table, $language)
540
    {
541
        $moduleDirname = $module->getVar('mod_dirname');
542
        $ret = <<<EOT
543
// ------------------- Config ------------------- //\n
544
EOT;
545
        $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
546 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...
547
            $fieldElement = $fields[$f]->getVar('field_element');
548
            if ($fieldElement == 4) {
549
                $fieldName = $fields[$f]->getVar('field_name');
550
                $rpFieldName = $this->getRightString($fieldName);
551
                $ret .= <<<EOT
552
// Editor
553
xoops_load('xoopseditorhandler');
554
\$editorHandler = XoopsEditorHandler::getInstance();
555
\$modversion['config'][] = array(
556
    'name' => '{$moduleDirname}_editor_{$rpFieldName}',
557
    'title' => '{$language}EDITOR',
558
    'description' => '{$language}EDITOR_DESC',
559
    'formtype' => 'select',
560
    'valuetype' => 'text',
561
    'options' => array_flip(\$editorHandler->getList()),
562
    'default' => 'dhtml');\n\n
563
EOT;
564
            }
565
        }
566
        if (1 == $table->getVar('table_permissions')) {
567
            $ret .= <<<EOT
568
// Get groups
569
\$memberHandler =& xoops_gethandler('member');
570
\$xoopsgroups = \$memberHandler->getGroupList();
571
foreach (\$xoopsgroups as \$key => \$group) {
572
    \$groups[\$group] = \$key;
573
}
574
\$modversion['config'][] = array(
575
    'name' => 'groups',
576
    'title' => '{$language}GROUPS',
577
    'description' => '{$language}GROUPS_DESC',
578
    'formtype' => 'select_multi',
579
    'valuetype' => 'array',
580
    'options' => \$groups,
581
    'default' => \$groups);
582
583
// Get Admin groups
584
\$criteria = new CriteriaCompo();
585
\$criteria->add( new Criteria( 'group_type', 'Admin' ) );
586
\$memberHandler =& xoops_gethandler('member');
587
\$admin_xoopsgroups = \$memberHandler->getGroupList(\$criteria);
588
foreach (\$admin_xoopsgroups as \$key => \$admin_group) {
589
    \$admin_groups[\$admin_group] = \$key;
590
}
591
\$modversion['config'][] = array(
592
    'name' => 'admin_groups',
593
    'title' => '{$language}ADMIN_GROUPS',
594
    'description' => '{$language}ADMIN_GROUPS_DESC',
595
    'formtype' => 'select_multi',
596
    'valuetype' => 'array',
597
    'options' => \$admin_groups,
598
    'default' => \$admin_groups);\n\n
599
EOT;
600
        }
601
        $keyword = implode(', ', $this->getKeywords());
602
        $ret .= <<<EOT
603
\$modversion['config'][] = array(
604
    'name' => 'keywords',
605
    'title' => '{$language}KEYWORDS',
606
    'description' => '{$language}KEYWORDS_DESC',
607
    'formtype' => 'textbox',
608
    'valuetype' => 'text',
609
    'default' => '{$moduleDirname}, {$keyword}');\n\n
610
EOT;
611
        unset($this->keywords);
612
        if (is_object($table)) {
613
            foreach (array_keys($fields) as $f) {
614
                $fieldElement = $fields[$f]->getVar('field_element');
615
                if ((10 == $fieldElement) || (11 == $fieldElement) ||
616
                    (12 == $fieldElement) || (13 == $fieldElement) || (14 == $fieldElement)
617
                ) {
618
                    $ret .= <<<EOT
619
//Uploads : maxsize of image
620
\$modversion['config'][] = array(
621
    'name' => 'maxsize',
622
    'title' => '{$language}MAXSIZE',
623
    'description' => '{$language}MAXSIZE_DESC',
624
    'formtype' => 'textbox',
625
    'valuetype' => 'int',
626
    'default' => 5000000);
627
628
//Uploads : mimetypes of image
629
\$modversion['config'][] = array(
630
    'name' => 'mimetypes',
631
    'title' => '{$language}MIMETYPES',
632
    'description' => '{$language}MIMETYPES_DESC',
633
    'formtype' => 'select_multi',
634
    'valuetype' => 'array',
635
    'default' => array('image/gif', 'image/jpeg', 'image/png'),
636
    'options' => array('bmp' => 'image/bmp','gif' => 'image/gif','pjpeg' => 'image/pjpeg',
637
                       'jpeg' => 'image/jpeg','jpg' => 'image/jpg','jpe' => 'image/jpe',
638
                       'png' => 'image/png'));\n\n
639
EOT;
640
                }
641
            }
642
            if (1 == $table->getVar('table_admin')) {
643
                $ret .= <<<EOT
644
\$modversion['config'][] = array(
645
    'name' => 'adminpager',
646
    'title' => '{$language}ADMIN_PAGER',
647
    'description' => '{$language}ADMIN_PAGER_DESC',
648
    'formtype' => 'textbox',
649
    'valuetype' => 'int',
650
    'default' => 10);\n\n
651
EOT;
652
            }
653
            if (1 == $table->getVar('table_user')) {
654
                $ret .= <<<EOT
655
\$modversion['config'][] = array(
656
    'name' => 'userpager',
657
    'title' => '{$language}USER_PAGER',
658
    'description' => '{$language}USER_PAGER_DESC',
659
    'formtype' => 'textbox',
660
    'valuetype' => 'int',
661
    'default' => 10);\n\n
662
EOT;
663
            }
664
        }
665
        if (1 == $table->getVar('table_tag')) {
666
            $ret .= <<<EOT
667
\$modversion['config'][] = array(
668
    'name' => 'usetag',
669
    'title' => '{$language}USE_TAG',
670
    'description' => '{$language}USE_TAG_DESC',
671
    'formtype' => 'yesno',
672
    'valuetype' => 'int',
673
    'default' => 0);\n\n
674
EOT;
675
        }
676
        $ret .= <<<EOT
677
\$modversion['config'][] = array(
678
    'name' => 'numb_col',
679
    'title' => '{$language}NUMB_COL',
680
    'description' => '{$language}NUMB_COL_DESC',
681
    'formtype' => 'select',
682
    'valuetype' => 'int',
683
    'default' => 1,
684
	'options' => array(1 => '1', 2 => '2', 3 => '3', 4 => '4'));
685
686
\$modversion['config'][] = array(
687
    'name' => 'divideby',
688
    'title' => '{$language}DIVIDEBY',
689
    'description' => '{$language}DIVIDEBY_DESC',
690
    'formtype' => 'select',
691
    'valuetype' => 'int',
692
    'default' => 1,
693
	'options' => array(1 => '1', 2 => '2', 3 => '3', 4 => '4'));
694
695
\$modversion['config'][] = array(
696
    'name' => 'table_type',
697
    'title' => '{$language}TABLE_TYPE',
698
    'description' => '{$language}TABLE_TYPE_DESC',
699
    'formtype' => 'select',
700
    'valuetype' => 'text',
701
    'default' => 'bordered',
702
    'options' => array('bordered' => 'bordered', 'striped' => 'striped', 'hover' => 'hover', 'condensed' => 'condensed'));
703
704
\$modversion['config'][] = array(
705
    'name' => 'panel_type',
706
    'title' => '{$language}PANEL_TYPE',
707
    'description' => '{$language}PANEL_TYPE_DESC',
708
    'formtype' => 'select',
709
    'valuetype' => 'text',
710
    'default' => 'default',
711
    'options' => array('default' => 'default', 'primary' => 'primary', 'success' => 'success', 'info' => 'info', 'warning' => 'warning', 'danger' => 'danger'));
712
713
\$modversion['config'][] = array(
714
    'name' => 'advertise',
715
    'title' => '{$language}ADVERTISE',
716
    'description' => '{$language}ADVERTISE_DESC',
717
    'formtype' => 'textarea',
718
    'valuetype' => 'text',
719
    'default' => '');
720
721
\$modversion['config'][] = array(
722
    'name' => 'bookmarks',
723
    'title' => '{$language}BOOKMARKS',
724
    'description' => '{$language}BOOKMARKS_DESC',
725
    'formtype' => 'yesno',
726
    'valuetype' => 'int',
727
    'default' => 0);
728
729
\$modversion['config'][] = array(
730
    'name' => 'facebook_comments',
731
    'title' => '{$language}FACEBOOK_COMMENTS',
732
    'description' => '{$language}FACEBOOK_COMMENTS_DESC',
733
    'formtype' => 'yesno',
734
    'valuetype' => 'int',
735
    'default' => 0);
736
737
\$modversion['config'][] = array(
738
    'name' => 'disqus_comments',
739
    'title' => '{$language}DISQUS_COMMENTS',
740
    'description' => '{$language}DISQUS_COMMENTS_DESC',
741
    'formtype' => 'yesno',
742
    'valuetype' => 'int',
743
    'default' => 0);
744
	
745
\$modversion['config'][] = array(
746
    'name' => 'maintainedby',
747
    'title' => '{$language}MAINTAINEDBY',
748
    'description' => '{$language}MAINTAINEDBY_DESC',
749
    'formtype' => 'textbox',
750
    'valuetype' => 'text',
751
    'default' => '{$module->getVar('mod_support_url')}');\n\n
752
EOT;
753
754
        return $ret;
755
    }
756
757
    /*
758
    *  @private function getTypeNotifications
759
    *  @param $language
760
    *  @param $type
761
    *  @param $tableName
762
    *  @param $item
763
    *  @param $typeOfNotify
764
    */
765
    /**
766
     * @param $language
767
     * @param $type
768
     * @param $tableName
769
     * @param $notifyFile
770
     * @param $item
771
     * @param $typeOfNotify
772
     *
773
     * @return string
774
     */
775
    private function getTypeNotifications($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...
776
    {
777
        $stuTableName = strtoupper($tableName);
778
        $stuTypeOfNotify = strtoupper($typeOfNotify);
779
        $notifyFile = explode(', ', $notifyFile);
780
        $notifyFile = implode(', ', $notifyFile);
781
        switch ($type) {
782
            case 'category':
783
                $ret = <<<EOT
784
\$modversion['notification']['{$type}'][] = array(
785
    'name' => 'category',
786
    'title' => {$language}{$stuTableName}_NOTIFY,
787
    'description' => {$language}{$stuTableName}_NOTIFY_DESC,
788
    'subscribe_from' => array('index.php',{$notifyFile}),
789
    'item_name' => '{$item}',
790
    'allow_bookmark' => 1);\n
791
EOT;
792
                break;
793
            case 'event':
794
                $ret = <<<EOT
795
\$modversion['notification']['{$type}'][] = array(
796
    'name' => '{$typeOfNotify}',
797
    'category' => '{$tableName}',
798
    'admin_only' => 1,
799
    'title' => {$language}{$stuTableName}_{$stuTypeOfNotify}_NOTIFY,
800
    'caption' => {$language}{$stuTableName}_{$stuTypeOfNotify}_NOTIFY_CAPTION,
801
    'description' => {$language}{$stuTableName}_{$stuTypeOfNotify}_NOTIFY_DESC,
802
    'mail_template' => '{$tableName}_{$typeOfNotify}_notify',
803
    'mail_subject' => {$language}{$stuTableName}_{$stuTypeOfNotify}_NOTIFY_SUBJECT);\n
804
EOT;
805
                break;
806
        }
807
808
        return $ret;
0 ignored issues
show
Bug introduced by
The variable $ret 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...
809
    }
810
811
    /*
812
    *  @private function getXoopsVersionNotifications
813
    *  @param $moduleDirname
814
    *  @param $language
815
    */
816
    /**
817
     * @param $moduleDirname
818
     * @param $language
819
     * @param $filename
820
     *
821
     * @return string
822
     */
823
    private function getXoopsVersionNotifications($module, $language, $filename)
0 ignored issues
show
Unused Code introduced by
The parameter $filename 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...
824
    {
825
        $moduleDirname = $module->getVar('mod_dirname');
826
        $ret = <<<EOT
827
// ------------------- Notifications ------------------- //
828
\$modversion['hasNotification'] = 1;
829
\$modversion['notification']['lookup_file'] = 'include/notification.inc.php';
830
\$modversion['notification']['lookup_func'] = '{$moduleDirname}_notify_iteminfo';\n\n
831
EOT;
832
        $notifyFiles = array();
833
        $single = 'single';
834
        $tables = $this->getTableTables($module->getVar('mod_id'), 'table_order');
835
        foreach (array_keys($tables) as $t) {
836
            $tableId = $tables[$t]->getVar('table_id');
837
            $tableMid = $tables[$t]->getVar('table_mid');
838
            $tableName = $tables[$t]->getVar('table_name');
839
            $tableCategory = $tables[$t]->getVar('table_category');
840
            $tableBroken = $tables[$t]->getVar('table_broken');
841
            $tableSubmit = $tables[$t]->getVar('table_submit');
842
            if (1 == $tables[$t]->getVar('table_notifications')) {
843
                if ($t <= count($tableName)) {
844
                    $notifyFiles[] = $tables[$t]->getVar('table_name');
845
                }
846
            }
847
            if (1 == $tables[$t]->getVar('table_single')) {
848
                $single = $tableName;
849
            }
850
        }
851
        $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...
852
        $fieldParent = null;
853
        foreach (array_keys($fields) as $f) {
854
            $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...
855
            $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...
856
            $fieldName = $fields[$f]->getVar('field_name');
857
            $fieldElement = $fields[$f]->getVar('field_element');
858
            if (0 == $f) {
859
                $fieldId = $fieldName;
860
            }
861
            if ($fieldElement > 15) {
862
                $fieldParent = $fieldName;
863
            }
864
        }
865
866
        $ret .= $this->getXoopsVersionNotificationGlobal($language, 'category', 'global', 'global', $notifyFiles);
867
        $ret .= $this->getXoopsVersionNotificationCategory($language, 'category', 'category', 'category', $notifyFiles, $fieldParent, '1');
868
        $ret .= $this->getXoopsVersionNotificationTableName($language, 'category', 'file', 'file', $single, $fieldId, 1);
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...
869
        if (1 == $tableCategory) {
0 ignored issues
show
Bug introduced by
The variable $tableCategory 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...
870
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'new_category', 'global', 0, 'global', 'newcategory', 'global_newcategory_notify');
871
        }
872
        $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'file_modify', 'global', 1, 'global', 'filemodify', 'global_filemodify_notify');
873
        if (1 == $tableBroken) {
0 ignored issues
show
Bug introduced by
The variable $tableBroken 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...
874
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'file_broken', 'global', 1, 'global', 'filebroken', 'global_filebroken_notify');
875
        }
876
        if (1 == $tableSubmit) {
0 ignored issues
show
Bug introduced by
The variable $tableSubmit 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...
877
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'file_submit', 'global', 1, 'global', 'filesubmit', 'global_filesubmit_notify');
878
        }
879
        $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'new_file', 'global', 0, 'global', 'newfile', 'global_newfile_notify');
880
        if (1 == $tableCategory) {
881
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'file_submit', 'category', 1, 'category', 'filesubmit', 'category_filesubmit_notify');
882
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'new_file', 'category', 0, 'category', 'newfile', 'category_newfile_notify');
883
        }
884
        $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'approve', 'file', 1, 'file', 'approve', 'file_approve_notify');
885
886
        return $ret;
887
    }
888
889
    /*
890
    *  @private function getXoopsVersionNotificationGlobal
891
    */
892
    /**
893
     * @param $language
894
     * @param $type
895
     * @param $name
896
     * @param $title
897
     * @param $from
898
     *
899
     * @return string
900
     */
901
    private function getXoopsVersionNotificationGlobal($language, $type, $name, $title, $from)
902
    {
903
        $title = strtoupper($title);
904
        $ret = "
905
\$modversion['notification']['{$type}'][] = array(
906
    'name' => '{$name}',
907
    'title' => {$language}{$title}_NOTIFY,
908
    'description' => {$language}{$title}_NOTIFY_DESC,
909
    'subscribe_from' => array('index.php', '".implode(".php', '", $from).".php'));\n
910
";
911
912
        return $ret;
913
    }
914
915
    /*
916
    *  @private function getXoopsVersionNotificationCategory
917
    */
918
    /**
919
     * @param $language
920
     * @param $type
921
     * @param $name
922
     * @param $title
923
     * @param $from
924
     *
925
     * @return string
926
     */
927 View Code Duplication
    private function getXoopsVersionNotificationCategory($language, $type, $name, $title, $from, $item, $allow)
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...
928
    {
929
        $title = strtoupper($title);//{$from}
930
        $ret = "
931
\$modversion['notification']['{$type}'][] = array(
932
    'name' => '{$name}',
933
    'title' => {$language}{$title}_NOTIFY,
934
    'description' => {$language}{$title}_NOTIFY_DESC,
935
    'subscribe_from' => array('".implode(".php', '", $from).".php'),
936
	'item_name' => '{$item}',
937
    'allow_bookmark' => {$allow});\n
938
";
939
940
        return $ret;
941
    }
942
943
    /*
944
    *  @private function getXoopsVersionNotificationTableName
945
    */
946
    /**
947
     * @param $language
948
     * @param $type
949
     * @param $name
950
     * @param $title
951
     * @param $from
952
     * @param $item
953
     * @param $allow
954
     *
955
     * @return string
956
     */
957 View Code Duplication
    private function getXoopsVersionNotificationTableName($language, $type, $name, $title, $from, $item = 'cid', $allow = 1)
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...
958
    {
959
        $title = strtoupper($title);
960
        $ret = <<<EOT
961
\$modversion['notification']['{$type}'][] = array(
962
    'name' => '{$name}',
963
    'title' => {$language}{$title}_NOTIFY,
964
    'description' => {$language}{$title}_NOTIFY_DESC,
965
    'subscribe_from' => '{$from}.php',
966
    'item_name' => '{$item}',
967
    'allow_bookmark' => {$allow});\n\n
968
EOT;
969
970
        return $ret;
971
    }
972
973
    /*
974
    *  @private function getXoopsVersionNotifications
975
    */
976
    /**
977
     * @param $language
978
     * @param $type
979
     * @param $name
980
     * @param $title
981
     * @param $from
982
     * @param $item
983
     * @param $mail
984
     *
985
     * @return string
986
     */
987
    private function getXoopsVersionNotificationCodeComplete($language, $type, $name, $category, $admin = 1, $title, $table, $mail)
988
    {
989
        $title = strtoupper($title);
990
        $table = strtoupper($table);
991
        $ret = <<<EOT
992
\$modversion['notification']['{$type}'][] = array(
993
    'name' => '{$name}',
994
    'category' => '{$category}',
995
    'admin_only' => {$admin},
996
    'title' => {$language}{$title}_{$table}_NOTIFY,
997
    'caption' => {$language}{$title}_{$table}_NOTIFY_CAPTION,
998
    'description' => {$language}{$title}_{$table}_NOTIFY_DESC,
999
    'mail_template' => '{$mail}',
1000
    'mail_subject' => {$language}{$title}_{$table}_NOTIFY_SUBJECT);\n\n
1001
EOT;
1002
1003
        return $ret;
1004
    }
1005
1006
    /*
1007
    *  @public function render
1008
    *  @param null
1009
    */
1010
    /**
1011
     * @return bool|string
1012
     */
1013
    public function render()
1014
    {
1015
        $module = $this->getModule();
1016
        $table = $this->getTable();
1017
        $tables = $this->getTables();
1018
        $filename = $this->getFileName();
1019
        $moduleDirname = $module->getVar('mod_dirname');
1020
        $language = $this->getLanguage($moduleDirname, 'MI');
1021
        $content = $this->getHeaderFilesComments($module, $filename);
1022
        $content .= $this->getXoopsVersionHeader($module, $table, $language);
1023
        if (1 == $module->getVar('mod_admin')) {
1024
            $content .= $this->getXoopsVersionTemplatesAdmin($moduleDirname, $table, $tables);
1025
        }
1026
        if (1 == $module->getVar('mod_user')) {
1027
            $content .= $this->getXoopsVersionTemplatesUser($moduleDirname, $tables);
1028
        }
1029
        $content .= $this->getXoopsVersionMySQL($moduleDirname, $table, $tables);
1030
        if (1 == $table->getVar('table_search')) {
1031
            $content .= $this->getXoopsVersionSearch($moduleDirname);
1032
        }
1033
        if (1 == $table->getVar('table_comments')) {
1034
            $content .= $this->getXoopsVersionComments($moduleDirname);
1035
        }
1036
1037
        //if (1 == $table->getVar('table_submenu')) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1038
            $content .= $this->getXoopsVersionSubmenu($language, $tables);
1039
        //}
1040
        if (1 == $table->getVar('table_blocks')) {
1041
            $content .= $this->getXoopsVersionBlocks($moduleDirname, $table, $tables, $language);
1042
        }
1043
        $content .= $this->getXoopsVersionConfig($module, $table, $language);
1044
        if (1 == $table->getVar('table_notifications')) {
1045
            $content .= $this->getXoopsVersionNotifications($module, $language, $filename);
1046
        }
1047
        $this->create($moduleDirname, '/', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
0 ignored issues
show
Documentation introduced by
_AM_TDMCREATE_FILE_CREATED 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...
Documentation introduced by
_AM_TDMCREATE_FILE_NOTCREATED 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...
1048
1049
        return $this->renderFile();
1050
    }
1051
}
1052