| Conditions | 14 |
| Paths | 2040 |
| Total Lines | 310 |
| Code Lines | 226 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 43 | public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) |
||
| 44 | { |
||
| 45 | /** @var Schema $schema */ |
||
| 46 | $schema = $schemaClosure(); |
||
| 47 | |||
| 48 | if (!$schema->hasTable('analytics_dataset')) { |
||
| 49 | $table = $schema->createTable('analytics_dataset'); |
||
| 50 | $table->addColumn('id', 'integer', [ |
||
| 51 | 'autoincrement' => true, |
||
| 52 | 'notnull' => true, |
||
| 53 | ]); |
||
| 54 | $table->addColumn('user_id', 'string', [ |
||
| 55 | 'notnull' => true, |
||
| 56 | 'length' => 64, |
||
| 57 | ]); |
||
| 58 | $table->addColumn('name', 'string', [ |
||
| 59 | 'notnull' => true, |
||
| 60 | 'length' => 64, |
||
| 61 | ]); |
||
| 62 | $table->addColumn('subheader', 'string', [ |
||
| 63 | 'notnull' => false, |
||
| 64 | 'length' => 256, |
||
| 65 | ]); |
||
| 66 | $table->addColumn('type', 'integer', [ |
||
| 67 | 'notnull' => false, |
||
| 68 | ]); |
||
| 69 | $table->addColumn('link', 'string', [ |
||
| 70 | 'notnull' => false, |
||
| 71 | 'length' => 500, |
||
| 72 | ]); |
||
| 73 | $table->addColumn('visualization', 'string', [ |
||
| 74 | 'notnull' => false, |
||
| 75 | 'length' => 10, |
||
| 76 | ]); |
||
| 77 | $table->addColumn('chart', 'string', [ |
||
| 78 | 'notnull' => false, |
||
| 79 | 'length' => 256, |
||
| 80 | ]); |
||
| 81 | $table->addColumn('parent', 'integer', [ |
||
| 82 | 'notnull' => false, |
||
| 83 | ]); |
||
| 84 | $table->addColumn('dimension1', 'string', [ |
||
| 85 | 'notnull' => false, |
||
| 86 | 'length' => 64, |
||
| 87 | ]); |
||
| 88 | $table->addColumn('dimension2', 'string', [ |
||
| 89 | 'notnull' => false, |
||
| 90 | 'length' => 64, |
||
| 91 | ]); |
||
| 92 | $table->addColumn('dimension3', 'string', [ |
||
| 93 | 'notnull' => false, |
||
| 94 | 'length' => 64, |
||
| 95 | ]); |
||
| 96 | $table->addColumn('value', 'string', [ |
||
| 97 | 'notnull' => false, |
||
| 98 | 'length' => 64, |
||
| 99 | ]); |
||
| 100 | $table->addColumn('chartoptions', 'string', [ |
||
| 101 | 'notnull' => false, |
||
| 102 | 'length' => 1000, |
||
| 103 | ]); |
||
| 104 | $table->addColumn('dataoptions', 'string', [ |
||
| 105 | 'notnull' => false, |
||
| 106 | 'length' => 1000, |
||
| 107 | ]); |
||
| 108 | $table->addColumn('filteroptions', 'string', [ |
||
| 109 | 'notnull' => false, |
||
| 110 | 'length' => 1000, |
||
| 111 | ]); |
||
| 112 | $table->setPrimaryKey(['id']); |
||
| 113 | $table->addIndex(['user_id'], 'analytics_dataset_user_id_idx'); |
||
| 114 | } else { |
||
| 115 | $table = $schema->getTable('analytics_dataset'); |
||
| 116 | if (!$table->hasColumn('value')) { |
||
| 117 | $table->addColumn('value', 'string', [ |
||
| 118 | 'notnull' => false, |
||
| 119 | 'length' => 64, |
||
| 120 | ]); |
||
| 121 | } |
||
| 122 | $column = $table->getColumn('link'); |
||
| 123 | if ($column->getLength() !== 500) { |
||
| 124 | $column->setLength(500); |
||
| 125 | } |
||
| 126 | |||
| 127 | if (!$table->hasColumn('dataoptions')) { |
||
| 128 | $table->addColumn('dataoptions', 'string', [ |
||
| 129 | 'notnull' => false, |
||
| 130 | 'length' => 1000, |
||
| 131 | ]); |
||
| 132 | } |
||
| 133 | if (!$table->hasColumn('filteroptions')) { |
||
| 134 | $table->addColumn('filteroptions', 'string', [ |
||
| 135 | 'notnull' => false, |
||
| 136 | 'length' => 1000, |
||
| 137 | ]); |
||
| 138 | } |
||
| 139 | } |
||
| 140 | |||
| 141 | if (!$schema->hasTable('analytics_facts')) { |
||
| 142 | $table = $schema->createTable('analytics_facts'); |
||
| 143 | $table->addColumn('id', 'integer', [ |
||
| 144 | 'autoincrement' => true, |
||
| 145 | 'notnull' => true, |
||
| 146 | ]); |
||
| 147 | $table->addColumn('user_id', 'string', [ |
||
| 148 | 'notnull' => true, |
||
| 149 | 'length' => 64, |
||
| 150 | ]); |
||
| 151 | $table->addColumn('dataset', 'integer', [ |
||
| 152 | 'notnull' => true, |
||
| 153 | ]); |
||
| 154 | $table->addColumn('dimension1', 'string', [ |
||
| 155 | 'notnull' => false, |
||
| 156 | 'length' => 64, |
||
| 157 | ]); |
||
| 158 | $table->addColumn('dimension2', 'string', [ |
||
| 159 | 'notnull' => false, |
||
| 160 | 'length' => 64, |
||
| 161 | ]); |
||
| 162 | $table->addColumn('dimension3', 'decimal', [ |
||
| 163 | 'notnull' => false, |
||
| 164 | ]); |
||
| 165 | $table->addColumn('value', 'decimal', [ |
||
| 166 | 'notnull' => false, |
||
| 167 | 'precision' => 15, |
||
| 168 | 'scale' => 2, |
||
| 169 | 'default' => 0, |
||
| 170 | ]); |
||
| 171 | $table->addColumn('timestamp', 'integer', [ |
||
| 172 | 'notnull' => false, |
||
| 173 | 'default' => 0, |
||
| 174 | ]); |
||
| 175 | $table->setPrimaryKey(['id']); |
||
| 176 | $table->addIndex(['dataset'], 'analytics_facts_dataset_idx'); |
||
| 177 | } else { |
||
| 178 | $table = $schema->getTable('analytics_facts'); |
||
| 179 | if (!$table->hasColumn('value')) { |
||
| 180 | $table->addColumn('value', 'decimal', [ |
||
| 181 | 'notnull' => false, |
||
| 182 | 'precision' => 15, |
||
| 183 | 'scale' => 2, |
||
| 184 | 'default' => 0, |
||
| 185 | ]); |
||
| 186 | } |
||
| 187 | if (!$table->hasColumn('timestamp')) { |
||
| 188 | $table->addColumn('timestamp', 'integer', [ |
||
| 189 | 'notnull' => false, |
||
| 190 | 'default' => 0, |
||
| 191 | ]); |
||
| 192 | } |
||
| 193 | } |
||
| 194 | |||
| 195 | if (!$schema->hasTable('analytics_share')) { |
||
| 196 | $table = $schema->createTable('analytics_share'); |
||
| 197 | $table->addColumn('id', 'integer', [ |
||
| 198 | 'autoincrement' => true, |
||
| 199 | 'notnull' => true, |
||
| 200 | ]); |
||
| 201 | $table->addColumn('dataset', 'integer', [ |
||
| 202 | 'notnull' => true, |
||
| 203 | ]); |
||
| 204 | $table->addColumn('type', 'integer', [ |
||
| 205 | 'notnull' => false, |
||
| 206 | ]); |
||
| 207 | $table->addColumn('uid_owner', 'string', [ |
||
| 208 | 'notnull' => false, |
||
| 209 | 'length' => 64, |
||
| 210 | ]); |
||
| 211 | $table->addColumn('uid_initiator', 'string', [ |
||
| 212 | 'notnull' => true, |
||
| 213 | 'length' => 64, |
||
| 214 | ]); |
||
| 215 | $table->addColumn('permissions', 'integer', [ |
||
| 216 | 'notnull' => false, |
||
| 217 | ]); |
||
| 218 | $table->addColumn('token', 'string', [ |
||
| 219 | 'notnull' => false, |
||
| 220 | 'length' => 32, |
||
| 221 | ]); |
||
| 222 | $table->addColumn('password', 'string', [ |
||
| 223 | 'notnull' => false, |
||
| 224 | 'length' => 64, |
||
| 225 | ]); |
||
| 226 | $table->setPrimaryKey(['id']); |
||
| 227 | $table->addIndex(['dataset'], 'analytics_share_dataset_idx'); |
||
| 228 | $table->addIndex(['uid_owner'], 'analytics_share_uid_owner_idx'); |
||
| 229 | $table->addIndex(['token'], 'analytics_share_token_idx'); |
||
| 230 | } |
||
| 231 | |||
| 232 | if (!$schema->hasTable('analytics_threshold')) { |
||
| 233 | $table = $schema->createTable('analytics_threshold'); |
||
| 234 | $table->addColumn('id', 'integer', [ |
||
| 235 | 'autoincrement' => true, |
||
| 236 | 'notnull' => true, |
||
| 237 | ]); |
||
| 238 | $table->addColumn('user_id', 'string', [ |
||
| 239 | 'notnull' => true, |
||
| 240 | 'length' => 64, |
||
| 241 | ]); |
||
| 242 | $table->addColumn('dataset', 'integer', [ |
||
| 243 | 'notnull' => true, |
||
| 244 | ]); |
||
| 245 | $table->addColumn('name', 'string', [ |
||
| 246 | 'notnull' => false, |
||
| 247 | 'length' => 64, |
||
| 248 | ]); |
||
| 249 | $table->addColumn('dimension1', 'string', [ |
||
| 250 | 'notnull' => false, |
||
| 251 | 'length' => 64, |
||
| 252 | ]); |
||
| 253 | $table->addColumn('dimension2', 'string', [ |
||
| 254 | 'notnull' => false, |
||
| 255 | 'length' => 64, |
||
| 256 | ]); |
||
| 257 | $table->addColumn('dimension3', 'decimal', [ |
||
| 258 | 'notnull' => false, |
||
| 259 | ]); |
||
| 260 | $table->addColumn('value', 'decimal', [ |
||
| 261 | 'notnull' => false, |
||
| 262 | 'precision' => 15, |
||
| 263 | 'scale' => 2, |
||
| 264 | 'default' => 0, |
||
| 265 | ]); |
||
| 266 | $table->addColumn('option', 'string', [ |
||
| 267 | 'notnull' => false, |
||
| 268 | 'length' => 5, |
||
| 269 | ]); |
||
| 270 | $table->addColumn('severity', 'integer', [ |
||
| 271 | 'notnull' => true, |
||
| 272 | ]); |
||
| 273 | $table->setPrimaryKey(['id']); |
||
| 274 | $table->addIndex(['dataset'], 'analytics_threshold_dset_idx'); |
||
| 275 | } else { |
||
| 276 | $table = $schema->getTable('analytics_threshold'); |
||
| 277 | if (!$table->hasColumn('value')) { |
||
| 278 | $table->addColumn('value', 'decimal', [ |
||
| 279 | 'notnull' => false, |
||
| 280 | 'precision' => 15, |
||
| 281 | 'scale' => 2, |
||
| 282 | 'default' => 0, |
||
| 283 | ]); |
||
| 284 | } |
||
| 285 | } |
||
| 286 | |||
| 287 | if (!$schema->hasTable('analytics_dataload')) { |
||
| 288 | $table = $schema->createTable('analytics_dataload'); |
||
| 289 | $table->addColumn('id', 'integer', [ |
||
| 290 | 'autoincrement' => true, |
||
| 291 | 'notnull' => true, |
||
| 292 | ]); |
||
| 293 | $table->addColumn('user_id', 'string', [ |
||
| 294 | 'notnull' => true, |
||
| 295 | 'length' => 64, |
||
| 296 | ]); |
||
| 297 | $table->addColumn('dataset', 'integer', [ |
||
| 298 | 'notnull' => true, |
||
| 299 | ]); |
||
| 300 | $table->addColumn('datasource', 'integer', [ |
||
| 301 | 'notnull' => true, |
||
| 302 | ]); |
||
| 303 | $table->addColumn('name', 'string', [ |
||
| 304 | 'notnull' => false, |
||
| 305 | 'length' => 64, |
||
| 306 | ]); |
||
| 307 | $table->addColumn('option', 'string', [ |
||
| 308 | 'notnull' => false, |
||
| 309 | 'length' => 500, |
||
| 310 | ]); |
||
| 311 | $table->addColumn('schedule', 'string', [ |
||
| 312 | 'notnull' => false, |
||
| 313 | 'length' => 1, |
||
| 314 | ]); |
||
| 315 | $table->setPrimaryKey(['id']); |
||
| 316 | $table->addIndex(['dataset'], 'analytics_dataload_dataset_idx'); |
||
| 317 | } |
||
| 318 | |||
| 319 | if (!$schema->hasTable('analytics_whats_new')) { |
||
| 320 | $table = $schema->createTable('analytics_whats_new'); |
||
| 321 | $table->addColumn('id', 'integer', [ |
||
| 322 | 'autoincrement' => true, |
||
| 323 | 'notnull' => true, |
||
| 324 | 'length' => 4, |
||
| 325 | 'unsigned' => true, |
||
| 326 | ]); |
||
| 327 | $table->addColumn('version', 'string', [ |
||
| 328 | 'notnull' => true, |
||
| 329 | 'length' => 64, |
||
| 330 | 'default' => '11', |
||
| 331 | ]); |
||
| 332 | $table->addColumn('etag', 'string', [ |
||
| 333 | 'notnull' => true, |
||
| 334 | 'length' => 64, |
||
| 335 | 'default' => '', |
||
| 336 | ]); |
||
| 337 | $table->addColumn('last_check', 'integer', [ |
||
| 338 | 'notnull' => true, |
||
| 339 | 'length' => 4, |
||
| 340 | 'unsigned' => true, |
||
| 341 | 'default' => 0, |
||
| 342 | ]); |
||
| 343 | $table->addColumn('data', 'text', [ |
||
| 344 | 'notnull' => true, |
||
| 345 | 'default' => '', |
||
| 346 | ]); |
||
| 347 | $table->setPrimaryKey(['id']); |
||
| 348 | $table->addUniqueIndex(['version'], 'analytics_whats_new_v_idx'); |
||
| 349 | $table->addIndex(['version', 'etag'], 'analytics_whats_new_v_e_idx'); |
||
| 350 | } |
||
| 351 | |||
| 352 | return $schema; |
||
| 353 | } |
||
| 364 |