| Conditions | 1 |
| Paths | 1 |
| Total Lines | 58 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 98 | protected function setupTestDbData() |
||
| 99 | { |
||
| 100 | $db = Yii::$app->getDb(); |
||
| 101 | |||
| 102 | // Structure : |
||
| 103 | |||
| 104 | $db->createCommand()->createTable('{{%auth_rule}}', [ |
||
| 105 | 'name' => 'string', |
||
| 106 | 'data' => 'text', |
||
| 107 | 'created_at' => 'integer', |
||
| 108 | 'updated_at' => 'integer', |
||
| 109 | 'PRIMARY KEY (name)', |
||
| 110 | ])->execute(); |
||
| 111 | |||
| 112 | $db->createCommand()->createTable('{{%auth_item}}', [ |
||
| 113 | 'name' => 'string', |
||
| 114 | 'type' => 'integer', |
||
| 115 | 'description' => 'text', |
||
| 116 | 'rule_name' => 'string', |
||
| 117 | 'data' => 'string', |
||
| 118 | 'created_at' => 'integer', |
||
| 119 | 'updated_at' => 'integer', |
||
| 120 | 'FOREIGN KEY (rule_name) REFERENCES ' . '{{%auth_rule}}' . ' (name) ON DELETE SET NULL ON UPDATE CASCADE', |
||
| 121 | ])->execute(); |
||
| 122 | |||
| 123 | $db->createCommand()->createTable('{{%auth_item_child}}', [ |
||
| 124 | 'parent' => 'string', |
||
| 125 | 'child' => 'string', |
||
| 126 | 'PRIMARY KEY (parent, child)', |
||
| 127 | 'FOREIGN KEY (parent) REFERENCES ' . '{{%auth_item}}' . ' (name) ON DELETE CASCADE ON UPDATE CASCADE', |
||
| 128 | 'FOREIGN KEY (child) REFERENCES ' . '{{%auth_item}}' . ' (name) ON DELETE CASCADE ON UPDATE CASCADE', |
||
| 129 | ])->execute(); |
||
| 130 | |||
| 131 | $db->createCommand()->createTable('{{%auth_assignment}}', [ |
||
| 132 | 'item_name' => 'string', |
||
| 133 | 'user_id' => 'integer', |
||
| 134 | 'created_at' => 'integer', |
||
| 135 | 'PRIMARY KEY (item_name, user_id)', |
||
| 136 | 'FOREIGN KEY (item_name) REFERENCES ' . '{{%auth_item}}' . ' (name) ON DELETE CASCADE ON UPDATE CASCADE', |
||
| 137 | ])->execute(); |
||
| 138 | |||
| 139 | $db->createCommand()->createTable('{{%user}}', [ |
||
| 140 | 'id' => 'pk', |
||
| 141 | 'username' => 'string not null unique', |
||
| 142 | 'auth_key' => 'string(32) not null', |
||
| 143 | 'password_hash' => 'string not null', |
||
| 144 | 'email' => 'string not null unique', |
||
| 145 | ])->execute(); |
||
| 146 | |||
| 147 | // Data : |
||
| 148 | |||
| 149 | $db->createCommand()->insert('{{%user}}', [ |
||
| 150 | 'username' => 'demo', |
||
| 151 | 'auth_key' => Yii::$app->getSecurity()->generateRandomString(), |
||
| 152 | 'password_hash' => Yii::$app->getSecurity()->generatePasswordHash('password'), |
||
| 153 | 'email' => '[email protected]', |
||
| 154 | ])->execute(); |
||
| 155 | } |
||
| 156 | } |
||
| 157 |