Conditions | 8 |
Paths | 128 |
Total Lines | 416 |
Lines | 60 |
Ratio | 14.42 % |
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 |
||
64 | public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
||
65 | /** @var ISchemaWrapper $schema */ |
||
66 | $schema = $schemaClosure(); |
||
67 | |||
68 | if (!$schema->hasTable('circle_circles')) { |
||
69 | $table = $schema->createTable('circle_circles'); |
||
70 | $table->addColumn( |
||
71 | 'id', 'integer', [ |
||
72 | 'autoincrement' => true, |
||
73 | 'notnull' => true, |
||
74 | 'length' => 4, |
||
75 | 'unsigned' => true, |
||
76 | ] |
||
77 | ); |
||
78 | $table->addColumn( |
||
79 | 'unique_id', 'string', [ |
||
80 | 'notnull' => true, |
||
81 | 'length' => 15, |
||
82 | ] |
||
83 | ); |
||
84 | $table->addColumn( |
||
85 | 'long_id', 'string', [ |
||
86 | 'notnull' => true, |
||
87 | 'length' => 64, |
||
88 | ] |
||
89 | ); |
||
90 | $table->addColumn( |
||
91 | 'name', 'string', [ |
||
92 | 'notnull' => true, |
||
93 | 'length' => 127, |
||
94 | ] |
||
95 | ); |
||
96 | $table->addColumn( |
||
97 | 'alt_name', 'string', [ |
||
98 | 'notnull' => false, |
||
99 | 'length' => 127, |
||
100 | 'default' => '' |
||
101 | ] |
||
102 | ); |
||
103 | $table->addColumn( |
||
104 | 'description', 'text', [ |
||
105 | 'notnull' => false |
||
106 | ] |
||
107 | ); |
||
108 | $table->addColumn( |
||
109 | 'settings', 'text', [ |
||
110 | 'notnull' => false |
||
111 | ] |
||
112 | ); |
||
113 | $table->addColumn( |
||
114 | 'type', 'smallint', [ |
||
115 | 'notnull' => true, |
||
116 | 'length' => 2, |
||
117 | ] |
||
118 | ); |
||
119 | $table->addColumn( |
||
120 | 'creation', 'datetime', [ |
||
121 | 'notnull' => false, |
||
122 | ] |
||
123 | ); |
||
124 | $table->addColumn( |
||
125 | 'contact_addressbook', 'integer', [ |
||
126 | 'notnull' => false, |
||
127 | 'unsigned' => true, |
||
128 | 'length' => 7, |
||
129 | ] |
||
130 | ); |
||
131 | $table->addColumn( |
||
132 | 'contact_groupname', 'string', [ |
||
133 | 'notnull' => false, |
||
134 | 'length' => 127, |
||
135 | ] |
||
136 | ); |
||
137 | $table->setPrimaryKey(['id']); |
||
138 | $table->addUniqueIndex(['unique_id']); |
||
139 | $table->addUniqueIndex(['long_id']); |
||
140 | $table->addIndex(['type']); |
||
141 | } |
||
142 | |||
143 | // |
||
144 | // if (!$schema->hasTable('circle_clouds')) { |
||
145 | // $table = $schema->createTable('circle_clouds'); |
||
146 | // $table->addColumn( |
||
147 | // 'cloud_id', 'string', [ |
||
148 | // 'notnull' => true, |
||
149 | // 'length' => 64, |
||
150 | // ] |
||
151 | // ); |
||
152 | // $table->addColumn( |
||
153 | // 'address', 'string', [ |
||
154 | // 'notnull' => true, |
||
155 | // 'length' => 255, |
||
156 | // ] |
||
157 | // ); |
||
158 | // $table->addColumn( |
||
159 | // 'status', 'smallint', [ |
||
160 | // 'notnull' => true, |
||
161 | // 'length' => 1, |
||
162 | // ] |
||
163 | // ); |
||
164 | // $table->addColumn( |
||
165 | // 'note', 'text', [ |
||
166 | // 'notnull' => false |
||
167 | // ] |
||
168 | // ); |
||
169 | // $table->addColumn( |
||
170 | // 'created', 'datetime', [ |
||
171 | // 'notnull' => false, |
||
172 | // ] |
||
173 | // ); |
||
174 | // $table->setPrimaryKey(['cloud_id']); |
||
175 | // } |
||
176 | |||
177 | |||
178 | View Code Duplication | if (!$schema->hasTable('circle_groups')) { |
|
|
|||
179 | $table = $schema->createTable('circle_groups'); |
||
180 | $table->addColumn( |
||
181 | 'circle_id', 'string', [ |
||
182 | 'notnull' => true, |
||
183 | 'length' => 15, |
||
184 | ] |
||
185 | ); |
||
186 | $table->addColumn( |
||
187 | 'group_id', 'string', [ |
||
188 | 'notnull' => true, |
||
189 | 'length' => 64, |
||
190 | ] |
||
191 | ); |
||
192 | $table->addColumn( |
||
193 | 'level', 'smallint', [ |
||
194 | 'notnull' => true, |
||
195 | 'length' => 1, |
||
196 | ] |
||
197 | ); |
||
198 | $table->addColumn( |
||
199 | 'note', 'text', [ |
||
200 | 'notnull' => false |
||
201 | ] |
||
202 | ); |
||
203 | $table->addColumn( |
||
204 | 'joined', 'datetime', [ |
||
205 | 'notnull' => false, |
||
206 | ] |
||
207 | ); |
||
208 | $table->setPrimaryKey(['circle_id', 'group_id']); |
||
209 | } |
||
210 | |||
211 | |||
212 | if (!$schema->hasTable('circle_gsevents')) { |
||
213 | $table = $schema->createTable('circle_gsevents'); |
||
214 | $table->addColumn( |
||
215 | 'token', 'string', [ |
||
216 | 'notnull' => false, |
||
217 | 'length' => 63, |
||
218 | ] |
||
219 | ); |
||
220 | $table->addColumn( |
||
221 | 'event', 'text', [ |
||
222 | 'notnull' => false |
||
223 | ] |
||
224 | ); |
||
225 | $table->addColumn( |
||
226 | 'instance', 'string', [ |
||
227 | 'length' => 255, |
||
228 | 'notnull' => false |
||
229 | ] |
||
230 | ); |
||
231 | $table->addColumn( |
||
232 | 'severity', 'integer', [ |
||
233 | 'length' => 3, |
||
234 | 'notnull' => false |
||
235 | ] |
||
236 | ); |
||
237 | $table->addColumn( |
||
238 | 'status', 'integer', [ |
||
239 | 'length' => 3, |
||
240 | 'notnull' => false |
||
241 | ] |
||
242 | ); |
||
243 | $table->addColumn( |
||
244 | 'creation', 'bigint', [ |
||
245 | 'length' => 14, |
||
246 | 'notnull' => false |
||
247 | ] |
||
248 | ); |
||
249 | $table->addUniqueIndex(['token', 'instance']); |
||
250 | } |
||
251 | |||
252 | |||
253 | if (!$schema->hasTable('circle_gsshares')) { |
||
254 | $table = $schema->createTable('circle_gsshares'); |
||
255 | $table->addColumn( |
||
256 | 'id', 'integer', [ |
||
257 | 'notnull' => false, |
||
258 | 'length' => 11, |
||
259 | 'autoincrement' => true, |
||
260 | 'unsigned' => true |
||
261 | ] |
||
262 | ); |
||
263 | $table->addColumn( |
||
264 | 'circle_id', 'string', [ |
||
265 | 'length' => 15, |
||
266 | 'notnull' => false |
||
267 | ] |
||
268 | ); |
||
269 | $table->addColumn( |
||
270 | 'owner', 'string', [ |
||
271 | 'length' => 15, |
||
272 | 'notnull' => false |
||
273 | ] |
||
274 | ); |
||
275 | $table->addColumn( |
||
276 | 'instance', 'string', [ |
||
277 | 'length' => 255, |
||
278 | 'notnull' => false |
||
279 | ] |
||
280 | ); |
||
281 | $table->addColumn( |
||
282 | 'token', 'string', [ |
||
283 | 'notnull' => false, |
||
284 | 'length' => 63 |
||
285 | ] |
||
286 | ); |
||
287 | $table->addColumn( |
||
288 | 'parent', 'integer', [ |
||
289 | 'notnull' => false, |
||
290 | 'length' => 11, |
||
291 | ] |
||
292 | ); |
||
293 | $table->addColumn( |
||
294 | 'mountpoint', 'text', [ |
||
295 | 'notnull' => false |
||
296 | ] |
||
297 | ); |
||
298 | $table->addColumn( |
||
299 | 'mountpoint_hash', 'string', [ |
||
300 | 'length' => 64, |
||
301 | 'notnull' => false |
||
302 | ] |
||
303 | ); |
||
304 | $table->setPrimaryKey(['id']); |
||
305 | $table->addUniqueIndex(['circle_id', 'mountpoint_hash']); |
||
306 | } |
||
307 | |||
308 | |||
309 | View Code Duplication | if (!$schema->hasTable('circle_gsshares_mp')) { |
|
310 | $table = $schema->createTable('circle_gsshares_mp'); |
||
311 | $table->addColumn( |
||
312 | 'share_id', 'integer', [ |
||
313 | 'length' => 11, |
||
314 | 'notnull' => false |
||
315 | ] |
||
316 | ); |
||
317 | $table->addColumn( |
||
318 | 'user_id', 'string', [ |
||
319 | 'length' => 127, |
||
320 | 'notnull' => false |
||
321 | ] |
||
322 | ); |
||
323 | $table->addColumn( |
||
324 | 'mountpoint', 'text', [ |
||
325 | 'notnull' => false |
||
326 | ] |
||
327 | ); |
||
328 | $table->addColumn( |
||
329 | 'mountpoint_hash', 'string', [ |
||
330 | 'length' => 64, |
||
331 | 'notnull' => false |
||
332 | ] |
||
333 | ); |
||
334 | $table->setPrimaryKey(['share_id', 'user_id']); |
||
335 | $table->addUniqueIndex(['share_id', 'mountpoint_hash']); |
||
336 | } |
||
337 | |||
338 | |||
339 | |||
340 | |||
341 | if (!$schema->hasTable('circle_members')) { |
||
342 | $table = $schema->createTable('circle_members'); |
||
343 | $table->addColumn( |
||
344 | 'circle_id', 'string', [ |
||
345 | 'notnull' => true, |
||
346 | 'length' => 15, |
||
347 | ] |
||
348 | ); |
||
349 | $table->addColumn( |
||
350 | 'member_id', 'string', [ |
||
351 | 'notnull' => false, |
||
352 | 'length' => 15, |
||
353 | ] |
||
354 | ); |
||
355 | $table->addColumn( |
||
356 | 'contact_id', 'string', [ |
||
357 | 'notnull' => false, |
||
358 | 'length' => 127, |
||
359 | ] |
||
360 | ); |
||
361 | $table->addColumn( |
||
362 | 'user_type', 'smallint', [ |
||
363 | 'notnull' => true, |
||
364 | 'length' => 1, |
||
365 | 'default' => 1, |
||
366 | ] |
||
367 | ); |
||
368 | $table->addColumn( |
||
369 | 'user_id', 'string', [ |
||
370 | 'notnull' => true, |
||
371 | 'length' => 127, |
||
372 | ] |
||
373 | ); |
||
374 | $table->addColumn( |
||
375 | 'cached_name', 'string', [ |
||
376 | 'notnull' => false, |
||
377 | 'length' => 255, |
||
378 | 'default' => '' |
||
379 | ] |
||
380 | ); |
||
381 | $table->addColumn( |
||
382 | 'cached_update', 'datetime', [ |
||
383 | 'notnull' => false, |
||
384 | ] |
||
385 | ); |
||
386 | $table->addColumn( |
||
387 | 'instance', 'string', [ |
||
388 | 'default' => '', |
||
389 | 'length' => 255 |
||
390 | ] |
||
391 | ); |
||
392 | $table->addColumn( |
||
393 | 'level', 'smallint', [ |
||
394 | 'notnull' => true, |
||
395 | 'length' => 1, |
||
396 | ] |
||
397 | ); |
||
398 | $table->addColumn( |
||
399 | 'status', 'string', [ |
||
400 | 'notnull' => false, |
||
401 | 'length' => 15, |
||
402 | ] |
||
403 | ); |
||
404 | $table->addColumn( |
||
405 | 'note', 'text', [ |
||
406 | 'notnull' => false |
||
407 | ] |
||
408 | ); |
||
409 | $table->addColumn( |
||
410 | 'joined', 'datetime', [ |
||
411 | 'notnull' => false, |
||
412 | ] |
||
413 | ); |
||
414 | $table->addColumn( |
||
415 | 'contact_meta', 'text', [ |
||
416 | 'notnull' => false |
||
417 | ] |
||
418 | ); |
||
419 | $table->addColumn( |
||
420 | 'contact_checked', 'integer', [ |
||
421 | 'notnull' => false, |
||
422 | 'length' => 1, |
||
423 | ] |
||
424 | ); |
||
425 | |||
426 | $table->setPrimaryKey(['circle_id', 'user_id', 'user_type', 'contact_id', 'instance']); |
||
427 | } |
||
428 | |||
429 | |||
430 | if (!$schema->hasTable('circle_tokens')) { |
||
431 | $table = $schema->createTable('circle_tokens'); |
||
432 | $table->addColumn( |
||
433 | 'circle_id', 'string', [ |
||
434 | 'notnull' => true, |
||
435 | 'length' => 15, |
||
436 | ] |
||
437 | ); |
||
438 | $table->addColumn( |
||
439 | 'member_id', 'string', [ |
||
440 | 'notnull' => false, |
||
441 | 'length' => 15, |
||
442 | ] |
||
443 | ); |
||
444 | $table->addColumn( |
||
445 | 'user_id', 'string', [ |
||
446 | 'notnull' => true, |
||
447 | 'length' => 255, |
||
448 | ] |
||
449 | ); |
||
450 | $table->addColumn( |
||
451 | 'share_id', 'bigint', [ |
||
452 | 'notnull' => true, |
||
453 | 'length' => 14, |
||
454 | ] |
||
455 | ); |
||
456 | $table->addColumn( |
||
457 | 'token', 'string', [ |
||
458 | 'notnull' => true, |
||
459 | 'length' => 31, |
||
460 | ] |
||
461 | ); |
||
462 | $table->addColumn( |
||
463 | 'password', 'string', [ |
||
464 | 'notnull' => true, |
||
465 | 'length' => 127, |
||
466 | ] |
||
467 | ); |
||
468 | $table->addColumn( |
||
469 | 'accepted', 'integer', [ |
||
470 | 'notnull' => false, |
||
471 | 'length' => 1, |
||
472 | ] |
||
473 | ); |
||
474 | $table->setPrimaryKey(['circle_id', 'user_id', 'share_id']); |
||
475 | } |
||
476 | |||
477 | |||
478 | return $schema; |
||
479 | } |
||
480 | |||
667 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.