Conditions | 20 |
Paths | 98 |
Total Lines | 108 |
Code Lines | 64 |
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 |
||
109 | public function indexAction() |
||
110 | { |
||
111 | global $route; |
||
112 | |||
113 | // Send table of column names to populate corresponding dropdowns depending |
||
114 | // on the current selection |
||
115 | if (isset($_POST['getDropdownValues']) |
||
116 | && $_POST['getDropdownValues'] === 'true' |
||
117 | ) { |
||
118 | // if both db and table are selected |
||
119 | if (isset($_POST['foreignTable'])) { |
||
120 | $this->getDropdownValueForTableAction(); |
||
121 | } else { // if only the db is selected |
||
122 | $this->getDropdownValueForDbAction(); |
||
123 | } |
||
124 | return; |
||
125 | } |
||
126 | |||
127 | $this->response->getHeader()->getScripts()->addFiles( |
||
128 | [ |
||
129 | 'table/relation.js', |
||
130 | 'indexes.js', |
||
131 | ] |
||
132 | ); |
||
133 | |||
134 | // Set the database |
||
135 | $this->dbi->selectDb($this->db); |
||
136 | |||
137 | // updates for Internal relations |
||
138 | if (isset($_POST['destination_db']) && $this->cfgRelation['relwork']) { |
||
139 | $this->updateForInternalRelationAction(); |
||
140 | } |
||
141 | |||
142 | // updates for foreign keys |
||
143 | $this->updateForForeignKeysAction(); |
||
144 | |||
145 | // Updates for display field |
||
146 | if ($this->cfgRelation['displaywork'] && isset($_POST['display_field'])) { |
||
147 | $this->updateForDisplayField(); |
||
148 | } |
||
149 | |||
150 | // If we did an update, refresh our data |
||
151 | if (isset($_POST['destination_db']) && $this->cfgRelation['relwork']) { |
||
152 | $this->existrel = $this->relation->getForeigners( |
||
153 | $this->db, |
||
154 | $this->table, |
||
155 | '', |
||
156 | 'internal' |
||
157 | ); |
||
158 | } |
||
159 | if (isset($_POST['destination_foreign_db']) |
||
160 | && Util::isForeignKeySupported($this->tbl_storage_engine) |
||
161 | ) { |
||
162 | $this->existrel_foreign = $this->relation->getForeigners( |
||
163 | $this->db, |
||
164 | $this->table, |
||
165 | '', |
||
166 | 'foreign' |
||
167 | ); |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * Dialog |
||
172 | */ |
||
173 | // Now find out the columns of our $table |
||
174 | // need to use DatabaseInterface::QUERY_STORE with $this->dbi->numRows() |
||
175 | // in mysqli |
||
176 | $columns = $this->dbi->getColumns($this->db, $this->table); |
||
177 | |||
178 | $column_array = []; |
||
179 | $column_hash_array = []; |
||
180 | $column_array[''] = ''; |
||
181 | foreach ($columns as $column) { |
||
182 | if (strtoupper($this->tbl_storage_engine) == 'INNODB' |
||
183 | || ! empty($column['Key']) |
||
184 | ) { |
||
185 | $column_array[$column['Field']] = $column['Field']; |
||
186 | $column_hash_array[$column['Field']] = md5($column['Field']); |
||
187 | } |
||
188 | } |
||
189 | if ($GLOBALS['cfg']['NaturalOrder']) { |
||
190 | uksort($column_array, 'strnatcasecmp'); |
||
191 | } |
||
192 | |||
193 | // common form |
||
194 | $engine = $this->dbi->getTable($this->db, $this->table)->getStorageEngine(); |
||
195 | $foreignKeySupported = Util::isForeignKeySupported($this->tbl_storage_engine); |
||
196 | $this->response->addHTML( |
||
197 | $this->template->render('table/relation/common_form', [ |
||
198 | 'is_foreign_key_supported' => Util::isForeignKeySupported($engine), |
||
199 | 'db' => $this->db, |
||
200 | 'table' => $this->table, |
||
201 | 'cfg_relation' => $this->cfgRelation, |
||
202 | 'tbl_storage_engine' => $this->tbl_storage_engine, |
||
203 | 'existrel' => isset($this->existrel) ? $this->existrel : [], |
||
204 | 'existrel_foreign' => is_array($this->existrel_foreign) && array_key_exists('foreign_keys_data', $this->existrel_foreign) |
||
205 | ? $this->existrel_foreign['foreign_keys_data'] : [], |
||
206 | 'options_array' => $this->options_array, |
||
207 | 'column_array' => $column_array, |
||
208 | 'column_hash_array' => $column_hash_array, |
||
209 | 'save_row' => array_values($columns), |
||
210 | 'url_params' => $GLOBALS['url_params'], |
||
211 | 'databases' => $GLOBALS['dblist']->databases, |
||
212 | 'dbi' => $this->dbi, |
||
213 | 'default_sliders_state' => $GLOBALS['cfg']['InitialSlidersState'], |
||
214 | 'foreignKeySupported' => $foreignKeySupported, |
||
215 | 'displayIndexesHtml' => $foreignKeySupported ? Index::getHtmlForDisplayIndexes() : null, |
||
216 | 'route' => $route, |
||
217 | ]) |
||
402 |