| Conditions | 37 |
| Paths | 96 |
| Total Lines | 106 |
| Code Lines | 72 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 79 | protected function recreateTable(string $table, string $name, array $fields, array $originals, |
||
| 80 | array $foreign, int $autoIncrement, array $indexes = []) |
||
| 81 | { |
||
| 82 | if ($table != "") { |
||
| 83 | if (empty($fields)) { |
||
| 84 | foreach ($this->driver->fields($table) as $key => $field) { |
||
| 85 | if (!empty($indexes)) { |
||
| 86 | $field->autoIncrement = 0; |
||
| 87 | } |
||
| 88 | $fields[] = $this->util->processField($field, $field); |
||
| 89 | $originals[$key] = $this->driver->escapeId($key); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | $primary_key = false; |
||
| 93 | foreach ($fields as $field) { |
||
| 94 | if ($field[6]) { |
||
| 95 | $primary_key = true; |
||
| 96 | } |
||
| 97 | } |
||
| 98 | $drop_indexes = []; |
||
| 99 | foreach ($indexes as $key => $val) { |
||
| 100 | if ($val[2] == "DROP") { |
||
| 101 | $drop_indexes[$val[1]] = true; |
||
| 102 | unset($indexes[$key]); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | foreach ($this->driver->indexes($table) as $key_name => $index) { |
||
| 106 | $columns = []; |
||
| 107 | foreach ($index->columns as $key => $column) { |
||
| 108 | if (!$originals[$column]) { |
||
| 109 | continue 2; |
||
| 110 | } |
||
| 111 | $columns[] = $originals[$column] . ($index->descs[$key] ? " DESC" : ""); |
||
| 112 | } |
||
| 113 | if (!$drop_indexes[$key_name]) { |
||
| 114 | if ($index->type != "PRIMARY" || !$primary_key) { |
||
| 115 | $indexes[] = [$index->type, $key_name, $columns]; |
||
| 116 | } |
||
| 117 | } |
||
| 118 | } |
||
| 119 | foreach ($indexes as $key => $val) { |
||
| 120 | if ($val[0] == "PRIMARY") { |
||
| 121 | unset($indexes[$key]); |
||
| 122 | $foreign[] = " PRIMARY KEY (" . implode(", ", $val[2]) . ")"; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | foreach ($this->driver->foreignKeys($table) as $key_name => $foreignKey) { |
||
| 126 | foreach ($foreignKey->source as $key => $column) { |
||
| 127 | if (!$originals[$column]) { |
||
| 128 | continue 2; |
||
| 129 | } |
||
| 130 | $foreignKey->source[$key] = $this->driver->unescapeId($originals[$column]); |
||
| 131 | } |
||
| 132 | if (!isset($foreign[" $key_name"])) { |
||
| 133 | $foreign[] = " " . $this->driver->formatForeignKey($foreignKey); |
||
| 134 | } |
||
| 135 | } |
||
| 136 | $this->driver->execute("BEGIN"); |
||
| 137 | } |
||
| 138 | foreach ($fields as $key => $field) { |
||
| 139 | $fields[$key] = " " . implode($field); |
||
| 140 | } |
||
| 141 | $fields = array_merge($fields, array_filter($foreign)); |
||
| 142 | $tempName = ($table == $name ? "adminer_$name" : $name); |
||
| 143 | if (!$this->driver->execute("CREATE TABLE " . $this->driver->table($tempName) . |
||
| 144 | " (\n" . implode(",\n", $fields) . "\n)")) { |
||
| 145 | // implicit ROLLBACK to not overwrite $this->driver->error() |
||
| 146 | return false; |
||
| 147 | } |
||
| 148 | if ($table != "") { |
||
| 149 | if ($originals && !$this->driver->execute("INSERT INTO " . $this->driver->table($tempName) . |
||
| 150 | " (" . implode(", ", $originals) . ") SELECT " . implode( |
||
| 151 | ", ", |
||
| 152 | array_map(function ($key) { |
||
| 153 | return $this->driver->escapeId($key); |
||
| 154 | }, array_keys($originals)) |
||
| 155 | ) . " FROM " . $this->driver->table($table))) { |
||
| 156 | return false; |
||
| 157 | } |
||
| 158 | $triggers = []; |
||
| 159 | foreach ($this->driver->triggers($table) as $trigger_name => $timing_event) { |
||
| 160 | $trigger = $this->trigger($trigger_name); |
||
|
|
|||
| 161 | $triggers[] = "CREATE TRIGGER " . $this->driver->escapeId($trigger_name) . " " . |
||
| 162 | implode(" ", $timing_event) . " ON " . $this->driver->table($name) . "\n$trigger[Statement]"; |
||
| 163 | } |
||
| 164 | $autoIncrement = $autoIncrement ? 0 : |
||
| 165 | $this->connection->result("SELECT seq FROM sqlite_sequence WHERE name = " . |
||
| 166 | $this->driver->quote($table)); // if $autoIncrement is set then it will be updated later |
||
| 167 | // drop before creating indexes and triggers to allow using old names |
||
| 168 | if (!$this->driver->execute("DROP TABLE " . $this->driver->table($table)) || |
||
| 169 | ($table == $name && !$this->driver->execute("ALTER TABLE " . $this->driver->table($tempName) . |
||
| 170 | " RENAME TO " . $this->driver->table($name))) || !$this->alterIndexes($name, $indexes) |
||
| 171 | ) { |
||
| 172 | return false; |
||
| 173 | } |
||
| 174 | if ($autoIncrement) { |
||
| 175 | $this->driver->execute("UPDATE sqlite_sequence SET seq = $autoIncrement WHERE name = " . $this->driver->quote($name)); // ignores error |
||
| 176 | } |
||
| 177 | foreach ($triggers as $trigger) { |
||
| 178 | if (!$this->driver->execute($trigger)) { |
||
| 179 | return false; |
||
| 180 | } |
||
| 181 | } |
||
| 182 | $this->driver->execute("COMMIT"); |
||
| 183 | } |
||
| 184 | return true; |
||
| 185 | } |
||
| 268 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.