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