| Conditions | 20 |
| Paths | 20 |
| Total Lines | 67 |
| Code Lines | 45 |
| Lines | 32 |
| Ratio | 47.76 % |
| 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 |
||
| 81 | public function queryFromFile($sql_file_path) |
||
| 82 | { |
||
| 83 | global $pieces; |
||
| 84 | $tables = array(); |
||
| 85 | |||
| 86 | if (!file_exists($sql_file_path)) { |
||
| 87 | return false; |
||
| 88 | } |
||
| 89 | $sql_query = trim(fread(fopen($sql_file_path, 'r'), filesize($sql_file_path))); |
||
| 90 | SqlUtility::splitMySqlFile($pieces, $sql_query); |
||
| 91 | $this->db->connect(); |
||
| 92 | foreach ($pieces as $piece) { |
||
| 93 | $piece = trim($piece); |
||
| 94 | // [0] contains the prefixed query |
||
| 95 | // [4] contains unprefixed table name |
||
| 96 | $prefixed_query = SqlUtility::prefixQuery($piece, $this->db->prefix()); |
||
| 97 | if ($prefixed_query !== false) { |
||
| 98 | $table = $this->db->prefix($prefixed_query[4]); |
||
| 99 | if ($prefixed_query[1] === 'CREATE TABLE') { |
||
| 100 | View Code Duplication | if ($this->db->query($prefixed_query[0]) !== false) { |
|
| 101 | if (!isset($this->s_tables['create'][$table])) { |
||
| 102 | $this->s_tables['create'][$table] = 1; |
||
| 103 | } |
||
| 104 | } else { |
||
| 105 | if (!isset($this->f_tables['create'][$table])) { |
||
| 106 | $this->f_tables['create'][$table] = 1; |
||
| 107 | } |
||
| 108 | } |
||
| 109 | } elseif ($prefixed_query[1] === 'INSERT INTO') { |
||
| 110 | if ($this->db->query($prefixed_query[0]) !== false) { |
||
| 111 | View Code Duplication | if (!isset($this->s_tables['insert'][$table])) { |
|
| 112 | $this->s_tables['insert'][$table] = 1; |
||
| 113 | } else { |
||
| 114 | $this->s_tables['insert'][$table]++; |
||
| 115 | } |
||
| 116 | View Code Duplication | } else { |
|
| 117 | if (!isset($this->f_tables['insert'][$table])) { |
||
| 118 | $this->f_tables['insert'][$table] = 1; |
||
| 119 | } else { |
||
| 120 | $this->f_tables['insert'][$table]++; |
||
| 121 | } |
||
| 122 | } |
||
| 123 | View Code Duplication | } elseif ($prefixed_query[1] === 'ALTER TABLE') { |
|
| 124 | if ($this->db->query($prefixed_query[0]) !== false) { |
||
| 125 | if (!isset($this->s_tables['alter'][$table])) { |
||
| 126 | $this->s_tables['alter'][$table] = 1; |
||
| 127 | } |
||
| 128 | } else { |
||
| 129 | if (!isset($this->s_tables['alter'][$table])) { |
||
| 130 | $this->f_tables['alter'][$table] = 1; |
||
| 131 | } |
||
| 132 | } |
||
| 133 | } elseif ($prefixed_query[1] === 'DROP TABLE') { |
||
| 134 | if ($this->db->query('DROP TABLE ' . $table) !== false) { |
||
| 135 | if (!isset($this->s_tables['drop'][$table])) { |
||
| 136 | $this->s_tables['drop'][$table] = 1; |
||
| 137 | } |
||
| 138 | } else { |
||
| 139 | if (!isset($this->s_tables['drop'][$table])) { |
||
| 140 | $this->f_tables['drop'][$table] = 1; |
||
| 141 | } |
||
| 142 | } |
||
| 143 | } |
||
| 144 | } |
||
| 145 | } |
||
| 146 | |||
| 147 | return true; |
||
| 148 | } |
||
| 307 |