| Conditions | 4 |
| Paths | 3 |
| Total Lines | 75 |
| Code Lines | 56 |
| 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 |
||
| 47 | public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
||
| 48 | /** @var ISchemaWrapper $schema */ |
||
| 49 | $schema = $schemaClosure(); |
||
| 50 | |||
| 51 | if (!$schema->hasTable('share_external')) { |
||
| 52 | $table = $schema->createTable('share_external'); |
||
| 53 | $table->addColumn('id', Types::BIGINT, [ |
||
| 54 | 'autoincrement' => true, |
||
| 55 | 'notnull' => true, |
||
| 56 | ]); |
||
| 57 | $table->addColumn('parent', Types::BIGINT, [ |
||
| 58 | 'notnull' => false, |
||
| 59 | 'default' => -1, |
||
| 60 | ]); |
||
| 61 | $table->addColumn('share_type', Types::INTEGER, [ |
||
| 62 | 'notnull' => false, |
||
| 63 | 'length' => 4, |
||
| 64 | ]); |
||
| 65 | $table->addColumn('remote', Types::STRING, [ |
||
| 66 | 'notnull' => true, |
||
| 67 | 'length' => 512, |
||
| 68 | ]); |
||
| 69 | $table->addColumn('remote_id', Types::STRING, [ |
||
| 70 | 'notnull' => false, |
||
| 71 | 'length' => 255, |
||
| 72 | 'default' => '', |
||
| 73 | ]); |
||
| 74 | $table->addColumn('share_token', Types::STRING, [ |
||
| 75 | 'notnull' => true, |
||
| 76 | 'length' => 64, |
||
| 77 | ]); |
||
| 78 | $table->addColumn('password', Types::STRING, [ |
||
| 79 | 'notnull' => false, |
||
| 80 | 'length' => 64, |
||
| 81 | ]); |
||
| 82 | $table->addColumn('name', Types::STRING, [ |
||
| 83 | 'notnull' => true, |
||
| 84 | 'length' => 64, |
||
| 85 | ]); |
||
| 86 | $table->addColumn('owner', Types::STRING, [ |
||
| 87 | 'notnull' => true, |
||
| 88 | 'length' => 64, |
||
| 89 | ]); |
||
| 90 | $table->addColumn('user', Types::STRING, [ |
||
| 91 | 'notnull' => true, |
||
| 92 | 'length' => 64, |
||
| 93 | ]); |
||
| 94 | $table->addColumn('mountpoint', Types::STRING, [ |
||
| 95 | 'notnull' => true, |
||
| 96 | 'length' => 4000, |
||
| 97 | ]); |
||
| 98 | $table->addColumn('mountpoint_hash', Types::STRING, [ |
||
| 99 | 'notnull' => true, |
||
| 100 | 'length' => 32, |
||
| 101 | ]); |
||
| 102 | $table->addColumn('accepted', Types::INTEGER, [ |
||
| 103 | 'notnull' => true, |
||
| 104 | 'length' => 4, |
||
| 105 | 'default' => 0, |
||
| 106 | ]); |
||
| 107 | $table->setPrimaryKey(['id']); |
||
| 108 | $table->addIndex(['user'], 'sh_external_user'); |
||
| 109 | $table->addUniqueIndex(['user', 'mountpoint_hash'], 'sh_external_mp'); |
||
| 110 | } else { |
||
| 111 | $table = $schema->getTable('share_external'); |
||
| 112 | $remoteIdColumn = $table->getColumn('remote_id'); |
||
| 113 | if ($remoteIdColumn && $remoteIdColumn->getType()->getName() !== Types::STRING) { |
||
| 114 | $remoteIdColumn->setNotnull(false); |
||
| 115 | $remoteIdColumn->setType(Type::getType(Types::STRING)); |
||
| 116 | $remoteIdColumn->setOptions(['length' => 255]); |
||
| 117 | $remoteIdColumn->setDefault(''); |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | return $schema; |
||
| 122 | } |
||
| 132 |