Passed
Branch master (7fc493)
by Gino
03:28
created

SqlFile   C

Complexity

Total Complexity 71

Size/Duplication

Total Lines 426
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2
Metric Value
wmc 71
lcom 2
cbo 2
dl 0
loc 426
rs 5.5904

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getInstance() 0 9 2
A write() 0 6 1
A getHeaderSqlComments() 0 19 1
A getHeadDatabaseTable() 0 9 1
A getDatabaseTables() 0 15 2
F getDatabaseFields() 0 164 47
A getFootDatabaseTable() 0 4 1
A getFieldRow() 0 18 4
B getKey() 0 22 6
A getComma() 0 4 1
A getCommaCicle() 0 13 3
A render() 0 13 1

How to fix   Complexity   

Complex Class

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

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

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

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: SqlFile.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
25
/**
26
 * Class SqlFile.
27
 */
28
class SqlFile 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
    * @var string
32
    */
33
    private $tdmcreate = null;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
34
	
35
	/*
36
    * @var string
37
    */
38
    private $tdmcfile = null;
39
40
    /*
41
    *  @public function constructor
42
    *  @param null
43
    
44
    /*
45
    *  @public function constructor
46
    *  @param null
47
    */
48
    /**
49
     *
50
     */
51
    public function __construct()
52
    {
53
        parent::__construct();
54
		$this->tdmcreate = TDMCreateHelper::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like \TDMCreateHelper::getInstance() of type object<TDMCreateHelper> is incompatible with the declared type string of property $tdmcreate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
55
        $this->tdmcfile = TDMCreateFile::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like \TDMCreateFile::getInstance() of type object<TDMCreateFile> is incompatible with the declared type string of property $tdmcfile.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
56
    }
57
58
    /*
59
    *  @static function &getInstance
60
    *  @param null
61
    */
62
    /**
63
     * @return SqlFile
64
     */
65
    public static function &getInstance()
66
    {
67
        static $instance = false;
68
        if (!$instance) {
69
            $instance = new self();
70
        }
71
72
        return $instance;
73
    }
74
75
    /*
76
    *  @public function write
77
    *  @param $module
78
    *  @param $table
79
    *  @param $tables
80
    *  @param $filename
81
    */
82
    /**
83
     * @param $module
84
     * @param $tables
85
     * @param $filename
86
     */
87
    public function write($module, $tables, $filename)
88
    {
89
        $this->setModule($module);
90
        $this->setTables($tables);
91
        $this->setFileName($filename);
92
    }
93
94
    /*
95
    *  @private function getHeaderSqlComments
96
    *  @param $moduleName
97
    */
98
    /**
99
     * @param $moduleName
100
     *
101
     * @return string
102
     */
103
    private function getHeaderSqlComments($moduleName)
104
    {
105
        $date = date('D M d, Y');
106
        $time = date('G:i');
107
        $server_name = $_SERVER['SERVER_NAME'];
108
        $server_version = mysql_get_server_info();
109
        $php_version = phpversion();
110
        // Header Sql Comments
111
        $ret = $this->getSimpleString("# SQL Dump for {$moduleName} module");
112
		$ret .= $this->getSimpleString('# PhpMyAdmin Version: 4.0.4');
113
		$ret .= $this->getSimpleString('# http://www.phpmyadmin.net');
114
		$ret .= $this->getSimpleString('#');		
115
		$ret .= $this->getSimpleString("# Host: {$server_name}");
116
		$ret .= $this->getSimpleString("# Generated on: {$date} to {$time}");
117
		$ret .= $this->getSimpleString("# Server version: {$server_version}");
118
		$ret .= $this->getSimpleString("# PHP Version: {$php_version}\n");
119
		
120
        return $ret;
121
    }
122
123
    /*
124
    *  @private function getHeadDatabaseTable
125
    *  @param $moduleDirname
126
    *  @param $tableName
127
    *  @param integer $fieldsNumb
128
    *
129
    *  Unused IF NOT EXISTS
130
    *  @return string
131
    */
132
    private function getHeadDatabaseTable($moduleDirname, $tableName, $fieldsNumb)
133
    {
134
        $ret = $this->getSimpleString('#');
135
		$ret .= $this->getSimpleString("# Structure table for `{$moduleDirname}_{$tableName}` {$fieldsNumb}");
136
		$ret .= $this->getSimpleString('#');
137
		$ret .= $this->getSimpleString("\nCREATE TABLE `{$moduleDirname}_{$tableName}` (");
138
		
139
        return $ret;
140
    }
141
142
    /*
143
    *  @private function getDatabaseTables
144
    *  @param $moduleDirname
145
    *  @return null|string
146
    */
147
    private function getDatabaseTables($moduleDirname)
148
    {
149
        $ret = null;
150
        $tables = $this->getTables();
151
        foreach (array_keys($tables) as $t) {
152
            $tableId = $tables[$t]->getVar('table_id');
153
            $tableMid = $tables[$t]->getVar('table_mid');
154
            $tableName = $tables[$t]->getVar('table_name');
155
            $tableAutoincrement = $tables[$t]->getVar('table_autoincrement');
156
            $fieldsNumb = $tables[$t]->getVar('table_nbfields');
157
            $ret .= $this->getDatabaseFields($moduleDirname, $tableMid, $tableId, $tableName, $tableAutoincrement, $fieldsNumb);
158
        }
159
160
        return $ret;
161
    }
162
163
    /*
164
    *  @private function getDatabaseFields
165
    *  @param $moduleDirname
166
    *  @param $tableName
167
    *  @param $tableAutoincrement
168
    *  @param $fieldsNumb
169
    *  @return null|string
170
    */
171
    private function getDatabaseFields($moduleDirname, $tableMid, $tableId, $tableName, $tableAutoincrement, $fieldsNumb)
172
    {
173
        $ret = null;
174
        $j = 0;
175
        $comma = array();
176
        $row = array();
177
        $type = '';
0 ignored issues
show
Unused Code introduced by
$type 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...
178
        $fields = $this->getTableFields($tableMid, $tableId, 'field_id ASC, field_name');
179
        foreach (array_keys($fields) as $f) {
180
            // Creation of database table
181
            $ret = $this->getHeadDatabaseTable($moduleDirname, $tableName, $fieldsNumb);
182
            $fieldName = $fields[$f]->getVar('field_name');
183
            $fieldType = $fields[$f]->getVar('field_type');
184
            $fieldValue = $fields[$f]->getVar('field_value');
185
            $fieldAttribute = $fields[$f]->getVar('field_attribute');
186
            $fieldNull = $fields[$f]->getVar('field_null');
187
            $fieldDefault = $fields[$f]->getVar('field_default');
188
            $fieldKey = $fields[$f]->getVar('field_key');
189
            if ($fieldType > 1) {
190
                $fType = $this->tdmcreate->getHandler('fieldtype')->get($fieldType);
0 ignored issues
show
Bug introduced by
The method getHandler cannot be called on $this->tdmcreate (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
191
                $fieldTypeName = $fType->getVar('fieldtype_name');
192
            } else {
193
                $fieldType = null;
194
            }
195
            if ($fieldAttribute > 1) {
196
                $fAttribute = $this->tdmcreate->getHandler('fieldattributes')->get($fieldAttribute);
0 ignored issues
show
Bug introduced by
The method getHandler cannot be called on $this->tdmcreate (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
197
                $fieldAttribute = $fAttribute->getVar('fieldattribute_name');
198
            } else {
199
                $fieldAttribute = null;
200
            }
201
            if ($fieldNull > 1) {
202
                $fNull = $this->tdmcreate->getHandler('fieldnull')->get($fieldNull);
0 ignored issues
show
Bug introduced by
The method getHandler cannot be called on $this->tdmcreate (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
203
                $fieldNull = $fNull->getVar('fieldnull_name');
204
            } else {
205
                $fieldNull = null;
206
            }
207
            if (!empty($fieldName)) {
208
                switch ($fieldType) {
209
                    case 2:
210
                    case 3:
211
                    case 4:
212
                    case 5:
213
                        $type = $fieldTypeName.'('.$fieldValue.')';
0 ignored issues
show
Bug introduced by
The variable $fieldTypeName 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...
214
                        if (empty($fieldDefault)) {
215
                            $default = "DEFAULT '0'";
216
                        } else {
217
                            $default = "DEFAULT '{$fieldDefault}'";
218
                        }
219
                        break;
220
                    case 6:
221
                    case 7:
222
                    case 8:
223
                        $type = $fieldTypeName.'('.$fieldValue.')';
224
                        if (empty($fieldDefault)) {
225
                            $default = "DEFAULT '0.00'"; // From MySQL 5.7 Manual
226
                        } else {
227
                            $default = "DEFAULT '{$fieldDefault}'";
228
                        }
229
                        break;
230
                    case 9:
231
                    case 10:
232
                        $type = $fieldTypeName;
233
                        break;
234
                    case 11:
235
                        $type = $fieldTypeName.'('.$fieldValue.')';
236
                        if (empty($fieldDefault)) {
237
                            $default = "DEFAULT '[email protected]'";
238
                        } else {
239
                            $default = "DEFAULT '{$fieldDefault}'";
240
                        }
241
                        break;
242
                    case 12:
243
                        $type = $fieldTypeName.'('.$fieldValue.')';
244
                        if (empty($fieldDefault)) {
245
                            $default = "DEFAULT 'http:\\'";
246
                        } else {
247
                            $default = "DEFAULT '{$fieldDefault}'";
248
                        }
249
                        break;
250
                    case 13:
251
                    case 14:
252
                        $type = $fieldTypeName.'('.$fieldValue.')';
253
                        $default = "DEFAULT '{$fieldDefault}'";
254
                        break;
255
                    case 15:
256
                    case 16:
257
                    case 17:
258
                    case 18:
259
                        $type = $fieldTypeName;
260
                        $default = null;
261
                        break;
262
                    case 19:
263
                    case 20:
264
                    case 21:
265
                    case 22:
266
                        $type = $fieldTypeName.'('.$fieldValue.')';
267
                        $default = "DEFAULT '{$fieldDefault}'";
268
                        break;
269
                    case 23:
270
                        $type = $fieldTypeName;
271
                        if (empty($fieldDefault)) {
272
                            $default = "DEFAULT '1970'"; // From MySQL 5.7 Manual
273
                        } else {
274
                            $default = "DEFAULT '{$fieldDefault}'";
275
                        }
276
                        break;
277
                    default:
278
                        $type = $fieldTypeName.'('.$fieldValue.')';
279
                        $default = "DEFAULT '{$fieldDefault}'";
280
                        break;
281
                }
282
                if ((0 == $f) && (1 == $tableAutoincrement)) {
283
                    $row[] = $this->getFieldRow($fieldName, $type, $fieldAttribute, $fieldNull, null, 'AUTO_INCREMENT');
284
                    $comma[$j] = $this->getKey(2, $fieldName);
285
                    ++$j;
286
                } elseif ((0 == $f) && (0 == $tableAutoincrement)) {
287
                    $row[] = $this->getFieldRow($fieldName, $type, $fieldAttribute, $fieldNull, $default);
0 ignored issues
show
Bug introduced by
The variable $default 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...
288
                    $comma[$j] = $this->getKey(2, $fieldName);
289
                    ++$j;
290
                } else {
291
                    if (3 == $fieldKey || 4 == $fieldKey || 5 == $fieldKey || 6 == $fieldKey) {
292
                        switch ($fieldKey) {
293
                            case 3:
294
                                $row[] = $this->getFieldRow($fieldName, $type, $fieldAttribute, $fieldNull, $default);
295
                                $comma[$j] = $this->getKey(3, $fieldName);
296
                                ++$j;
297
                                break;
298
                            case 4:
299
                                $row[] = $this->getFieldRow($fieldName, $type, $fieldAttribute, $fieldNull, $default);
300
                                $comma[$j] = $this->getKey(4, $fieldName);
301
                                ++$j;
302
                                break;
303
                            case 5:
304
                                $row[] = $this->getFieldRow($fieldName, $type, $fieldAttribute, $fieldNull, $default);
305
                                $comma[$j] = $this->getKey(5, $fieldName);
306
                                ++$j;
307
                                break;
308
                            case 6:
309
                                $row[] = $this->getFieldRow($fieldName, $type, $fieldAttribute, $fieldNull, $default);
310
                                $comma[$j] = $this->getKey(6, $fieldName);
311
                                ++$j;
312
                                break;
313
                        }
314
                    } else {
315
                        $row[] = $this->getFieldRow($fieldName, $type, $fieldAttribute, $fieldNull, $default);
316
                    }
317
                }
318
            }
319
        }
320
        // ================= COMMA ================= //
321
        for ($i = 0; $i < $j; ++$i) {
322
            if ($i != $j - 1) {
323
                $row[] = $comma[$i].',';
324
            } else {
325
                $row[] = $comma[$i];
326
            }
327
        }
328
        // ================= COMMA CICLE ================= //
329
        $ret .= implode("\n", $row);
330
        unset($j);
331
        $ret .= $this->getFootDatabaseTable();
332
333
        return $ret;
334
    }
335
336
    /*
337
    *  @private function getFootDatabaseTable
338
    *  @param null
339
    */
340
    /**
341
     * @return string
342
     */
343
    private function getFootDatabaseTable()
344
    {
345
        return "\n) ENGINE=InnoDB;\n\n";
346
    }
347
348
    /*
349
    *  @private function getFieldRow
350
    *  @param $fieldName
351
    *  @param $fieldTypeValue
352
    *  @param $fieldAttribute
353
    *  @param $fieldNull
354
    *  @param $fieldDefault
355
    *  @param $autoincrement
356
    *  @return string
357
    */
358
    private function getFieldRow($fieldName, $fieldTypeValue, $fieldAttribute = null, $fieldNull = null, $fieldDefault = null, $autoincrement = null)
359
    {
360
        $retAutoincrement = "  `{$fieldName}` {$fieldTypeValue} {$fieldAttribute} {$fieldNull} {$autoincrement},";
361
        $retFieldAttribute = "  `{$fieldName}` {$fieldTypeValue} {$fieldAttribute} {$fieldNull} {$fieldDefault},";
362
        $fieldDefault = "  `{$fieldName}` {$fieldTypeValue} {$fieldNull} {$fieldDefault},";
363
        $retShort = "  `{$fieldName}` {$fieldTypeValue},";
364
365
        $ret = $retShort;
366
        if ($autoincrement != null) {
367
            $ret = $retAutoincrement;
368
        } elseif ($fieldAttribute != null) {
369
            $ret = $retFieldAttribute;
370
        } elseif ($fieldAttribute == null) {
371
            $ret = $fieldDefault;
372
        }
373
374
        return $ret;
375
    }
376
377
    /*
378
    *  @private function getKey
379
    *  @return string
380
    */
381
    private function getKey($key, $fieldName)
382
    {
383
        switch ($key) {
384
            case 2: // PRIMARY KEY
385
                $ret = "  PRIMARY KEY (`{$fieldName}`)";
386
                break;
387
            case 3: // UNIQUE KEY
388
                $ret = "  UNIQUE KEY `{$fieldName}` (`{$fieldName}`)";
389
                break;
390
            case 4: // KEY
391
                $ret = "  KEY `{$fieldName}` (`{$fieldName}`)";
392
                break;
393
            case 5: // INDEX
394
                $ret = "  INDEX (`{$fieldName}`)";
395
                break;
396
            case 6: // FULLTEXT KEY
397
                $ret = "  FULLTEXT KEY `{$fieldName}` (`{$fieldName}`)";
398
                break;
399
        }
400
401
        return $ret;
0 ignored issues
show
Bug introduced by
The variable $ret does not seem to be defined for all execution paths leading up to this point.

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
402
    }
403
404
    /*
405
    *  @private function getComma
406
    *  @param $row
407
    *  @param $comma
408
    *  @return string
409
    */
410
    private function getComma($row, $comma = null)
411
    {
412
		return "\t\t\t{$row}{$comma}";
413
    }
414
415
    /*
416
    *  @private function getCommaCicle
417
    *  @param $comma
418
    *  @param $index
419
    *  @return string
420
    */
421
    private function getCommaCicle($comma, $index)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
422
    {
423
        // Comma issue
424
        for ($i = 1; $i <= $index; ++$i) {
425
            if ($i != $index - 1) {
426
                $ret = $this->getComma(isset($comma[$i]), ',')."\n";
427
            } else {
428
                $ret = $this->getComma(isset($comma[$i]))."\n";
429
            }
430
        }
431
432
        return $ret;
0 ignored issues
show
Bug introduced by
The variable $ret does not seem to be defined for all execution paths leading up to this point.

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
433
    }
434
435
    /*
436
    *  @public function render
437
    *  @param null
438
    *  @return bool|string
439
    */
440
    public function render()
441
    {
442
        $module = $this->getModule();
443
        $filename = $this->getFileName();
444
        $moduleName = strtolower($module->getVar('mod_name'));
445
        $moduleDirname = strtolower($module->getVar('mod_dirname'));
446
        $content = $this->getHeaderSqlComments($moduleName);
447
        $content      .= $this->getDatabaseTables($moduleDirname);
448
        //
449
        $this->tdmcfile->create($moduleDirname, 'sql', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
0 ignored issues
show
Bug introduced by
The method create cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
450
451
        return $this->tdmcfile->renderFile();
0 ignored issues
show
Bug introduced by
The method renderFile cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
452
    }
453
}
454