| Conditions | 2 | 
| Paths | 2 | 
| Total Lines | 245 | 
| Code Lines | 180 | 
| 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 | ||
| 187 | private static function initSchema(Connection $connection): void | ||
| 188 |     { | ||
| 189 | $fromSchema = $connection->getSchemaManager()->createSchema(); | ||
| 190 | $toSchema = clone $fromSchema; | ||
| 191 | |||
| 192 | $db = new FluidSchema($toSchema); | ||
| 193 | |||
| 194 |         $db->table('country') | ||
| 195 |             ->column('id')->integer()->primaryKey()->autoIncrement()->comment('@Autoincrement') | ||
| 196 |             ->column('label')->string(255); | ||
| 197 | |||
| 198 |         $db->table('person') | ||
| 199 |             ->column('id')->integer()->primaryKey()->autoIncrement()->comment('@Autoincrement') | ||
| 200 |             ->column('name')->string(255); | ||
| 201 | |||
| 202 |         $toSchema->getTable('person') | ||
| 203 | ->addColumn( | ||
| 204 | 'created_at', | ||
| 205 | 'datetime', | ||
| 206 | ['columnDefinition' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP'] | ||
| 207 | ); | ||
| 208 | |||
| 209 |         $db->table('person') | ||
| 210 |             ->column('modified_at')->datetime()->null() | ||
| 211 |             ->column('order')->integer()->null(); | ||
| 212 | |||
| 213 | |||
| 214 |         $db->table('contact') | ||
| 215 |             ->extends('person') | ||
| 216 |             ->column('email')->string(255) | ||
| 217 |             ->column('manager_id')->references('contact')->null(); | ||
| 218 | |||
| 219 |         $db->table('users') | ||
| 220 |             ->extends('contact') | ||
| 221 |             ->column('login')->string(255) | ||
| 222 |             ->column('password')->string(255)->null() | ||
| 223 |             ->column('status')->string(10)->null()->default(null) | ||
| 224 |             ->column('country_id')->references('country'); | ||
| 225 | |||
| 226 |         $db->table('rights') | ||
| 227 |             ->column('label')->string(255)->primaryKey()->comment('Non autoincrementable primary key'); | ||
| 228 | |||
| 229 |         $db->table('roles') | ||
| 230 |             ->column('id')->integer()->primaryKey()->autoIncrement()->comment('@Autoincrement') | ||
| 231 |             ->column('name')->string(255) | ||
| 232 |             ->column('created_at')->date()->null() | ||
| 233 |             ->column('status')->boolean()->null()->default(1); | ||
| 234 | |||
| 235 |         $db->table('roles_rights') | ||
| 236 |             ->column('role_id')->references('roles') | ||
| 237 |             ->column('right_label')->references('rights')->then() | ||
| 238 | ->primaryKey(['role_id', 'right_label']); | ||
| 239 | |||
| 240 |         $db->table('users_roles') | ||
| 241 |             ->column('id')->integer()->primaryKey()->autoIncrement()->comment('@Autoincrement') | ||
| 242 |             ->column('user_id')->references('users') | ||
| 243 |             ->column('role_id')->references('roles'); | ||
| 244 | |||
| 245 |         $db->table('all_nullable') | ||
| 246 |             ->column('id')->integer()->primaryKey()->autoIncrement()->comment('@Autoincrement') | ||
| 247 |             ->column('label')->string(255)->null() | ||
| 248 |             ->column('country_id')->references('country')->null(); | ||
| 249 | |||
| 250 |         $db->table('animal') | ||
| 251 |             ->column('id')->integer()->primaryKey()->autoIncrement()->comment('@Autoincrement') | ||
| 252 |             ->column('name')->string(45)->index() | ||
| 253 |             ->column('order')->integer()->null(); | ||
| 254 | |||
| 255 |         $db->table('dog') | ||
| 256 |             ->extends('animal') | ||
| 257 |             ->column('race')->string(45)->null(); | ||
| 258 | |||
| 259 |         $db->table('cat') | ||
| 260 |             ->extends('animal') | ||
| 261 |             ->column('cuteness_level')->integer()->null(); | ||
| 262 | |||
| 263 |         $db->table('boats') | ||
| 264 |             ->column('id')->integer()->primaryKey()->autoIncrement()->comment('@Autoincrement') | ||
| 265 |             ->column('name')->string(255) | ||
| 266 |             ->column('anchorage_country')->references('country')->notNull(); | ||
| 267 | |||
| 268 |         $db->table('sailed_countries') | ||
| 269 |             ->column('boat_id')->references('boats') | ||
| 270 |             ->column('country_id')->references('country') | ||
| 271 | ->then()->primaryKey(['boat_id', 'country_id']); | ||
| 272 | |||
| 273 |         $db->table('category') | ||
| 274 |             ->column('id')->integer()->primaryKey()->autoIncrement()->comment('@Autoincrement') | ||
| 275 |             ->column('label')->string(255) | ||
| 276 |             ->column('parent_id')->references('category')->null(); | ||
| 277 | |||
| 278 |         $db->table('article') | ||
| 279 |             ->column('id')->string(36)->primaryKey()->comment('@UUID') | ||
| 280 |             ->column('content')->string(255); | ||
| 281 | |||
| 282 |         $db->table('article2') | ||
| 283 |             ->column('id')->string(36)->primaryKey()->comment('@UUID v4') | ||
| 284 |             ->column('content')->string(255); | ||
| 285 | |||
| 286 |         $toSchema->getTable('users') | ||
| 287 | ->addUniqueIndex(['login'], 'users_login_idx') | ||
| 288 | ->addUniqueIndex(['login'], 'users_login_idx_2') // We create the same index twice | ||
| 289 | ->addIndex(['status', 'country_id'], 'users_status_country_idx'); | ||
| 290 | |||
| 291 | $sqlStmts = $toSchema->getMigrateFromSql($fromSchema, $connection->getDatabasePlatform()); | ||
| 292 | |||
| 293 |         foreach ($sqlStmts as $sqlStmt) { | ||
| 294 | $connection->exec($sqlStmt); | ||
| 295 | } | ||
| 296 | |||
| 297 |         $connection->insert('country', [ | ||
| 298 | 'label' => 'France', | ||
| 299 | ]); | ||
| 300 |         $connection->insert('country', [ | ||
| 301 | 'label' => 'UK', | ||
| 302 | ]); | ||
| 303 |         $connection->insert('country', [ | ||
| 304 | 'label' => 'Jamaica', | ||
| 305 | ]); | ||
| 306 | |||
| 307 |         $connection->insert('person', [ | ||
| 308 | 'name' => 'John Smith', | ||
| 309 | 'created_at' => '2015-10-24 11:57:13', | ||
| 310 | ]); | ||
| 311 |         $connection->insert('person', [ | ||
| 312 | 'name' => 'Jean Dupont', | ||
| 313 | 'created_at' => '2015-10-24 11:57:13', | ||
| 314 | ]); | ||
| 315 |         $connection->insert('person', [ | ||
| 316 | 'name' => 'Robert Marley', | ||
| 317 | 'created_at' => '2015-10-24 11:57:13', | ||
| 318 | ]); | ||
| 319 |         $connection->insert('person', [ | ||
| 320 | 'name' => 'Bill Shakespeare', | ||
| 321 | 'created_at' => '2015-10-24 11:57:13', | ||
| 322 | ]); | ||
| 323 | |||
| 324 |         $connection->insert('contact', [ | ||
| 325 | 'id' => 1, | ||
| 326 | 'email' => '[email protected]', | ||
| 327 | 'manager_id' => null, | ||
| 328 | ]); | ||
| 329 |         $connection->insert('contact', [ | ||
| 330 | 'id' => 2, | ||
| 331 | 'email' => '[email protected]', | ||
| 332 | 'manager_id' => null, | ||
| 333 | ]); | ||
| 334 |         $connection->insert('contact', [ | ||
| 335 | 'id' => 3, | ||
| 336 | 'email' => '[email protected]', | ||
| 337 | 'manager_id' => null, | ||
| 338 | ]); | ||
| 339 |         $connection->insert('contact', [ | ||
| 340 | 'id' => 4, | ||
| 341 | 'email' => '[email protected]', | ||
| 342 | 'manager_id' => 1, | ||
| 343 | ]); | ||
| 344 | |||
| 345 |         $connection->insert('rights', [ | ||
| 346 | 'label' => 'CAN_SING', | ||
| 347 | ]); | ||
| 348 |         $connection->insert('rights', [ | ||
| 349 | 'label' => 'CAN_WRITE', | ||
| 350 | ]); | ||
| 351 | |||
| 352 |         $connection->insert('roles', [ | ||
| 353 | 'name' => 'Admins', | ||
| 354 | 'created_at' => '2015-10-24' | ||
| 355 | ]); | ||
| 356 |         $connection->insert('roles', [ | ||
| 357 | 'name' => 'Writers', | ||
| 358 | 'created_at' => '2015-10-24' | ||
| 359 | ]); | ||
| 360 |         $connection->insert('roles', [ | ||
| 361 | 'name' => 'Singers', | ||
| 362 | 'created_at' => '2015-10-24' | ||
| 363 | ]); | ||
| 364 | |||
| 365 |         $connection->insert('roles_rights', [ | ||
| 366 | 'role_id' => 1, | ||
| 367 | 'right_label' => 'CAN_SING' | ||
| 368 | ]); | ||
| 369 |         $connection->insert('roles_rights', [ | ||
| 370 | 'role_id' => 3, | ||
| 371 | 'right_label' => 'CAN_SING' | ||
| 372 | ]); | ||
| 373 |         $connection->insert('roles_rights', [ | ||
| 374 | 'role_id' => 1, | ||
| 375 | 'right_label' => 'CAN_WRITE' | ||
| 376 | ]); | ||
| 377 |         $connection->insert('roles_rights', [ | ||
| 378 | 'role_id' => 2, | ||
| 379 | 'right_label' => 'CAN_WRITE' | ||
| 380 | ]); | ||
| 381 | |||
| 382 |         $connection->insert('users', [ | ||
| 383 | 'id' => 1, | ||
| 384 | 'login' => 'john.smith', | ||
| 385 | 'password' => null, | ||
| 386 | 'status' => 'on', | ||
| 387 | 'country_id' => 2 | ||
| 388 | ]); | ||
| 389 |         $connection->insert('users', [ | ||
| 390 | 'id' => 2, | ||
| 391 | 'login' => 'jean.dupont', | ||
| 392 | 'password' => null, | ||
| 393 | 'status' => 'on', | ||
| 394 | 'country_id' => 1 | ||
| 395 | ]); | ||
| 396 |         $connection->insert('users', [ | ||
| 397 | 'id' => 3, | ||
| 398 | 'login' => 'robert.marley', | ||
| 399 | 'password' => null, | ||
| 400 | 'status' => 'off', | ||
| 401 | 'country_id' => 3 | ||
| 402 | ]); | ||
| 403 |         $connection->insert('users', [ | ||
| 404 | 'id' => 4, | ||
| 405 | 'login' => 'bill.shakespeare', | ||
| 406 | 'password' => null, | ||
| 407 | 'status' => 'off', | ||
| 408 | 'country_id' => 2 | ||
| 409 | ]); | ||
| 410 | |||
| 411 |         $connection->insert('users_roles', [ | ||
| 412 | 'user_id' => 1, | ||
| 413 | 'role_id' => 1, | ||
| 414 | ]); | ||
| 415 |         $connection->insert('users_roles', [ | ||
| 416 | 'user_id' => 2, | ||
| 417 | 'role_id' => 1, | ||
| 418 | ]); | ||
| 419 |         $connection->insert('users_roles', [ | ||
| 420 | 'user_id' => 3, | ||
| 421 | 'role_id' => 3, | ||
| 422 | ]); | ||
| 423 |         $connection->insert('users_roles', [ | ||
| 424 | 'user_id' => 4, | ||
| 425 | 'role_id' => 2, | ||
| 426 | ]); | ||
| 427 |         $connection->insert('users_roles', [ | ||
| 428 | 'user_id' => 3, | ||
| 429 | 'role_id' => 2, | ||
| 430 | ]); | ||
| 431 | } | ||
| 432 | } | ||
| 433 |