Passed
Push — master ( 0f0f99...fb91d6 )
by Michael
17s
created

UserIndex::getBodyPagesIndex()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 50
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
c 4
b 1
f 0
dl 0
loc 50
rs 9.3333
cc 3
eloc 43
nc 3
nop 5
1
<?php
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
25
/**
26
 * Class UserIndex.
27
 */
28
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...
29
{
30
    /*
31
    *  @public function constructor
32
    *  @param null
33
    */
34
    /**
35
     *
36
     */
37
    public function __construct()
38
    {
39
        parent::__construct();
40
    }
41
42
    /*
43
    *  @static function &getInstance
44
    *  @param null
45
    */
46
    /**
47
     * @return UserIndex
48
     */
49
    public static function &getInstance()
50
    {
51
        static $instance = false;
52
        if (!$instance) {
53
            $instance = new self();
54
        }
55
56
        return $instance;
57
    }
58
59
    /*
60
    *  @public function write
61
    *  @param string $module
62
    *  @param string $filename
63
    */
64
    /**
65
     * @param $module
66
     * @param $filename
67
     */
68
    public function write($module, $table, $filename)
69
    {
70
        $this->setModule($module);
71
        $this->setTable($table);
72
        $this->setFileName($filename);
73
    }
74
75
    /**
76
     * @private function getTemplateHeaderFile
77
     *
78
     * @param $moduleDirname
79
     *
80
     * @return string
81
     */
82
    private function getTemplateHeaderFile($moduleDirname)
83
    {
84
        $pc = TDMCreatePhpCode::getInstance();
85
        $xc = TDMCreateXoopsCode::getInstance();
86
        $uc = UserXoopsCode::getInstance();
87
        $cc = ClassXoopsCode::getInstance();
0 ignored issues
show
Unused Code introduced by
$cc is not used, you could remove the assignment.

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

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

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

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

Loading history...
88
        $ret = $this->getInclude();
89
        $ret .= $uc->getUserTplMain($moduleDirname);
90
        $ret .= $pc->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'header', true);
91
        $ret .= $pc->getPhpCodeCommentLine('Define Stylesheet');
92
        $ret .= $xc->getXcAddStylesheet();
93
        $ret .= $pc->getPhpCodeArray('keywords');
94
95
        return $ret;
96
    }
97
98
    /**
99
     * @private function getBodyCategoriesIndex
100
     *
101
     * @param $moduleDirname
102
     * @param $language
103
     *
104
     * @return string
105
     */
106
    private function getBodyCategoriesIndex($moduleDirname, $tableMid, $tableId, $tableName, $tableSoleName, $tableFieldname)
107
    {
108
        $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...
109
        // Fields
110
        $fields = $this->getTableFields($tableMid, $tableId);
111
        $fieldParentId = array();
112
        foreach (array_keys($fields) as $f) {
113
            $fieldName = $fields[$f]->getVar('field_name');
114
            if (0 == $f) {
115
                $fieldId = $fieldName; // fieldMain = fields parameters main field
0 ignored issues
show
Unused Code introduced by
$fieldId 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...
116
            }
117
            $fieldParentId[] = $fields[$f]->getVar('field_parent');
118
            if (1 == $fields[$f]->getVar('field_main')) {
119
                $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...
120
            }
121
            if (1 == $fields[$f]->getVar('field_parent')) {
122
                $fieldParent = $fieldName; // fieldMain = fields parameters main field
0 ignored issues
show
Unused Code introduced by
$fieldParent 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...
123
            }
124
        }
125
        $ret = '';
126
        $pc = TDMCreatePhpCode::getInstance();
127
        $xc = TDMCreateXoopsCode::getInstance();
128
        $cc = ClassXoopsCode::getInstance();
0 ignored issues
show
Unused Code introduced by
$cc 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...
129
        if (in_array(1, $fieldParentId)) {
130
            $ret .= $xc->getXcObjHandlerCount($tableName);
131
            $ret .= $pc->getPhpCodeCommentLine('If there are ', $tableName);
132
            $ret .= $this->getSimpleString('$count = 1;');
133
134
            $contentIf = $xc->getXcObjHandlerAll($tableName, '', 0, 0, "\t");
135
            $contentIf .= $pc->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/tree', true, false, 'include', "\t");
136
            //$contentIf .= $cc->getClassXoopsObjectTree('mytree', $tableName, $fieldId, $fieldParent, "\t");
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...
137
            $contentIf .= $pc->getPhpCodeArray($tableName, "\t");
138
            $foreach = $xc->getXcGetValues($tableName, $tableSoleName, $tableFieldname, false, "\t");
139
            $foreach .= $pc->getPhpCodeArray('acount', array("'count'", '$count'));
140
            $foreach .= $pc->getPhpCodeArrayType($tableName, 'merge', $tableSoleName, '$acount');
141
            $foreach .= $this->getSimpleString('++$count;', "\t\t");
142
            $contentIf .= $pc->getPhpCodeForeach("{$tableName}All", true, false, $tableFieldname, $foreach, "\t");
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a false|string.

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...
143
            $contentIf .= $xc->getXcTplAssign($tableName, '$'.$tableName, true, "\t");
144
            $contentIf .= $pc->getPhpCodeUnset($tableName, "\t");
145
            $getConfig = $xc->getXcGetConfig($moduleDirname, 'numb_col');
146
            $contentIf .= $xc->getXcTplAssign('numb_col', $getConfig, true, "\t");
147
            $ret .= $pc->getPhpCodeConditions("\${$tableName}Count", ' > ', '0', $contentIf, false);
148
            $ret .= $pc->getPhpCodeUnset('count');
149
        }
150
        unset($fieldParentId);
151
152
        return $ret;
153
    }
154
155
    /**
156
     * @private function getBodyPagesIndex
157
     *
158
     * @param $moduleDirname
159
     * @param $language
160
     *
161
     * @return string
162
     */
163
    private function getBodyPagesIndex($moduleDirname, $tableName, $tableSoleName, $tableFieldname, $language)
164
    {
165
        $pc = TDMCreatePhpCode::getInstance();
166
        $xc = TDMCreateXoopsCode::getInstance();
167
        $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...
168
        $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...
169
        $stuModuleDirname = strtoupper($moduleDirname);
170
        $ucfTableName = ucfirst($tableName);
171
        $ret = $pc->getPhpCodeCommentLine();
172
        $ret .= $xc->getXcTplAssign('xoops_icons32_url', 'XOOPS_ICONS32_URL');
173
        $ret .= $xc->getXcTplAssign("{$moduleDirname}_url", "{$stuModuleDirname}_URL");
174
        $ret .= $pc->getPhpCodeCommentLine();
175
        $ret .= $xc->getXcObjHandlerCount($tableName);
176
        $ret .= $this->getSimpleString('$count = 1;');
177
        $condIf = $xc->getXcXoopsRequest('start', 'start', '0', 'Int', false, "\t");
178
        $userpager = $xc->getXcGetConfig($moduleDirname, 'userpager');
179
        $condIf .= $xc->getXcXoopsRequest('limit', 'limit', $userpager, 'Int', false, "\t");
180
        $condIf .= $xc->getXcObjHandlerAll($tableName, '', '$start', '$limit', "\t");
181
        $condIf .= $pc->getPhpCodeCommentLine('Get All', $ucfTableName, "\t");
182
        $condIf .= $pc->getPhpCodeArray($tableName);
183
        $foreach = $xc->getXcGetValues($tableName, $tableSoleName, $tableFieldname, false, "\t");
184
        $foreach .= $pc->getPhpCodeArray('acount', array("'count'", '$count'));
185
        $foreach .= $pc->getPhpCodeArrayType($tableName, 'merge', $tableSoleName, '$acount');
186
        $table = $this->getTable();
187
        // Fields
188
        $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
189
        foreach (array_keys($fields) as $f) {
190
            $fieldName = $fields[$f]->getVar('field_name');
191
            if (1 == $fields[$f]->getVar('field_main')) {
192
                $fieldMain = $fieldName; // fieldMain = fields parameters main field
193
            }
194
        }
195
        $foreach .= $xc->getXcGetVar('keywords[]', "{$tableName}All[\$i]", $fieldMain, false, "\t\t");
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...
196
        $foreach .= $this->getSimpleString('++$count;', "\t\t");
197
        $condIf .= $pc->getPhpCodeForeach("{$tableName}All", true, false, 'i', $foreach, "\t");
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a false|string.

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...
198
        $condIf .= $xc->getXcTplAssign($tableName, '$'.$tableName, true, "\t");
199
        $condIf .= $pc->getPhpCodeUnset($tableName, "\t");
200
        $condIf .= $xc->getXcPageNav($tableName, "\t");
201
        $thereare = $pc->getPhpCodeSprintf("{$language}INDEX_THEREARE", "\${$tableName}Count");
202
        $condIf .= $xc->getXcTplAssign('lang_thereare', $thereare, true, "\t");
203
        $divideby = $xc->getXcGetConfig($moduleDirname, 'divideby');
204
        $condIf .= $xc->getXcTplAssign('divideby', $divideby, true, "\t");
205
206
        $ret .= $pc->getPhpCodeConditions("\${$tableName}Count", ' > ', '0', $condIf);
207
        $ret .= $pc->getPhpCodeUnset('count');
208
        $tableType = $xc->getXcGetConfig($moduleDirname, 'table_type');
209
        $ret .= $xc->getXcTplAssign('table_type', $tableType);
210
211
        return $ret;
212
    }
213
214
    /**
215
     * @private function getUserPagesFooter
216
     *
217
     * @param $moduleDirname
218
     * @param $tableName
219
     * @param $language
220
     *
221
     * @return string
222
     */
223
    private function getUserIndexFooter($moduleDirname, $language)
224
    {
225
        $pc = TDMCreatePhpCode::getInstance();
226
        $xc = TDMCreateXoopsCode::getInstance();
227
        $uc = UserXoopsCode::getInstance();
228
        $stuModuleDirname = strtoupper($moduleDirname);
229
        $ret = $pc->getPhpCodeCommentLine('Breadcrumbs');
230
        $ret .= $uc->getUserBreadcrumbs($language);
231
        $ret .= $pc->getPhpCodeCommentLine('Keywords');
232
        $ret .= $uc->getUserMetaKeywords($moduleDirname);
233
        $ret .= $pc->getPhpCodeUnset('keywords');
234
        $ret .= $pc->getPhpCodeCommentLine('Description');
235
        $ret .= $uc->getUserMetaDesc($moduleDirname, $language);
236
        $ret .= $xc->getXcTplAssign('xoops_mpageurl', "{$stuModuleDirname}_URL.'/index.php'");
237
        $ret .= $xc->getXcTplAssign('xoops_icons32_url', 'XOOPS_ICONS32_URL');
238
        $ret .= $xc->getXcTplAssign("{$moduleDirname}_upload_url", "{$stuModuleDirname}_UPLOAD_URL");
239
        $ret .= $this->getInclude('footer');
240
241
        return $ret;
242
    }
243
244
    /*
245
    *  @public function render
246
    *  @param null
247
    */
248
    /**
249
     * @return bool|string
250
     */
251
    public function render()
252
    {
253
        $module = $this->getModule();
254
        $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...
255
        $tables = $this->getTableTables($module->getVar('mod_id'), 'table_order');
256
        $filename = $this->getFileName();
257
        $moduleDirname = $module->getVar('mod_dirname');
258
        $language = $this->getLanguage($moduleDirname, 'MA');
259
        $content = $this->getHeaderFilesComments($module, $filename);
260
        $content .= $this->getTemplateHeaderFile($moduleDirname);
261
        foreach (array_keys($tables) as $t) {
262
            $tableId = $tables[$t]->getVar('table_id');
263
            $tableMid = $tables[$t]->getVar('table_mid');
264
            $tableName = $tables[$t]->getVar('table_name');
265
            $tableSoleName = $tables[$t]->getVar('table_solename');
266
            $tableCategory[] = $tables[$t]->getVar('table_category');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$tableCategory was never initialized. Although not strictly required by PHP, it is generally a good practice to add $tableCategory = 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...
267
            $tableFieldname = $tables[$t]->getVar('table_fieldname');
268
            $tableIndex[] = $tables[$t]->getVar('table_index');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$tableIndex was never initialized. Although not strictly required by PHP, it is generally a good practice to add $tableIndex = 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...
269
            if (in_array(1, $tableCategory) && in_array(1, $tableIndex)) {
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...
Bug introduced by
The variable $tableIndex 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...
270
                $content .= $this->getBodyCategoriesIndex($moduleDirname, $tableMid, $tableId, $tableName, $tableSoleName, $tableFieldname);
271
            }
272
            if (in_array(0, $tableCategory) && in_array(1, $tableIndex)) {
273
                $content .= $this->getBodyPagesIndex($moduleDirname, $tableName, $tableSoleName, $tableFieldname, $language);
274
            }
275
        }
276
        $content .= $this->getUserIndexFooter($moduleDirname, $language);
277
        //
278
        $this->create($moduleDirname, '/', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
279
280
        return $this->renderFile();
281
    }
282
}
283