| Conditions | 18 |
| Paths | 2592 |
| Total Lines | 111 |
| Code Lines | 82 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 namespace EvolutionCMS\Support; |
||
| 69 | public function createDump($callBack) |
||
| 70 | { |
||
| 71 | $modx = evolutionCMS(); |
||
| 72 | $createtable = array(); |
||
| 73 | |||
| 74 | // Set line feed |
||
| 75 | $lf = "\n"; |
||
| 76 | $tempfile_path = $modx->config['base_path'] . 'assets/backup/temp.php'; |
||
| 77 | |||
| 78 | $result = $modx->db->query('SHOW TABLES'); |
||
| 79 | $tables = $this->result2Array(0, $result); |
||
| 80 | foreach ($tables as $tblval) { |
||
| 81 | $result = $modx->db->query("SHOW CREATE TABLE `{$tblval}`"); |
||
| 82 | $createtable[$tblval] = $this->result2Array(1, $result); |
||
| 83 | } |
||
| 84 | |||
| 85 | $version = $modx->getVersionData(); |
||
| 86 | |||
| 87 | // Set header |
||
| 88 | $output = "#{$lf}"; |
||
| 89 | $output .= "# " . addslashes($modx->config['site_name']) . " Database Dump{$lf}"; |
||
| 90 | $output .= "# MODX Version:{$version['version']}{$lf}"; |
||
| 91 | $output .= "# {$lf}"; |
||
| 92 | $output .= "# Host: {$this->database_server}{$lf}"; |
||
| 93 | $output .= "# Generation Time: " . $modx->toDateFormat(time()) . $lf; |
||
| 94 | $output .= "# Server version: " . $modx->db->getVersion() . $lf; |
||
| 95 | $output .= "# PHP Version: " . phpversion() . $lf; |
||
| 96 | $output .= "# Database: `{$this->dbname}`{$lf}"; |
||
| 97 | $output .= "# Description: " . trim($_REQUEST['backup_title']) . "{$lf}"; |
||
| 98 | $output .= "#"; |
||
| 99 | file_put_contents($tempfile_path, $output, FILE_APPEND | LOCK_EX); |
||
| 100 | $output = ''; |
||
| 101 | |||
| 102 | // Generate dumptext for the tables. |
||
| 103 | if (isset($this->_dbtables) && count($this->_dbtables)) { |
||
| 104 | $this->_dbtables = implode(',', $this->_dbtables); |
||
| 105 | } else { |
||
| 106 | unset($this->_dbtables); |
||
| 107 | } |
||
| 108 | foreach ($tables as $tblval) { |
||
| 109 | // check for selected table |
||
| 110 | if (isset($this->_dbtables)) { |
||
| 111 | if (strstr(",{$this->_dbtables},", ",{$tblval},") === false) { |
||
| 112 | continue; |
||
| 113 | } |
||
| 114 | } |
||
| 115 | if ($callBack === 'snapshot') { |
||
| 116 | if (!preg_match('@^' . $modx->db->config['table_prefix'] . '@', $tblval)) { |
||
| 117 | continue; |
||
| 118 | } |
||
| 119 | } |
||
| 120 | $output .= "{$lf}{$lf}# --------------------------------------------------------{$lf}{$lf}"; |
||
| 121 | $output .= "#{$lf}# Table structure for table `{$tblval}`{$lf}"; |
||
| 122 | $output .= "#{$lf}{$lf}"; |
||
| 123 | // Generate DROP TABLE statement when client wants it to. |
||
| 124 | if ($this->isDroptables()) { |
||
| 125 | $output .= "SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;{$lf}"; |
||
| 126 | $output .= "DROP TABLE IF EXISTS `{$tblval}`;{$lf}"; |
||
| 127 | $output .= "SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;{$lf}{$lf}"; |
||
| 128 | } |
||
| 129 | $output .= "{$createtable[$tblval][0]};{$lf}"; |
||
| 130 | $output .= $lf; |
||
| 131 | $output .= "#{$lf}# Dumping data for table `{$tblval}`{$lf}#{$lf}"; |
||
| 132 | $result = $modx->db->select('*', $tblval); |
||
| 133 | $rows = $this->loadObjectList('', $result); |
||
| 134 | foreach ($rows as $row) { |
||
| 135 | $insertdump = $lf; |
||
| 136 | $insertdump .= "INSERT INTO `{$tblval}` VALUES ("; |
||
| 137 | $arr = $this->object2Array($row); |
||
| 138 | if (!is_array($arr)) { |
||
| 139 | $arr = array(); |
||
| 140 | } |
||
| 141 | foreach ($arr as $key => $value) { |
||
| 142 | if (is_null($value)) { |
||
| 143 | $value = 'NULL'; |
||
| 144 | } else { |
||
| 145 | $value = addslashes($value); |
||
| 146 | $value = str_replace(array( |
||
| 147 | "\r\n", |
||
| 148 | "\r", |
||
| 149 | "\n" |
||
| 150 | ), '\\n', $value); |
||
| 151 | $value = "'{$value}'"; |
||
| 152 | } |
||
| 153 | $insertdump .= $value . ','; |
||
| 154 | } |
||
| 155 | $output .= rtrim($insertdump, ',') . ");\n"; |
||
| 156 | if (1048576 < strlen($output)) { |
||
| 157 | file_put_contents($tempfile_path, $output, FILE_APPEND | LOCK_EX); |
||
| 158 | $output = ''; |
||
| 159 | } |
||
| 160 | } |
||
| 161 | file_put_contents($tempfile_path, $output, FILE_APPEND | LOCK_EX); |
||
| 162 | $output = ''; |
||
| 163 | } |
||
| 164 | $output = file_get_contents($tempfile_path); |
||
| 165 | if (!empty($output)) { |
||
| 166 | unlink($tempfile_path); |
||
| 167 | } |
||
| 168 | |||
| 169 | switch ($callBack) { |
||
| 170 | case 'dumpSql': |
||
| 171 | dumpSql($output); |
||
| 172 | break; |
||
| 173 | case 'snapshot': |
||
| 174 | snapshot($output); |
||
| 175 | break; |
||
| 176 | } |
||
| 177 | |||
| 178 | return true; |
||
| 179 | } |
||
| 180 | |||
| 248 |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.