Completed
Pull Request — master (#51)
by Gino
06:03
created

UserIndex   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 241
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4
Metric Value
wmc 21
lcom 2
cbo 4
dl 0
loc 241
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getInstance() 0 9 2
A write() 0 6 1
A getTemplateHeaderFile() 0 10 1
B getBodyCategoriesIndex() 0 43 6
B getBodyPagesIndex() 0 45 3
A getUserIndexFooter() 0 18 1
B render() 0 31 6
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: user_index.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
defined('XOOPS_ROOT_PATH') || die('Restricted access');
25
26
/**
27
 * Class UserIndex.
28
 */
29
class UserIndex 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
    *  @public function constructor
33
    *  @param null
34
    */
35
    /**
36
     *
37
     */
38
    public function __construct()
39
    {
40
        parent::__construct();
41
        $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...
42
        $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...
43
        $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...
44
    }
45
46
    /*
47
    *  @static function &getInstance
48
    *  @param null
49
    */
50
    /**
51
     * @return UserIndex
52
     */
53
    public static function &getInstance()
54
    {
55
        static $instance = false;
56
        if (!$instance) {
57
            $instance = new self();
58
        }
59
60
        return $instance;
61
    }
62
63
    /*
64
    *  @public function write
65
    *  @param string $module
66
    *  @param string $filename
67
    */
68
    /**
69
     * @param $module
70
     * @param $filename
71
     */
72
    public function write($module, $table, $filename)
73
    {
74
        $this->setModule($module);
75
        $this->setTable($table);
76
        $this->setFileName($filename);
77
    }
78
79
    /**
80
     * @private function getTemplateHeaderFile
81
     *
82
     * @param $moduleDirname
83
     *
84
     * @return string
85
     */
86
    private function getTemplateHeaderFile($moduleDirname)
87
    {
88
        $ret = $this->getInclude();
89
        $ret .= $this->usercode->getUserTplMain($moduleDirname);
90
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'header', true);
91
        $ret .= $this->getCommentLine('Define Stylesheet');
92
        $ret .= $this->xoopscode->getXoopsCodeAddStylesheet();
93
94
        return $ret;
95
    }
96
97
    /**
98
     * @private function getBodyCategoriesIndex
99
     *
100
     * @param $moduleDirname
101
     * @param $language
102
     *
103
     * @return string
104
     */
105
    private function getBodyCategoriesIndex($moduleDirname, $tableMid, $tableId, $tableName, $tableSoleName, $tableFieldname)
106
    {
107
        $ucfTableName = ucfirst($tableName);
0 ignored issues
show
Unused Code introduced by
$ucfTableName is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
108
        // Fields
109
        $fields = $this->getTableFields($tableMid, $tableId);
110
111
        foreach (array_keys($fields) as $f) {
112
            $fieldName = $fields[$f]->getVar('field_name');
113
            if (0 == $f) {
114
                $fieldId = $fieldName; // fieldMain = fields parameters main field
115
            }
116
            $fieldParentId[] = $fields[$f]->getVar('field_parent');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$fieldParentId was never initialized. Although not strictly required by PHP, it is generally a good practice to add $fieldParentId = 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...
117
            if (1 == $fields[$f]->getVar('field_main')) {
118
                $fieldMain = $fieldName; // fieldMain = fields parameters main field
0 ignored issues
show
Unused Code introduced by
$fieldMain 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...
119
            }
120
            if (1 == $fields[$f]->getVar('field_parent')) {
121
                $fieldParent = $fieldName; // fieldMain = fields parameters main field
122
            }
123
        }
124
        $ret = '';
125
        if (in_array(1, $fieldParentId)) {
0 ignored issues
show
Bug introduced by
The variable $fieldParentId 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...
126
            $ret .= $this->xoopscode->getXoopsCodeObjHandlerCount($tableName);
127
            $ret .= $this->getCommentLine('If there are ', $tableName);
128
            $ret .= $this->getSimpleString('$count = 1;');
129
130
            $contentIf = $this->xoopscode->getXoopsCodeObjHandlerAll($tableName);
131
            $contentIf .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/tree', true);
132
            $contentIf .= $this->xoopscode->getXoopsCodeObjectTree($tableName, $fieldId, $fieldParent);
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...
Bug introduced by
The variable $fieldParent 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...
133
134
            $foreach = $this->xoopscode->getXoopsCodeGetValues($tableName, $tableSoleName, $tableFieldname);
135
            $foreach .= $this->phpcode->getPhpCodeArray('acount', 'count', '$count');
136
            $foreach .= $this->phpcode->getPhpCodeArrayMerge($tableSoleName, "\${$tableSoleName}", '$acount');
137
            $foreach .= $this->xoopscode->getXoopsCodeXoopsTplAppend($tableName, "\${$tableSoleName}");
138
            $foreach .= $this->phpcode->getPhpCodeUnset($tableSoleName);
139
            $contentIf .= $this->phpcode->getPhpCodeForeach("\${$tableName}All", true, false, $tableFieldname, $foreach, "\t");
140
            $getConfig = $this->xoopscode->getXoopsCodeGetConfig($moduleDirname, 'numb_col');
141
            $contentIf .= $this->xoopscode->getXoopsCodeTplAssign('numb_col', $getConfig);
142
            $ret .= $this->phpcode->getPhpCodeConditions("\${$tableName}Count", ' > ', '0', $contentIf, false);
143
            $ret .= $this->phpcode->getPhpCodeUnset('count');
144
        }
145
146
        return $ret;
147
    }
148
149
    /**
150
     * @private function getBodyPagesIndex
151
     *
152
     * @param $moduleDirname
153
     * @param $language
154
     *
155
     * @return string
156
     */
157
    private function getBodyPagesIndex($moduleDirname, $tableName, $tableSoleName, $tableFieldname, $language)
158
    {
159
        $stuModuleDirname = strtoupper($moduleDirname);
0 ignored issues
show
Unused Code introduced by
$stuModuleDirname 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...
160
        $ucfTableName = ucfirst($tableName);
0 ignored issues
show
Unused Code introduced by
$ucfTableName is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
161
        $stuModuleDirname = strtoupper($moduleDirname);
162
        $ucfTableName = ucfirst($tableName);
163
        $ret = $this->getCommentLine();
164
        $ret .= $this->xoopscode->getXoopsCodeTplAssign('xoops_icons32_url', 'XOOPS_ICONS32_URL');
165
        $ret .= $this->xoopscode->getXoopsCodeTplAssign("{$moduleDirname}_upload_url", "{$stuModuleDirname}_UPLOAD_URL");
166
        $ret .= $this->getCommentLine();
167
        $ret .= $this->xoopscode->getXoopsCodeObjHandlerCount($tableName);
168
        $ret .= $this->getSimpleString('$count = 1;');
169
        $condIf = $this->xoopscode->getXoopsCodeXoopsRequest('start', 'start', '0', 'Int');
170
        $userpager = $this->xoopscode->getXoopsCodeGetConfig($moduleDirname, 'userpager');
171
        $condIf .= $this->xoopscode->getXoopsCodeXoopsRequest('limit', 'limit', $userpager, 'Int');
172
        $condIf .= $this->xoopscode->getXoopsCodeObjHandlerAll($tableName, '', '$start', '$limit');
173
        $condIf .= $this->getCommentLine('Get All', $ucfTableName);
174
        $foreach = $this->xoopscode->getXoopsCodeGetValues($tableName, $tableFieldname);
175
        $foreach .= $this->phpcode->getPhpCodeArray('acount', "'count'", '$count');
176
        $foreach .= $this->phpcode->getPhpCodeArrayMerge('acount', "\${$tableSoleName}", '$acount');
177
        $foreach .= $this->xoopscode->getXoopsCodeXoopsTplAppend($tableName, "\${$tableSoleName}");
178
        $table = $this->getTable();
179
        // Fields
180
        $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
181
        foreach (array_keys($fields) as $f) {
182
            $fieldName = $fields[$f]->getVar('field_name');
183
            if (1 == $fields[$f]->getVar('field_main')) {
184
                $fieldMain = $fieldName; // fieldMain = fields parameters main field
185
            }
186
        }
187
        $foreach .= $this->xoopscode->getXoopsCodeGetVar('keywords[]', "{$tableName}All[\$i]", $fieldMain);
0 ignored issues
show
Bug introduced by
The variable $fieldMain does not seem to be defined for all execution paths leading up to this point.

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
188
        $foreach .= $this->phpcode->getPhpCodeUnset($tableSoleName);
189
        $foreach .= $this->getSimpleString('++$count;');
190
        $condIf .= $this->phpcode->getPhpCodeForeach("{$tableName}All", true, false, 'i', $foreach, "\t");
191
        $condIf .= $this->xoopscode->getXoopsCodePageNav($tableName);
192
        $thereare = $this->phpcode->getPhpCodeSprintf("{$language}INDEX_THEREARE", "\${$tableName}Count");
193
        $condIf .= $this->xoopscode->getXoopsCodeTplAssign('lang_thereare', $thereare);
194
        $divideby = $this->xoopscode->getXoopsCodeGetConfig($moduleDirname, 'divideby');
195
        $condIf .= $this->xoopscode->getXoopsCodeTplAssign('divideby', $divideby);
196
197
        $ret .= $this->phpcode->getPhpCodeConditions("\${$tableName}Count", ' > ', '0', $condIf);
198
        $ret .= $this->phpcode->getPhpCodeUnset('count');
199
200
        return $ret;
201
    }
202
203
    /**
204
     * @private function getUserPagesFooter
205
     *
206
     * @param $moduleDirname
207
     * @param $tableName
208
     * @param $language
209
     *
210
     * @return string
211
     */
212
    private function getUserIndexFooter($moduleDirname, $tableName, $language)
213
    {
214
        $stuModuleDirname = strtoupper($moduleDirname);
215
        $stuTableName = strtoupper($tableName);
216
        $ret = $this->getCommentLine('Breadcrumbs');
217
        $ret .= $this->usercode->getUserBreadcrumbs("{$stuTableName}", $language);
218
        $ret .= $this->getCommentLine('Keywords');
219
        $ret .= $this->usercode->getUserMetaKeywords($moduleDirname);
220
        $ret .= $this->phpcode->getPhpCodeUnset('keywords');
221
        $ret .= $this->getCommentLine('Description');
222
        $ret .= $this->usercode->getUserMetaDesc($moduleDirname, 'DESC', $language);
223
        $ret .= $this->xoopscode->getXoopsCodeTplAssign('xoops_mpageurl', "{$stuModuleDirname}_URL.'/index.php'");
224
        $ret .= $this->xoopscode->getXoopsCodeTplAssign('xoops_icons32_url', 'XOOPS_ICONS32_URL');
225
        $ret .= $this->xoopscode->getXoopsCodeTplAssign("{$moduleDirname}_upload_url", "{$stuModuleDirname}_UPLOAD_URL");
226
        $ret .= $this->getInclude('footer');
227
228
        return $ret;
229
    }
230
231
    /*
232
    *  @public function render
233
    *  @param null
234
    */
235
    /**
236
     * @return bool|string
237
     */
238
    public function render()
239
    {
240
        $module = $this->getModule();
241
        $table = $this->getTable();
0 ignored issues
show
Unused Code introduced by
$table is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
242
        $tables = $this->getTableTables($module->getVar('mod_id'), 'table_order');
243
        $filename = $this->getFileName();
244
        $moduleDirname = $module->getVar('mod_dirname');
245
        $language = $this->getLanguage($moduleDirname, 'MA');
246
        $content = $this->getHeaderFilesComments($module, $filename);
247
        $content .= $this->getTemplateHeaderFile($moduleDirname);
248
        foreach (array_keys($tables) as $t) {
249
            $tableId = $tables[$t]->getVar('table_id');
250
            $tableMid = $tables[$t]->getVar('table_mid');
251
            $tableName = $tables[$t]->getVar('table_name');
252
            $tableSoleName = $tables[$t]->getVar('table_solename');
253
            $tableCategory = $tables[$t]->getVar('table_category');
254
            $tableFieldname = $tables[$t]->getVar('table_fieldname');
255
            $tableIndex = $tables[$t]->getVar('table_index');
256
            if ((1 == $tableCategory) && (1 == $tableIndex)) {
257
                $content .= $this->getBodyCategoriesIndex($moduleDirname, $tableMid, $tableId, $tableName, $tableSoleName, $tableFieldname);
258
            }
259
            if ((0 == $tableCategory) && (1 == $tableIndex)) {
260
                $content .= $this->getBodyPagesIndex($moduleDirname, $tableName, $tableSoleName, $tableFieldname, $language);
261
            }
262
        }
263
        $content .= $this->getUserIndexFooter($moduleDirname, $tableName, $language);
0 ignored issues
show
Bug introduced by
The variable $tableName 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...
264
        //
265
        $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...
266
267
        return $this->renderFile();
268
    }
269
}
270