| Conditions | 5 |
| Paths | 16 |
| Total Lines | 55 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 45 |
| CRAP Score | 5 |
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 |
||
| 18 | 201 | public function up() |
|
| 19 | { |
||
| 20 | 201 | ob_start(); |
|
| 21 | 201 | $tableOptions = null; |
|
| 22 | 201 | if ($this->db->driverName === 'mysql') { |
|
| 23 | // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci |
||
| 24 | 67 | $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; |
|
| 25 | 67 | } |
|
| 26 | |||
| 27 | // tree |
||
| 28 | 201 | if ($this->db->getTableSchema('{{%tree}}', true) !== null) { |
|
| 29 | 197 | $this->dropTable('{{%tree}}'); |
|
| 30 | 197 | } |
|
| 31 | 201 | $this->createTable('{{%tree}}', [ |
|
| 32 | 201 | 'id' => Schema::TYPE_PK, |
|
| 33 | 201 | 'path' => Schema::TYPE_STRING . ' NULL', |
|
| 34 | 201 | 'depth' => Schema::TYPE_INTEGER . ' NOT NULL', |
|
| 35 | 201 | 'sort' => Schema::TYPE_INTEGER . ' NOT NULL', |
|
| 36 | 201 | 'slug' => Schema::TYPE_STRING . ' NOT NULL', |
|
| 37 | 201 | ], $tableOptions); |
|
| 38 | 201 | $this->createIndex('path', '{{%tree}}', ['path']); |
|
| 39 | |||
| 40 | // attribute mode tree |
||
| 41 | 201 | if ($this->db->getTableSchema('{{%attribute_mode_tree}}', true) !== null) { |
|
| 42 | 197 | $this->dropTable('{{%attribute_mode_tree}}'); |
|
| 43 | 197 | } |
|
| 44 | 201 | $this->createTable('{{%attribute_mode_tree}}', [ |
|
| 45 | 201 | 'id' => Schema::TYPE_PK, |
|
| 46 | 201 | 'path' => Schema::TYPE_STRING . ' NULL', |
|
| 47 | 201 | 'depth' => Schema::TYPE_INTEGER . ' NOT NULL', |
|
| 48 | 201 | 'sort' => Schema::TYPE_INTEGER . ' NOT NULL', |
|
| 49 | 201 | 'slug' => Schema::TYPE_STRING . ' NOT NULL', |
|
| 50 | 201 | ], $tableOptions); |
|
| 51 | 201 | $this->createIndex('path2', '{{%attribute_mode_tree}}', ['path']); |
|
| 52 | |||
| 53 | // multiple tree |
||
| 54 | 201 | if ($this->db->getTableSchema('{{%multiple_tree}}', true) !== null) { |
|
| 55 | 197 | $this->dropTable('{{%multiple_tree}}'); |
|
| 56 | 197 | } |
|
| 57 | 201 | $this->createTable('{{%multiple_tree}}', [ |
|
| 58 | 201 | 'id' => Schema::TYPE_PK, |
|
| 59 | 201 | 'tree' => Schema::TYPE_INTEGER . ' NULL', |
|
| 60 | 201 | 'path' => Schema::TYPE_STRING . ' NULL', |
|
| 61 | 201 | 'depth' => Schema::TYPE_INTEGER . ' NOT NULL', |
|
| 62 | 201 | 'sort' => Schema::TYPE_INTEGER . ' NOT NULL', |
|
| 63 | 201 | 'slug' => Schema::TYPE_STRING . ' NOT NULL', |
|
| 64 | 201 | ], $tableOptions); |
|
| 65 | 201 | $this->createIndex('path3', '{{%multiple_tree}}', ['tree', 'path']); |
|
| 66 | |||
| 67 | // update cache (sqlite bug) |
||
| 68 | 201 | $this->db->getSchema()->getTableSchema('{{%tree}}', true); |
|
| 69 | 201 | $this->db->getSchema()->getTableSchema('{{%attribute_mode_tree}}', true); |
|
| 70 | 201 | $this->db->getSchema()->getTableSchema('{{%multiple_tree}}', true); |
|
| 71 | 201 | ob_end_clean(); |
|
| 72 | 201 | } |
|
| 73 | } |
||
| 74 |