Conditions | 18 |
Paths | 6075 |
Total Lines | 182 |
Code Lines | 94 |
Lines | 40 |
Ratio | 21.98 % |
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 |
||
147 | public function down() { |
||
148 | |||
149 | if ($this->hasTable('access_collections')) { |
||
150 | |||
151 | $table = $this->table('access_collections'); |
||
152 | |||
153 | View Code Duplication | if (!$table->hasColumn('site_guid')) { |
|
1 ignored issue
–
show
|
|||
154 | $table->addColumn('site_guid', 'integer', [ |
||
155 | 'null' => false, |
||
156 | 'limit' => MysqlAdapter::INT_BIG, |
||
157 | 'precision' => 20, |
||
158 | 'signed' => false, |
||
159 | ]); |
||
160 | } |
||
161 | |||
162 | if (!$table->hasIndex('site_guid')) { |
||
163 | $table->addIndex(['site_guid'], [ |
||
164 | 'name' => 'site_guid', |
||
165 | 'unique' => false, |
||
166 | ]); |
||
167 | } |
||
168 | |||
169 | $table->save(); |
||
170 | |||
171 | $prefix = $this->getAdapter()->getOption('table_prefix'); |
||
172 | $this->query(" |
||
173 | UPDATE {$prefix}access_collections |
||
174 | SET site_guid = 1 |
||
175 | WHERE site_guid != 1 |
||
176 | "); |
||
177 | |||
178 | } |
||
179 | |||
180 | if ($this->hasTable('api_users')) { |
||
181 | |||
182 | $table = $this->table('api_users'); |
||
183 | |||
184 | View Code Duplication | if (!$table->hasColumn('site_guid')) { |
|
1 ignored issue
–
show
|
|||
185 | $table->addColumn('site_guid', 'integer', [ |
||
186 | 'null' => false, |
||
187 | 'limit' => MysqlAdapter::INT_BIG, |
||
188 | 'precision' => 20, |
||
189 | 'signed' => false, |
||
190 | ]); |
||
191 | } |
||
192 | |||
193 | $table->save(); |
||
194 | |||
195 | $prefix = $this->getAdapter()->getOption('table_prefix'); |
||
196 | $this->query(" |
||
197 | UPDATE {$prefix}api_users |
||
198 | SET site_guid = 1 |
||
199 | WHERE site_guid != 1 |
||
200 | "); |
||
201 | |||
202 | } |
||
203 | |||
204 | if ($this->hasTable('config')) { |
||
205 | |||
206 | $table = $this->table('config', [ |
||
207 | 'primary_key' => [ |
||
208 | "name", |
||
209 | "site_guid" |
||
210 | ], |
||
211 | ]); |
||
212 | |||
213 | View Code Duplication | if (!$table->hasColumn('site_guid')) { |
|
1 ignored issue
–
show
|
|||
214 | $table->addColumn('site_guid', 'integer', [ |
||
215 | 'null' => false, |
||
216 | 'limit' => MysqlAdapter::INT_BIG, |
||
217 | 'precision' => 20, |
||
218 | 'signed' => false, |
||
219 | ]); |
||
220 | } |
||
221 | |||
222 | if (!$table->hasIndex('site_guid')) { |
||
223 | $table->addIndex(['site_guid'], [ |
||
224 | 'name' => 'site_guid', |
||
225 | 'unique' => false, |
||
226 | ]); |
||
227 | } |
||
228 | |||
229 | $table->save(); |
||
230 | |||
231 | $prefix = $this->getAdapter()->getOption('table_prefix'); |
||
232 | $this->query(" |
||
233 | UPDATE {$prefix}config |
||
234 | SET site_guid = 1 |
||
235 | WHERE site_guid != 1 |
||
236 | "); |
||
237 | |||
238 | } |
||
239 | |||
240 | if ($this->hasTable('entities')) { |
||
241 | |||
242 | // remove site guid from entities |
||
243 | $table = $this->table('entities'); |
||
244 | |||
245 | View Code Duplication | if (!$table->hasColumn('site_guid')) { |
|
1 ignored issue
–
show
|
|||
246 | $table->addColumn('site_guid', 'integer', [ |
||
247 | 'null' => false, |
||
248 | 'limit' => MysqlAdapter::INT_BIG, |
||
249 | 'precision' => 20, |
||
250 | 'signed' => false, |
||
251 | ]); |
||
252 | } |
||
253 | |||
254 | if (!$table->hasIndex('site_guid')) { |
||
255 | $table->addIndex(['site_guid'], [ |
||
256 | 'name' => 'site_guid', |
||
257 | 'unique' => false, |
||
258 | ]); |
||
259 | } |
||
260 | |||
261 | $table->save(); |
||
262 | |||
263 | $prefix = $this->getAdapter()->getOption('table_prefix'); |
||
264 | $this->query(" |
||
265 | UPDATE {$prefix}entities |
||
266 | SET site_guid = 1 |
||
267 | WHERE site_guid != 1 |
||
268 | "); |
||
269 | |||
270 | if ($this->hasTable('entity_relationships')) { |
||
271 | $rows = $this->fetchAll(" |
||
272 | SELECT guid FROM {$prefix}entities |
||
273 | WHERE type = 'user' |
||
274 | "); |
||
275 | |||
276 | foreach ($rows as $row) { |
||
277 | $this->insert('entity_relationships', [ |
||
278 | 'guid_one' => $row['guid'], |
||
279 | 'relationship' => 'member_of_site', |
||
280 | 'guid_two' => 1, |
||
281 | 'time_created' => time(), |
||
282 | ]); |
||
283 | } |
||
284 | } |
||
285 | } |
||
286 | |||
287 | if ($this->hasTable('users_apisessions')) { |
||
288 | |||
289 | // remove site guid from users_apisessions |
||
290 | $table = $this->table('users_apisessions'); |
||
291 | |||
292 | if ($table->hasIndex('site_guid')) { |
||
293 | $table->removeIndexByName('site_guid'); |
||
294 | } |
||
295 | |||
296 | View Code Duplication | if (!$table->hasColumn('site_guid')) { |
|
1 ignored issue
–
show
|
|||
297 | $table->addColumn('site_guid', 'integer', [ |
||
298 | 'null' => false, |
||
299 | 'limit' => MysqlAdapter::INT_BIG, |
||
300 | 'precision' => 20, |
||
301 | 'signed' => false, |
||
302 | ]); |
||
303 | } |
||
304 | |||
305 | if ($table->hasIndex('user_guid')) { |
||
306 | $table->removeIndexByName('user_guid'); |
||
307 | } |
||
308 | |||
309 | $table->addIndex([ |
||
310 | 'user_guid', |
||
311 | 'site_guid' |
||
312 | ], [ |
||
313 | 'name' => "user_guid", |
||
314 | 'unique' => true, |
||
315 | ]); |
||
316 | |||
317 | $table->save(); |
||
318 | |||
319 | $prefix = $this->getAdapter()->getOption('table_prefix'); |
||
320 | $this->query(" |
||
321 | UPDATE {$prefix}users_apisessions |
||
322 | SET site_guid = 1 |
||
323 | WHERE site_guid != 1 |
||
324 | "); |
||
325 | |||
326 | } |
||
327 | |||
328 | } |
||
329 | } |
||
330 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.