| Conditions | 9 |
| Paths | 600 |
| Total Lines | 163 |
| Lines | 31 |
| Ratio | 19.02 % |
| 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 |
||
| 67 | public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
||
| 68 | /** @var ISchemaWrapper $schema */ |
||
| 69 | $schema = $schemaClosure(); |
||
| 70 | |||
| 71 | try { |
||
| 72 | $circles = $schema->getTable('circle_circles'); |
||
| 73 | if (!$circles->hasColumn('config')) { |
||
| 74 | $circles->addColumn( |
||
| 75 | 'config', 'integer', [ |
||
| 76 | 'notnull' => false, |
||
| 77 | 'length' => 11, |
||
| 78 | 'unsigned' => true, |
||
| 79 | ] |
||
| 80 | ); |
||
| 81 | } |
||
| 82 | if (!$circles->hasColumn('instance')) { |
||
| 83 | $circles->addColumn( |
||
| 84 | 'instance', 'string', [ |
||
| 85 | 'notnull' => true, |
||
| 86 | 'default' => '', |
||
| 87 | 'length' => 255 |
||
| 88 | ] |
||
| 89 | ); |
||
| 90 | } |
||
| 91 | $circles->addIndex(['config']); |
||
| 92 | } catch (SchemaException $e) { |
||
| 93 | } |
||
| 94 | |||
| 95 | |||
| 96 | try { |
||
| 97 | $circles = $schema->getTable('circle_members'); |
||
| 98 | if (!$circles->hasColumn('single_id')) { |
||
| 99 | $circles->addColumn( |
||
| 100 | 'single_id', 'string', [ |
||
| 101 | 'notnull' => false, |
||
| 102 | 'length' => 15 |
||
| 103 | ] |
||
| 104 | ); |
||
| 105 | } |
||
| 106 | } catch (SchemaException $e) { |
||
| 107 | } |
||
| 108 | |||
| 109 | |||
| 110 | if (!$schema->hasTable('circle_remotes')) { |
||
| 111 | $table = $schema->createTable('circle_remotes'); |
||
| 112 | $table->addColumn( |
||
| 113 | 'id', 'integer', [ |
||
| 114 | 'autoincrement' => true, |
||
| 115 | 'notnull' => true, |
||
| 116 | 'length' => 4, |
||
| 117 | 'unsigned' => true, |
||
| 118 | ] |
||
| 119 | ); |
||
| 120 | $table->addColumn( |
||
| 121 | 'type', 'string', [ |
||
| 122 | 'notnull' => true, |
||
| 123 | 'length' => 15, |
||
| 124 | 'default' => 'Unknown' |
||
| 125 | ] |
||
| 126 | ); |
||
| 127 | $table->addColumn( |
||
| 128 | 'uid', 'string', [ |
||
| 129 | 'notnull' => false, |
||
| 130 | 'length' => 20, |
||
| 131 | ] |
||
| 132 | ); |
||
| 133 | $table->addColumn( |
||
| 134 | 'instance', 'string', [ |
||
| 135 | 'notnull' => false, |
||
| 136 | 'length' => 127, |
||
| 137 | ] |
||
| 138 | ); |
||
| 139 | $table->addColumn( |
||
| 140 | 'href', 'string', [ |
||
| 141 | 'notnull' => false, |
||
| 142 | 'length' => 254, |
||
| 143 | ] |
||
| 144 | ); |
||
| 145 | $table->addColumn( |
||
| 146 | 'item', 'text', [ |
||
| 147 | 'notnull' => false, |
||
| 148 | ] |
||
| 149 | ); |
||
| 150 | $table->addColumn( |
||
| 151 | 'creation', 'datetime', [ |
||
| 152 | 'notnull' => false, |
||
| 153 | ] |
||
| 154 | ); |
||
| 155 | |||
| 156 | $table->setPrimaryKey(['id']); |
||
| 157 | $table->addUniqueIndex(['instance']); |
||
| 158 | $table->addIndex(['uid']); |
||
| 159 | $table->addIndex(['href']); |
||
| 160 | } |
||
| 161 | |||
| 162 | View Code Duplication | if (!$schema->hasTable('circle_membership')) { |
|
| 163 | $table = $schema->createTable('circle_membership'); |
||
| 164 | |||
| 165 | $table->addColumn( |
||
| 166 | 'id', 'string', [ |
||
| 167 | 'notnull' => true, |
||
| 168 | 'length' => 15, |
||
| 169 | ] |
||
| 170 | ); |
||
| 171 | $table->addColumn( |
||
| 172 | 'circle_id', 'string', [ |
||
| 173 | 'notnull' => true, |
||
| 174 | 'length' => 15, |
||
| 175 | ] |
||
| 176 | ); |
||
| 177 | $table->addColumn( |
||
| 178 | 'member_id', 'string', [ |
||
| 179 | 'notnull' => true, |
||
| 180 | 'length' => 15, |
||
| 181 | ] |
||
| 182 | ); |
||
| 183 | $table->addColumn( |
||
| 184 | 'level', 'integer', [ |
||
| 185 | 'notnull' => true, |
||
| 186 | 'length' => 1, |
||
| 187 | 'unsigned' => true |
||
| 188 | ] |
||
| 189 | ); |
||
| 190 | |||
| 191 | $table->addIndex(['id']); |
||
| 192 | } |
||
| 193 | |||
| 194 | |||
| 195 | if (!$schema->hasTable('circle_share_locks')) { |
||
| 196 | $table = $schema->createTable('circle_share_locks'); |
||
| 197 | $table->addColumn( |
||
| 198 | 'id', 'integer', [ |
||
| 199 | 'autoincrement' => true, |
||
| 200 | 'notnull' => true, |
||
| 201 | 'length' => 4, |
||
| 202 | 'unsigned' => true, |
||
| 203 | ] |
||
| 204 | ); |
||
| 205 | $table->addColumn( |
||
| 206 | 'item_id', 'string', [ |
||
| 207 | 'notnull' => true, |
||
| 208 | 'length' => 15 |
||
| 209 | ] |
||
| 210 | ); |
||
| 211 | $table->addColumn( |
||
| 212 | 'circle_id', 'string', [ |
||
| 213 | 'notnull' => true, |
||
| 214 | 'length' => 15 |
||
| 215 | ] |
||
| 216 | ); |
||
| 217 | $table->addColumn( |
||
| 218 | 'instance', 'string', [ |
||
| 219 | 'notnull' => true, |
||
| 220 | 'length' => 127, |
||
| 221 | ] |
||
| 222 | ); |
||
| 223 | |||
| 224 | $table->setPrimaryKey(['id']); |
||
| 225 | $table->addUniqueIndex(['item_id', 'circle_id']); |
||
| 226 | } |
||
| 227 | |||
| 228 | return $schema; |
||
| 229 | } |
||
| 230 | |||
| 233 |