| Conditions | 9 |
| Paths | 70 |
| Total Lines | 61 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 61 | public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
||
| 62 | /** @var ISchemaWrapper $schema */ |
||
| 63 | $schema = $schemaClosure(); |
||
| 64 | |||
| 65 | $changeSchema = false; |
||
| 66 | foreach (['ldap_user_mapping', 'ldap_group_mapping'] as $tableName) { |
||
| 67 | $table = $schema->getTable($tableName); |
||
| 68 | if (!$table->hasColumn('ldap_dn_hash')) { |
||
| 69 | $table->addColumn('ldap_dn_hash', Types::STRING, [ |
||
| 70 | 'notnull' => false, |
||
| 71 | 'length' => 64, |
||
| 72 | ]); |
||
| 73 | $changeSchema = true; |
||
| 74 | } |
||
| 75 | $column = $table->getColumn('ldap_dn'); |
||
| 76 | if ($tableName === 'ldap_user_mapping') { |
||
| 77 | if ($column->getLength() < 4096) { |
||
| 78 | $column->setLength(4096); |
||
| 79 | $changeSchema = true; |
||
| 80 | } |
||
| 81 | |||
| 82 | if ($table->hasIndex('ldap_dn_users')) { |
||
| 83 | $table->dropIndex('ldap_dn_users'); |
||
| 84 | $changeSchema = true; |
||
| 85 | } |
||
| 86 | if (!$table->hasIndex('ldap_user_dn_hashes')) { |
||
| 87 | $table->addUniqueIndex(['ldap_dn_hash'], 'ldap_user_dn_hashes'); |
||
| 88 | $changeSchema = true; |
||
| 89 | } |
||
| 90 | if (!$table->hasIndex('ldap_user_directory_uuid')) { |
||
| 91 | $table->addUniqueIndex(['directory_uuid'], 'ldap_user_directory_uuid'); |
||
| 92 | $changeSchema = true; |
||
| 93 | } |
||
| 94 | } else { |
||
| 95 | // We need to copy the table twice to be able to change primary key, prepare the backup table |
||
| 96 | $table2 = $schema->createTable('ldap_group_mapping_backup'); |
||
| 97 | $table2->addColumn('ldap_dn', Types::STRING, [ |
||
| 98 | 'notnull' => true, |
||
| 99 | 'length' => 4096, |
||
| 100 | 'default' => '', |
||
| 101 | ]); |
||
| 102 | $table2->addColumn('owncloud_name', Types::STRING, [ |
||
| 103 | 'notnull' => true, |
||
| 104 | 'length' => 64, |
||
| 105 | 'default' => '', |
||
| 106 | ]); |
||
| 107 | $table2->addColumn('directory_uuid', Types::STRING, [ |
||
| 108 | 'notnull' => true, |
||
| 109 | 'length' => 255, |
||
| 110 | 'default' => '', |
||
| 111 | ]); |
||
| 112 | $table2->addColumn('ldap_dn_hash', Types::STRING, [ |
||
| 113 | 'notnull' => false, |
||
| 114 | 'length' => 64, |
||
| 115 | ]); |
||
| 116 | $table2->setPrimaryKey(['owncloud_name'], 'lgm_backup_primary'); |
||
| 117 | $changeSchema = true; |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | return $changeSchema ? $schema : null; |
||
| 122 | } |
||
| 176 |