| Conditions | 1 |
| Paths | 1 |
| Total Lines | 60 |
| 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 |
||
| 13 | public function changeSchema(Schema $schema, array $options) { |
||
| 14 | $prefix = $options['tablePrefix']; |
||
| 15 | $table = $schema->createTable("{$prefix}persistent_locks"); |
||
| 16 | $table->addColumn('id', Type::BIGINT, [ |
||
| 17 | 'autoincrement' => true, |
||
| 18 | 'unsigned' => true, |
||
| 19 | 'notnull' => true, |
||
| 20 | ]); |
||
| 21 | $table->addColumn('file_id', Type::BIGINT, [ |
||
| 22 | 'notnull' => true, |
||
| 23 | 'length' => 20, |
||
| 24 | 'comment' => 'FK to fileid in table oc_file_cache' |
||
| 25 | ]); |
||
| 26 | $table->addColumn('owner', Type::STRING, [ |
||
| 27 | 'notnull' => false, |
||
| 28 | 'length' => 100, |
||
| 29 | 'comment' => 'owner of the lock - just a human readable string' |
||
| 30 | ]); |
||
| 31 | $table->addColumn('timeout', Type::INTEGER, [ |
||
| 32 | 'notnull' => true, |
||
| 33 | 'unsigned' => true, |
||
| 34 | 'comment' => 'timestamp when the lock expires' |
||
| 35 | ]); |
||
| 36 | $table->addColumn('created_at', Type::INTEGER, [ |
||
| 37 | 'notnull' => true, |
||
| 38 | 'unsigned' => true, |
||
| 39 | 'comment' => 'timestamp when the lock was created' |
||
| 40 | ]); |
||
| 41 | $table->addColumn('token', Type::STRING, [ |
||
| 42 | 'notnull' => true, |
||
| 43 | 'length' => 1024, |
||
| 44 | 'comment' => 'uuid for webdav locks - 1024 random chars for WOPI locks' |
||
| 45 | ]); |
||
| 46 | $table->addColumn('token_hash', Type::STRING, [ |
||
| 47 | 'notnull' => true, |
||
| 48 | 'length' => 32, |
||
| 49 | 'comment' => 'md5(token)' |
||
| 50 | ]); |
||
| 51 | // mysql specific |
||
| 52 | $table->addColumn('scope', Type::SMALLINT, [ |
||
| 53 | 'notnull' => true, |
||
| 54 | 'comment' => '1 - exclusive, 2 - shared' |
||
| 55 | ]); |
||
| 56 | $table->addColumn('depth', Type::SMALLINT, [ |
||
| 57 | 'notnull' => true, |
||
| 58 | 'comment' => '0, 1 or infinite' |
||
| 59 | ]); |
||
| 60 | $table->addColumn('owner_account_id', Type::BIGINT, [ |
||
| 61 | 'notnull' => false, |
||
| 62 | 'unsigned' => true, |
||
| 63 | 'length' => 20, |
||
| 64 | 'comment' => 'owner of the lock - FK to account table' |
||
| 65 | ]); |
||
| 66 | |||
| 67 | $table->setPrimaryKey(['id']); |
||
| 68 | $table->addUniqueIndex(['token_hash']); |
||
| 69 | $table->addForeignKeyConstraint("{$prefix}filecache", ['file_id'], ['fileid']); |
||
| 70 | $table->addForeignKeyConstraint("{$prefix}accounts", ['owner_account_id'], ['id']); |
||
| 71 | // TODO: cascade delete |
||
| 72 | } |
||
| 73 | } |
||
| 74 |