Conditions | 7 |
Paths | 20 |
Total Lines | 59 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 2 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
76 | public function backup_data($exclude=array(), $system_tables=FALSE) |
||
77 | { |
||
78 | // Determine which tables to use |
||
79 | $tables = $this->get_driver()->get_tables(); |
||
80 | if($system_tables == TRUE) |
||
81 | { |
||
82 | $tables = array_merge($tables, $this->get_driver()->get_system_tables()); |
||
83 | } |
||
84 | |||
85 | // Filter out the tables you don't want |
||
86 | if( ! empty($exclude)) |
||
87 | { |
||
88 | $tables = array_diff($tables, $exclude); |
||
89 | } |
||
90 | |||
91 | $output_sql = ''; |
||
92 | |||
93 | // Get the data for each object |
||
94 | foreach($tables as $t) |
||
95 | { |
||
96 | $sql = 'SELECT * FROM "'.trim($t).'"'; |
||
97 | $res = $this->get_driver()->query($sql); |
||
98 | $obj_res = $res->fetchAll(\PDO::FETCH_ASSOC); |
||
99 | |||
100 | // Don't add to the file if the table is empty |
||
101 | if (count($obj_res) < 1) |
||
102 | { |
||
103 | continue; |
||
104 | } |
||
105 | |||
106 | // Nab the column names by getting the keys of the first row |
||
107 | $columns = @array_keys($obj_res[0]); |
||
108 | |||
109 | $insert_rows = array(); |
||
110 | |||
111 | // Create the insert statements |
||
112 | foreach($obj_res as $row) |
||
113 | { |
||
114 | $row = array_values($row); |
||
115 | |||
116 | // Quote values as needed by type |
||
117 | if(stripos($t, 'RDB$') === FALSE) |
||
118 | { |
||
119 | $row = array_map(array($this->get_driver(), 'quote'), $row); |
||
120 | $row = array_map('trim', $row); |
||
121 | } |
||
122 | |||
123 | $row_string = 'INSERT INTO "'.trim($t).'" ("'.implode('","', $columns).'") VALUES ('.implode(',', $row).');'; |
||
124 | |||
125 | $row = NULL; |
||
126 | |||
127 | $insert_rows[] = $row_string; |
||
128 | } |
||
129 | |||
130 | $output_sql .= "\n\nSET TRANSACTION;\n".implode("\n", $insert_rows)."\nCOMMIT;"; |
||
131 | } |
||
132 | |||
133 | return $output_sql; |
||
134 | } |
||
135 | } |
||
136 | // End of firebird_util.php |