Completed
Push — master ( 544d04...d95223 )
by Gino
05:38 queued 01:36
created

getXoopsVersionNotificationCodeComplete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 13
rs 9.4285
cc 1
eloc 10
nc 1
nop 9

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

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

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
48
        $this->usercode = UserXoopsCode::getInstance();
0 ignored issues
show
Bug introduced by
The property usercode does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
49
    }
50
51
    /*
52
    *  @static function &getInstance
53
    *  @param null
54
    */
55
    /**
56
     * @return UserXoopsVersion
57
     */
58
    public static function &getInstance()
59
    {
60
        static $instance = false;
61
        if (!$instance) {
62
            $instance = new self();
63
        }
64
65
        return $instance;
66
    }
67
68
    /*
69
    *  @public function write
70
    *  @param $module
71
    *  @param mixed $table
72
    *  @param mixed $tables
73
    *  @param $filename
74
    */
75
    /**
76
     * @param $module
77
     * @param $table
78
     * @param $tables
79
     * @param $filename
80
     */
81
    public function write($module, $table, $tables, $filename)
82
    {
83
        $this->setModule($module);
84
        $this->setTable($table);
85
        $this->setTables($tables);
86
        $this->setFileName($filename);
87
        foreach (array_keys($tables) as $t) {
88
            $tableName = $tables[$t]->getVar('table_name');
89
            $this->setKeywords($tableName);
90
        }
91
    }
92
93
    /*
94
    *  @public function setKeywords
95
    *  @param mixed $keywords
96
    */
97
    /**
98
     * @param $keywords
99
     */
100
    public function setKeywords($keywords)
101
    {
102
        if (is_array($keywords)) {
103
            $this->keywords = $keywords;
104
        } else {
105
            $this->keywords[] = $keywords;
106
        }
107
    }
108
109
    /*
110
    *  @public function getKeywords
111
    *  @param null
112
    */
113
    /**
114
     * @return array
115
     */
116
    public function getKeywords()
117
    {
118
        return $this->keywords;
119
    }
120
121
    /*
122
    *  @private function getXoopsVersionHeader
123
    *  @param $language
124
    */
125
    /**
126
     * @param $module
127
     * @param $table
128
     * @param $language
129
     *
130
     * @return string
131
     */
132
    private function getXoopsVersionHeader($module, $table, $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...
133
    {
134
        $date = date(_DBDATESTRING);
135
        $ret = $this->getSimpleString("defined('XOOPS_ROOT_PATH') || die('Restricted access');");
136
        $ret .= $this->getCommentLine();
137
        $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$dirname ', 'basename(__DIR__)');
138
        $ret .= $this->getHeaderComment('Informations');
139
        $ha = (1 == $module->getVar('mod_admin')) ? 1 : 0;
140
        $hm = (1 == $module->getVar('mod_user')) ? 1 : 0;
141
142
        $descriptions = array('name' => "{$language}NAME", 'version' => "{$module->getVar('mod_version')}", 'description' => "{$language}DESC",
143
                            'author' => "'{$module->getVar('mod_author')}'", 'author_mail' => "'{$module->getVar('mod_author_mail')}'", 'author_website_url' => "'{$module->getVar('mod_author_website_url')}'",
144
                            'author_website_name' => "'{$module->getVar('mod_author_website_name')}'",'credits' => "'{$module->getVar('mod_credits')}'",'license' => "'{$module->getVar('mod_license')}'",
145
                            'license_url' => "'www.gnu.org/licenses/gpl-2.0.html/'", 'help' => "'page=help'", 'release_info' => "'{$module->getVar('mod_release_info')}'",
146
                            'release_file' => "XOOPS_URL . '/modules/{$module->getVar('mod_dirname')}/docs/{$module->getVar('mod_release_file')}'", 'release_date' => "'{$date}'",
147
                            'manual' => "'{$module->getVar('mod_manual')}'", 'manual_file' => "XOOPS_URL . '/modules/{$module->getVar('mod_dirname')}/docs/{$module->getVar('mod_manual_file')}'",
148
                            'min_php' => "'{$module->getVar('mod_min_php')}'", 'min_xoops' => "'{$module->getVar('mod_min_xoops')}'", 'min_admin' => "'{$module->getVar('mod_min_admin')}'",
149
                            'min_db' => "array('mysql' => '{$module->getVar('mod_min_mysql')}', 'mysqli' => '{$module->getVar('mod_min_mysql')}')", 'image' => "'assets/images/{$module->getVar('mod_image')}'",
150
                            'dirname' => 'basename(__DIR__)', 'dirmoduleadmin' => "'Frameworks/moduleclasses/moduleadmin'", 'sysicons16' => "'../../Frameworks/moduleclasses/icons/16'",
151
                            'sysicons32' => "'../../Frameworks/moduleclasses/icons/32'", 'modicons16' => "'assets/icons/16'", 'modicons32' => "'assets/icons/32'",
152
                            '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')}'",
153
                            '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')}'",
154
                            'system_menu' => '1', 'hasAdmin' => $ha, 'hasMain' => $hm, 'adminindex' => "'admin/index.php'", 'adminmenu' => "'admin/menu.php'",
155
                            'onInstall' => "'include/install.php'", 'onUpdate' => "'include/update.php'", );
156
157
        $ret .= $this->usercode->getUserModVersion(1, $descriptions);
158
159
        return $ret;
160
    }
161
162
    /*
163
    *  @private function getXoopsVersionMySQL
164
    *  @param $moduleDirname
165
    *  @param $table
166
    */
167
    /**
168
     * @param $moduleDirname
169
     * @param $table
170
     *
171
     * @return string
172
     */
173
    private function getXoopsVersionMySQL($moduleDirname, $table, $tables)
174
    {
175
        $tableName = $table->getVar('table_name');
176
        $n = 1;
177
        $ret = '';
178
        if (!empty($tableName)) {
179
            $ret .= $this->getHeaderComment('Mysql');
180
            $ret .= $this->usercode->getUserModVersion(2, "'sql/mysql.sql'", 'sqlfile', "'mysql'");
181
            $ret .= $this->getCommentLine('Tables');
182
183
            foreach (array_keys($tables) as $t) {
184
                $ret .= $this->usercode->getUserModVersion(2, "'{$moduleDirname}_{$tables[$t]->getVar('table_name')}'", 'tables', $n);
185
                ++$n;
186
            }
187
            unset($n);
188
        }
189
190
        return $ret;
191
    }
192
193
    /*
194
    *  @private function getXoopsVersionSearch
195
    *  @param $moduleDirname
196
    */
197
    /**
198
     * @param $moduleDirname
199
     *
200
     * @return string
201
     */
202
    private function getXoopsVersionSearch($moduleDirname)
203
    {
204
        $ret = $this->getHeaderComment('Search');
205
        $ret .= $this->usercode->getUserModVersion(1, 1, 'hasSearch');
206
        $ret .= $this->usercode->getUserModVersion(2, "'include/search.inc.php'", 'search', "'file'");
207
        $ret .= $this->usercode->getUserModVersion(2, "'{$moduleDirname}_search'", 'search', "'func'");
208
209
        return $ret;
210
    }
211
212
    /*
213
    *  @private function getXoopsVersionComments
214
    *  @param $moduleDirname
215
    */
216
    /**
217
     * @param $moduleDirname
218
     *
219
     * @return string
220
     */
221
    private function getXoopsVersionComments($moduleDirname)
222
    {
223
        $ret = $this->getHeaderComment('Comments');
224
        $ret .= $this->usercode->getUserModVersion(2, "'comments.php'", 'comments', "'pageName'");
225
        $ret .= $this->usercode->getUserModVersion(2, "'com_id'", 'comments', "'itemName'");
226
        $ret .= $this->getCommentLine('Comment callback functions');
227
        $ret .= $this->usercode->getUserModVersion(2, "'include/comment_functions.php'", 'comments', "'callbackFile'");
228
        $descriptions = array('approve' => "'{$moduleDirname}CommentsApprove'", 'update' => "'{$moduleDirname}CommentsUpdate'");
229
        $ret .= $this->usercode->getUserModVersion(3, $descriptions, 'comments', "'callback'");
230
231
        return $ret;
232
    }
233
234
    /*
235
    *  @private function getXoopsVersionTemplatesAdmin
236
    *  @param $moduleDirname
237
    */
238
    /**
239
     * @param $moduleDirname
240
     * @param $table
241
     *
242
     * @return string
243
     */
244
    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...
245
    {
246
        $ret = $this->getHeaderComment('Templates');
247
        $ret .= $this->getCommentLine('Admin');
248
249
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'about', false, true);
250
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'header', false, true);
251
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'index', false, true);
252 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...
253
            $tableName = $tables[$t]->getVar('table_name');
254
            $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...
255
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, $tableName, false, true);
256
        }
257
        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...
258
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'permissions', false, true);
259
        }
260
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'footer', false, true);
261
262
        return $ret;
263
    }
264
265
    /*
266
    *  @private function getXoopsVersionTemplatesLine
267
    *  @param $moduleDirname
268
    */
269
    /**
270
     * @param $moduleDirname
271
     *
272
     * @return string
273
     */
274
    private function getXoopsVersionTemplatesLine($moduleDirname, $type, $extra = false, $isAdmin = false)
275
    {
276
        $ret = '';
277
        $desc = "'description' => ''";
278
        $arrayFile = "array('file' =>";
279
        if ($isAdmin) {
280
            $ret .= $this->usercode->getUserModVersion(2, "{$arrayFile} '{$moduleDirname}_admin_{$type}.tpl', {$desc}, 'type' => 'admin')", 'templates', '');
281
        } else {
282
            if (!$extra) {
283
                $ret .= $this->usercode->getUserModVersion(2, "{$arrayFile} '{$moduleDirname}_{$type}.tpl', {$desc})", 'templates', '');
284
            } else {
285
                $ret .= $this->usercode->getUserModVersion(2, "{$arrayFile} '{$moduleDirname}_{$type}_{$extra}.tpl', {$desc})", 'templates', '');
286
            }
287
        }
288
289
        return $ret;
290
    }
291
292
    /*
293
    *  @private function getXoopsVersionTemplatesUser
294
    *  @param $moduleDirname
295
    */
296
    /**
297
     * @param $moduleDirname
298
     *
299
     * @return string
300
     */
301
    private function getXoopsVersionTemplatesUser($moduleDirname, $tables)
302
    {
303
        $table = $this->getTable();
304
        $ret = $this->getCommentLine('User');
305
306
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'header');
307
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'index');
308
        foreach (array_keys($tables) as $t) {
309
            $tableName = $tables[$t]->getVar('table_name');
310
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, $tableName);
311
            $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...
312
        }
313
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'breadcrumbs');
314
        if (1 == $table->getVar('table_broken')) {
315
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'broken');
316
        }
317
        if (1 == $table->getVar('table_pdf')) {
318
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'pdf');
319
        }
320
        if (1 == $table->getVar('table_print')) {
321
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'print');
322
        }
323
        if (1 == $table->getVar('table_rate')) {
324
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'rate');
325
        }
326
        if (1 == $table->getVar('table_rss')) {
327
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'rss');
328
        }
329
        if (1 == $table->getVar('table_search')) {
330
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'search');
331
        }
332
        if (1 == $table->getVar('table_single')) {
333
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'single');
334
        }
335
        if (1 == $table->getVar('table_submit')) {
336
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'submit');
337
        }
338
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'footer');
339
340
        return $ret;
341
    }
342
343
    /*
344
    *  @private function getXoopsVersionSubmenu
345
    *  @param $language
346
    */
347
    /**
348
     * @param $language
349
     *
350
     * @return string
351
     */
352
    private function getXoopsVersionSubmenu($language, $tables)
353
    {
354
        $ret = $this->getHeaderComment('Submenu');
355
        $i = 1;
356
        foreach (array_keys($tables) as $t) {
357
            $tableName = $tables[$t]->getVar('table_name');
358
            $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...
359
            if (1 == $tables[$t]->getVar('table_submenu')) {
360
                $ret .= $this->getCommentLine('Sub', $tableName);
361
                $tname = array('name' => "{$language}SMNAME{$i}", 'url' => "'{$tableName}.php'");
362
                $ret .= $this->usercode->getUserModVersion(3, $tname, 'sub', $i);
363
            }
364
            ++$i;
365
        }
366
        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...
367
            $ret .= $this->getCommentLine('Sub', 'Submit');
368
            $submit = array('name' => "{$language}SMNAME{$i}", 'url' => "'submit.php'");
369
            $ret .= $this->usercode->getUserModVersion(3, $submit, 'sub', $i);
370
        }
371
        unset($i);
372
373
        return $ret;
374
    }
375
376
    /*
377
    *  @private function getXoopsVersionBlocks
378
    *  @param $moduleDirname
379
    *  @param $language
380
    */
381
    /**
382
     * @param $moduleDirname
383
     * @param $language
384
     *
385
     * @return string
386
     */
387
    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...
388
    {
389
        $ret = $this->getHeaderComment('Blocks');
390
        $ret .= $this->getSimpleString('$b = 1;');
391
        foreach (array_keys($tables) as $i) {
392
            $tableName = $tables[$i]->getVar('table_name');
393
            $tableFieldName = $tables[$i]->getVar('table_fieldname');
394
            if (1 == $tables[$i]->getVar('table_category')) {
395
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, $language, $tableFieldName);
0 ignored issues
show
Bug introduced by
The call to getXoopsVersionTypeBlocks() misses a required argument $numb.

This check looks for function calls that miss required arguments.

Loading history...
396
            } else {
397
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, $language, 'last');
0 ignored issues
show
Bug introduced by
The call to getXoopsVersionTypeBlocks() misses a required argument $numb.

This check looks for function calls that miss required arguments.

Loading history...
398
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, $language, 'new');
0 ignored issues
show
Bug introduced by
The call to getXoopsVersionTypeBlocks() misses a required argument $numb.

This check looks for function calls that miss required arguments.

Loading history...
399
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, $language, 'hits');
0 ignored issues
show
Bug introduced by
The call to getXoopsVersionTypeBlocks() misses a required argument $numb.

This check looks for function calls that miss required arguments.

Loading history...
400
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, $language, 'top');
0 ignored issues
show
Bug introduced by
The call to getXoopsVersionTypeBlocks() misses a required argument $numb.

This check looks for function calls that miss required arguments.

Loading history...
401
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, $language, 'random');
0 ignored issues
show
Bug introduced by
The call to getXoopsVersionTypeBlocks() misses a required argument $numb.

This check looks for function calls that miss required arguments.

Loading history...
402
            }
403
        }
404
        $ret .= $this->getSimpleString('unset($b);');
405
406
        return $ret;
407
    }
408
409
    /*
410
    *  @private function getXoopsVersionTypeBlocks
411
    *  @param $moduleDirname
412
    *  @param $language
413
    */
414
    /**
415
     * @param $moduleDirname
416
     * @param $language
417
     *
418
     * @return string
419
     */
420
    private function getXoopsVersionTypeBlocks($moduleDirname, $tableName, $language, $type, $numb)
0 ignored issues
show
Unused Code introduced by
The parameter $numb 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...
421
    {
422
        $stuTableName = strtoupper($tableName);
423
        $stuType = strtoupper($type);
424
        $ucfType = ucfirst($type);
425
        $ret = $this->getCommentLine("{$ucfType}");
426
        $blocks = array('file' => "'{$tableName}.php'", 'name' => "{$language}{$stuTableName}_BLOCK_{$stuType}", 'description' => "{$language}{$stuTableName}_BLOCK_{$stuType}_DESC",
427
                        'show_func' => "'b_{$moduleDirname}_{$tableName}_show'", 'edit_func' => "'b_{$moduleDirname}_{$tableName}_edit'",
428
                        'template' => "'{$moduleDirname}_block_{$tableName}.tpl'", 'options' => "'{$type}|5|25|0'", );
429
        $ret .= $this->usercode->getUserModVersion(3, $blocks, 'blocks', '$b');
430
        $ret .= $this->getSimpleString('++$b;');
431
432
        return $ret;
433
    }
434
435
    /*
436
    *  @private function getXoopsVersionConfig
437
    *  @param $moduleDirname
438
    *  @param $language
439
    */
440
    /**
441
     * @param $module
442
     * @param $table
443
     * @param $language
444
     *
445
     * @return string
446
     */
447
    private function getXoopsVersionConfig($module, $table, $language)
448
    {
449
        $moduleDirname = $module->getVar('mod_dirname');
450
        $ret = $this->getHeaderComment('Config');
451
        $ret .= $this->getSimpleString('$c = 1;');
452
        $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
453
        foreach (array_keys($fields) as $f) {
454
            $fieldElement[] = $fields[$f]->getVar('field_element');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$fieldElement was never initialized. Although not strictly required by PHP, it is generally a good practice to add $fieldElement = 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...
455
        }
456
        if (in_array(4, $fieldElement)) {
0 ignored issues
show
Bug introduced by
The variable $fieldElement does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
457
            $fieldName = $fields[$f]->getVar('field_name');
0 ignored issues
show
Bug introduced by
The variable $f seems to be defined by a foreach iteration on line 453. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
458
            $rpFieldName = $this->getRightString($fieldName);
459
            $ucfFieldName = ucfirst($rpFieldName);
460
            $ret .= $this->getCommentLine('Editor', $rpFieldName);
461
            $ret .= $this->xoopscode->getXoopsCodeLoad('xoopseditorhandler');
462
            $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('editorHandler ', 'XoopsEditorHandler::getInstance()');
463
            $editor = array('name' => "'{$moduleDirname}_editor_{$rpFieldName}'", 'title' => "'{$language}EDITOR_{$ucfFieldName}'", 'description' => "'{$language}EDITOR_{$ucfFieldName}_DESC'",
464
                    'formtype' => "'select'", 'valuetype' => "'text'", 'default' => "'dhtml'", 'options' => 'array_flip($editorHandler->getList())', );
465
            $ret .= $this->usercode->getUserModVersion(3, $editor, 'config', '$c');
466
            $ret .= $this->getSimpleString('++$c;');
467
        }
468
        if (1 == $table->getVar('table_permissions')) {
469
            $ret .= $this->getCommentLine('Get groups');
470
            $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$memberHandler ', "xoops_gethandler('member')", true);
471
            $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$xoopsGroups ', '$memberHandler->getGroupList()');
472
            $group = $this->xoopscode->getXoopsCodeEqualsOperator('$groups[$group] ', '$key');
473
            $ret .= $this->phpcode->getPhpCodeForeach('xoopsGroups', false, 'key', 'group', $group);
474
            $groups = array('name' => "'groups'", 'title' => "'{$language}GROUPS'", 'description' => "'{$language}GROUPS_DESC'",
475
                        'formtype' => "'select_multi'", 'valuetype' => "'array'", 'default' => '$groups', 'options' => '$groups', );
476
            $ret .= $this->usercode->getUserModVersion(3, $groups, 'config', '$c');
477
            $ret .= $this->getSimpleString('++$c;');
478
            $ret .= $this->getCommentLine('Get Admin groups');
479
            $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$criteria ', 'new CriteriaCompo()');
480
            $ret .= $this->getSimpleString("\$criteria->add( new Criteria( 'group_type', 'Admin' ) );");
481
            $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$memberHandler ', "xoops_gethandler('member')", true);
482
            $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$adminXoopsGroups ', '$memberHandler->getGroupList($criteria)');
483
            $adminGroup = $this->xoopscode->getXoopsCodeEqualsOperator('$adminGroups[$adminGroup] ', '$key');
484
            $ret .= $this->phpcode->getPhpCodeForeach('adminXoopsGroups', false, 'key', 'adminGroup', $adminGroup);
485
            $adminGroups = array('name' => "'admin_groups'", 'title' => "'{$language}GROUPS'", 'description' => "'{$language}GROUPS_DESC'",
486
                        'formtype' => "'select_multi'", 'valuetype' => "'array'", 'default' => '$adminGroups', 'options' => '$adminGroups', );
487
            $ret .= $this->usercode->getUserModVersion(3, $adminGroups, 'config', '$c');
488
            $ret .= $this->getSimpleString('++$c;');
489
        }
490
        $keyword = implode(', ', $this->getKeywords());
491
        $ret .= $this->getCommentLine('Keywords');
492
        $arrayKeyword = array('name' => "'keywords'", 'title' => "'{$language}KEYWORDS'", 'description' => "'{$language}KEYWORDS_DESC'",
493
                        'formtype' => "'textbox'", 'valuetype' => "'text'", 'default' => "'{$moduleDirname}, {$keyword}'", );
494
        $ret .= $this->usercode->getUserModVersion(3, $arrayKeyword, 'config', '$c');
495
        $ret .= $this->getSimpleString('++$c;');
496
        unset($this->keywords);
497
        if (is_object($table)) {
498
            if (in_array(array(10, 11, 12, 13, 14), $fieldElement)) {
499
                $ret .= $this->getCommentLine('Uploads : maxsize of image');
500
                $maxsize = array('name' => "'maxsize'", 'title' => "'{$language}MAXSIZE'", 'description' => "'{$language}MAXSIZE_DESC'",
501
                    'formtype' => "'textbox'", 'valuetype' => "'int'", 'default' => '5000000', );
502
                $ret .= $this->usercode->getUserModVersion(3, $maxsize, 'config', '$c');
503
                $ret .= $this->getCommentLine('Uploads : mimetypes of image');
504
                $ret .= $this->getSimpleString('++$c;');
505
                $mimetypes = array('name' => "'mimetypes'", 'title' => "'{$language}MIMETYPES'", 'description' => "'{$language}MIMETYPES_DESC'",
506
                    'formtype' => "'select_multi'", 'valuetype' => "'array'", 'default' => "array('image/gif', 'image/jpeg', 'image/png')", 'options' => "array('bmp' => 'image/bmp','gif' => 'image/gif','pjpeg' => 'image/pjpeg',
507
				   'jpeg' => 'image/jpeg','jpg' => 'image/jpg','jpe' => 'image/jpe',
508
				   'png' => 'image/png')", );
509
                $ret .= $this->usercode->getUserModVersion(3, $mimetypes, 'config', '$c');
510
                $ret .= $this->getSimpleString('++$c;');
511
            }
512 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...
513
                $ret .= $this->getCommentLine('Admin pager');
514
                $adminPager = array('name' => "'adminpager'", 'title' => "'{$language}ADMIN_PAGER'", 'description' => "'{$language}ADMIN_PAGER_DESC'",
515
                        'formtype' => "'textbox'", 'valuetype' => "'int'", 'default' => '10', );
516
                $ret .= $this->usercode->getUserModVersion(3, $adminPager, 'config', '$c');
517
                $ret .= $this->getSimpleString('++$c;');
518
            }
519 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...
520
                $ret .= $this->getCommentLine('User pager');
521
                $userPager = array('name' => "'userpager'", 'title' => "'{$language}USER_PAGER'", 'description' => "'{$language}USER_PAGER_DESC'",
522
                        'formtype' => "'textbox'", 'valuetype' => "'int'", 'default' => '10', );
523
                $ret .= $this->usercode->getUserModVersion(3, $userPager, 'config', '$c');
524
                $ret .= $this->getSimpleString('++$c;');
525
            }
526 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...
527
                $ret .= $this->getCommentLine('Use tag');
528
                $useTag = array('name' => "'usetag'", 'title' => "'{$language}USE_TAG'", 'description' => "'{$language}USE_TAG_DESC'",
529
                        'formtype' => "'yesno'", 'valuetype' => "'int'", 'default' => '0', );
530
                $ret .= $this->usercode->getUserModVersion(3, $useTag, 'config', '$c');
531
                $ret .= $this->getSimpleString('++$c;');
532
            }
533
        }
534
        $ret .= $this->getCommentLine('Number column');
535
        $numbCol = array('name' => "'numb_col'", 'title' => "'{$language}NUMB_COL'", 'description' => "'{$language}NUMB_COL_DESC'",
536
                        'formtype' => "'select'", 'valuetype' => "'int'", 'default' => '1', 'options' => "array(1 => '1', 2 => '2', 3 => '3', 4 => '4')", );
537
        $ret .= $this->usercode->getUserModVersion(3, $numbCol, 'config', '$c');
538
        $ret .= $this->getSimpleString('++$c;');
539
        $ret .= $this->getCommentLine('Divide by');
540
        $divideby = array('name' => "'divideby'", 'title' => "'{$language}DIVIDEBY'", 'description' => "'{$language}DIVIDEBY_DESC'",
541
                        'formtype' => "'select'", 'valuetype' => "'int'", 'default' => '1', 'options' => "array(1 => '1', 2 => '2', 3 => '3', 4 => '4')", );
542
        $ret .= $this->usercode->getUserModVersion(3, $divideby, 'config', '$c');
543
        $ret .= $this->getSimpleString('++$c;');
544
        $ret .= $this->getCommentLine('Table type');
545
        $tableType = array('name' => "'table_type'", 'title' => "'{$language}DIVIDEBY'", 'description' => "'{$language}DIVIDEBY_DESC'",
546
                        'formtype' => "'select'", 'valuetype' => "'int'", 'default' => "'bordered'", 'options' => "array('bordered' => 'bordered', 'striped' => 'striped', 'hover' => 'hover', 'condensed' => 'condensed')", );
547
        $ret .= $this->usercode->getUserModVersion(3, $tableType, 'config', '$c');
548
        $ret .= $this->getSimpleString('++$c;');
549
        $ret .= $this->getCommentLine('Panel by');
550
        $panelType = array('name' => "'panel_type'", 'title' => "'{$language}PANEL_TYPE'", 'description' => "'{$language}PANEL_TYPE_DESC'",
551
                        'formtype' => "'select'", 'valuetype' => "'text'", 'default' => "'default'", 'options' => "array('default' => 'default', 'primary' => 'primary', 'success' => 'success', 'info' => 'info', 'warning' => 'warning', 'danger' => 'danger')", );
552
        $ret .= $this->usercode->getUserModVersion(3, $panelType, 'config', '$c');
553
        $ret .= $this->getSimpleString('++$c;');
554
        $ret .= $this->getCommentLine('Panel by');
555
        $advertise = array('name' => "'advertise'", 'title' => "'{$language}ADVERTISE'", 'description' => "'{$language}ADVERTISE_DESC'",
556
                        'formtype' => "'textarea'", 'valuetype' => "'text'", 'default' => "''", );
557
        $ret .= $this->usercode->getUserModVersion(3, $advertise, 'config', '$c');
558
        $ret .= $this->getSimpleString('++$c;');
559
        $ret .= $this->getCommentLine('Panel by');
560
        $bookmarks = array('name' => "'bookmarks'", 'title' => "'{$language}BOOKMARKS'", 'description' => "'{$language}BOOKMARKS_DESC'",
561
                        'formtype' => "'yesno'", 'valuetype' => "'int'", 'default' => '0', );
562
        $ret .= $this->usercode->getUserModVersion(3, $bookmarks, 'config', '$c');
563
        $ret .= $this->getSimpleString('++$c;');
564
        $ret .= $this->getCommentLine('Facebook Comments');
565
        $facebookComments = array('name' => "'facebook_comments'", 'title' => "'{$language}FACEBOOK_COMMENTS'", 'description' => "'{$language}FACEBOOK_COMMENTS_DESC'",
566
                        'formtype' => "'yesno'", 'valuetype' => "'int'", 'default' => '0', );
567
        $ret .= $this->usercode->getUserModVersion(3, $facebookComments, 'config', '$c');
568
        $ret .= $this->getSimpleString('++$c;');
569
        $ret .= $this->getCommentLine('Disqus Comments');
570
        $disqusComments = array('name' => "'disqus_comments'", 'title' => "'{$language}DISQUS_COMMENTS'", 'description' => "'{$language}DISQUS_COMMENTS_DESC'",
571
                        'formtype' => "'yesno'", 'valuetype' => "'int'", 'default' => '0', );
572
        $ret .= $this->usercode->getUserModVersion(3, $disqusComments, 'config', '$c');
573
        $ret .= $this->getSimpleString('++$c;');
574
        $ret .= $this->getCommentLine('Maintained by');
575
        $maintainedby = array('name' => "'maintainedby'", 'title' => "'{$language}MAINTAINEDBY'", 'description' => "'{$language}MAINTAINEDBY_DESC'",
576
                        'formtype' => "'yesno'", 'valuetype' => "'int'", 'default' => "'{$module->getVar('mod_support_url')}'", );
577
        $ret .= $this->usercode->getUserModVersion(3, $maintainedby, 'config', '$c');
578
        $ret .= $this->getSimpleString('unset($c);');
579
580
        return $ret;
581
    }
582
583
    /*
584
    *  @private function getNotificationsType
585
    *  @param $language
586
    *  @param $type
587
    *  @param $tableName
588
    *  @param $item
589
    *  @param $typeOfNotify
590
    */
591
    /**
592
     * @param $language
593
     * @param $type
594
     * @param $tableName
595
     * @param $notifyFile
596
     * @param $item
597
     * @param $typeOfNotify
598
     *
599
     * @return string
600
     */
601
    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...
602
    {
603
        $stuTableName = strtoupper($tableName);
604
        $stuTypeOfNotify = strtoupper($typeOfNotify);
605
        $notifyFile = explode(', ', $notifyFile);
606
        $notifyFile = implode(', ', $notifyFile);
607
        switch ($type) {
608
            case 'category':
609
                $ret .= $this->getCommentLine('Category Notify');
0 ignored issues
show
Bug introduced by
The variable $ret does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
610
                $category = array('name' => "'category'", 'title' => "'{$language}{$stuTableName}_NOTIFY'", 'description' => "'{$language}{$stuTableName}_NOTIFY_DESC'",
611
                                    'subscribe_from' => "array('index.php',{$notifyFile})", 'item_name' => "'{$item}'", "'allow_bookmark'" => '1', );
612
                $ret .= $this->usercode->getUserModVersion(3, $category, 'notification', "'{$type}'");
613
                break;
614
            case 'event':
615
                $ret .= $this->getCommentLine('Event Notify');
616
                $event = array('name' => "'{$typeOfNotify}'", 'category' => "'{$tableName}'", 'admin_only' => '1', "'title'" => "'{$language}{$stuTableName}_{$stuTypeOfNotify}_NOTIFY'",
617
                                'caption' => "'{$language}{$stuTableName}_{$stuTypeOfNotify}_NOTIFY_CAPTION'", 'description' => "'{$language}{$stuTableName}_{$stuTypeOfNotify}_NOTIFY_DESC'",
618
                                'mail_template' => "'{$tableName}_{$typeOfNotify}_notify'", 'mail_subject' => "'{$language}{$stuTableName}_{$stuTypeOfNotify}_NOTIFY_SUBJECT'", );
619
                $ret .= $this->usercode->getUserModVersion(3, $event, 'notification', "'{$type}'");
620
                break;
621
        }
622
623
        return $ret;
624
    }
625
626
    /*
627
    *  @private function getXoopsVersionNotifications
628
    *  @param $moduleDirname
629
    *  @param $language
630
    */
631
    /**
632
     * @param $moduleDirname
633
     * @param $language
634
     * @param $filename
635
     *
636
     * @return string
637
     */
638
    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...
639
    {
640
        $moduleDirname = $module->getVar('mod_dirname');
641
        $ret = $this->getHeaderComment('Notifications');
642
        $ret .= $this->usercode->getUserModVersion(1, 1, 'hasNotification');
643
        $notifications = array("'lookup_file'" => "'include/notification.inc.php'", "'lookup_func'" => "'{$moduleDirname}_notify_iteminfo'");
644
        $ret .= $this->usercode->getUserModVersion(2, $notifications, 'notification');
645
646
        $notifyFiles = array();
647
        $single = 'single';
648
        $tables = $this->getTableTables($module->getVar('mod_id'), 'table_order');
649
        foreach (array_keys($tables) as $t) {
650
            $tableId = $tables[$t]->getVar('table_id');
651
            $tableMid = $tables[$t]->getVar('table_mid');
652
            $tableName = $tables[$t]->getVar('table_name');
653
            $tableCategory = $tables[$t]->getVar('table_category');
654
            $tableBroken = $tables[$t]->getVar('table_broken');
655
            $tableSubmit = $tables[$t]->getVar('table_submit');
656
            if (1 == $tables[$t]->getVar('table_notifications')) {
657
                if ($t <= count($tableName)) {
658
                    $notifyFiles[] = $tables[$t]->getVar('table_name');
659
                }
660
            }
661
            if (1 == $tables[$t]->getVar('table_single')) {
662
                $single = $tableName;
663
            }
664
        }
665
        $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...
666
        $fieldParent = null;
667
        foreach (array_keys($fields) as $f) {
668
            $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...
669
            $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...
670
            $fieldName = $fields[$f]->getVar('field_name');
671
            $fieldElement = $fields[$f]->getVar('field_element');
672
            if (0 == $f) {
673
                $fieldId = $fieldName;
674
            }
675
            if ($fieldElement > 15) {
676
                $fieldParent = $fieldName;
677
            }
678
        }
679
680
        $num = 1;
681
        $ret .= $this->getXoopsVersionNotificationGlobal($language, 'category', 'global', 'global', $notifyFiles, $num);
682
        ++$num;
683
        $ret .= $this->getXoopsVersionNotificationCategory($language, 'category', 'category', 'category', $notifyFiles, $fieldParent, '1', $num);
684
        ++$num;
685
        $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...
686
        unset($num);
687
        $num = 1;
688
        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...
689
            ++$num;
690
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'new_category', 'global', 0, 'global', 'newcategory', 'global_newcategory_notify', $num);
691
        }
692
        $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'file_modify', 'global', 1, 'global', 'filemodify', 'global_filemodify_notify', $num);
693
        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...
694
            ++$num;
695
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'file_broken', 'global', 1, 'global', 'filebroken', 'global_filebroken_notify', $num);
696
        }
697
        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...
698
            ++$num;
699
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'file_submit', 'global', 1, 'global', 'filesubmit', 'global_filesubmit_notify', $num);
700
        }
701
        ++$num;
702
        $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'new_file', 'global', 0, 'global', 'newfile', 'global_newfile_notify', $num);
703
        if (1 == $tableCategory) {
704
            ++$num;
705
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'file_submit', 'category', 1, 'category', 'filesubmit', 'category_filesubmit_notify', $num);
706
            ++$num;
707
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'new_file', 'category', 0, 'category', 'newfile', 'category_newfile_notify', $num);
708
        }
709
        ++$num;
710
        $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'approve', 'file', 1, 'file', 'approve', 'file_approve_notify', $num);
711
        unset($num);
712
713
        return $ret;
714
    }
715
716
    /*
717
    *  @private function getXoopsVersionNotificationGlobal
718
    */
719
    /**
720
     * @param $language
721
     * @param $type
722
     * @param $name
723
     * @param $title
724
     * @param $from
725
     *
726
     * @return string
727
     */
728
    private function getXoopsVersionNotificationGlobal($language, $type, $name, $title, $from, $num)
729
    {
730
        $title = strtoupper($title);
731
        $implodeFrom = implode(".php', '", $from);
732
        $ret = $this->getCommentLine('Global Notify');
733
        $global = array('name' => "'{$name}'", 'title' => "{$language}{$title}_NOTIFY", 'description' => "{$language}{$title}_NOTIFY_DESC",
734
                        'subscribe_from' => "array('index.php', '{$implodeFrom}.php')", );
735
        $ret .= $this->usercode->getUserModVersion(4, $global, 'notification', "'{$type}'", $num);
736
737
        return $ret;
738
    }
739
740
    /*
741
    *  @private function getXoopsVersionNotificationCategory
742
    */
743
    /**
744
     * @param $language
745
     * @param $type
746
     * @param $name
747
     * @param $title
748
     * @param $from
749
     *
750
     * @return string
751
     */
752 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...
753
    {
754
        $title = strtoupper($title);//{$from}
755
        $implodeFrom = implode(".php', '", $from);
756
        $ret = $this->getCommentLine('Category Notify');
757
        $global = array('name' => "'{$name}'", 'title' => "{$language}{$title}_NOTIFY", 'description' => "{$language}{$title}_NOTIFY_DESC",
758
                        'subscribe_from' => "array('{$implodeFrom}.php')", 'item_name' => "'{$item}'", 'allow_bookmark' => "{$allow}", );
759
        $ret .= $this->usercode->getUserModVersion(4, $global, 'notification', "'{$type}'", $num);
760
761
        return $ret;
762
    }
763
764
    /*
765
    *  @private function getXoopsVersionNotificationTableName
766
    */
767
    /**
768
     * @param $language
769
     * @param $type
770
     * @param $name
771
     * @param $title
772
     * @param $from
773
     * @param $item
774
     * @param $allow
775
     *
776
     * @return string
777
     */
778 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...
779
    {
780
        $stuTitle = strtoupper($title);
781
        $ucfTitle = ucfirst($title);
782
        $ret = $this->getCommentLine($ucfTitle.' Notify');
783
        $global = array('name' => "'{$name}'", 'title' => "{$language}{$stuTitle}_NOTIFY", 'description' => "{$language}{$stuTitle}_NOTIFY_DESC",
784
                        'subscribe_from' => "'{$from}.php'", 'item_name' => "'{$item}'", 'allow_bookmark' => "{$allow}", );
785
        $ret .= $this->usercode->getUserModVersion(4, $global, 'notification', "'{$type}'", $num);
786
787
        return $ret;
788
    }
789
790
    /*
791
    *  @private function getXoopsVersionNotifications
792
    */
793
    /**
794
     * @param $language
795
     * @param $type
796
     * @param $name
797
     * @param $title
798
     * @param $from
799
     * @param $item
800
     * @param $mail
801
     *
802
     * @return string
803
     */
804
    private function getXoopsVersionNotificationCodeComplete($language, $type, $name, $category, $admin = 1, $title, $table, $mail, $num)
805
    {
806
        $title = strtoupper($title);
807
        $table = strtoupper($table);
808
        $ucfTitle = ucfirst($title);
809
        $ret = $this->getCommentLine($ucfTitle.' Notify');
810
        $event = array('name' => "'{$name}'", 'category' => "'{$category}'", 'admin_only' => "{$admin}", 'title' => "{$language}{$title}_{$table}_NOTIFY",
811
                        'caption' => "{$language}{$title}_{$table}_NOTIFY_CAPTION", 'description' => "{$language}{$title}_{$table}_NOTIFY_DESC",
812
                        'mail_template' => "'{$mail}'", 'mail_subject' => "{$language}{$title}_{$table}_NOTIFY_SUBJECT", );
813
        $ret .= $this->usercode->getUserModVersion(4, $event, 'notification', "'{$type}'", $num);
814
815
        return $ret;
816
    }
817
818
    /*
819
    *  @public function render
820
    *  @param null
821
    */
822
    /**
823
     * @return bool|string
824
     */
825
    public function render()
826
    {
827
        $module = $this->getModule();
828
        $table = $this->getTable();
829
        $tables = $this->getTables();
830
        $filename = $this->getFileName();
831
        $moduleDirname = $module->getVar('mod_dirname');
832
        $language = $this->getLanguage($moduleDirname, 'MI');
833
        $content = $this->getHeaderFilesComments($module, $filename);
834
        $content .= $this->getXoopsVersionHeader($module, $table, $language);
835
        if (1 == $module->getVar('mod_admin')) {
836
            $content .= $this->getXoopsVersionTemplatesAdmin($moduleDirname, $table, $tables);
837
        }
838
        if (1 == $module->getVar('mod_user')) {
839
            $content .= $this->getXoopsVersionTemplatesUser($moduleDirname, $tables);
840
        }
841
        $content .= $this->getXoopsVersionMySQL($moduleDirname, $table, $tables);
842
        if (1 == $table->getVar('table_search')) {
843
            $content .= $this->getXoopsVersionSearch($moduleDirname);
844
        }
845
        if (1 == $table->getVar('table_comments')) {
846
            $content .= $this->getXoopsVersionComments($moduleDirname);
847
        }
848
849
        //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...
850
            $content .= $this->getXoopsVersionSubmenu($language, $tables);
851
        //}
852
        if (1 == $table->getVar('table_blocks')) {
853
            $content .= $this->getXoopsVersionBlocks($moduleDirname, $table, $tables, $language);
854
        }
855
        $content .= $this->getXoopsVersionConfig($module, $table, $language);
856
        if (1 == $table->getVar('table_notifications')) {
857
            $content .= $this->getXoopsVersionNotifications($module, $language, $filename);
858
        }
859
        $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...
860
861
        return $this->renderFile();
862
    }
863
}
864