Conditions | 2 |
Paths | 4 |
Total Lines | 53 |
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 |
||
44 | public function createTestData() |
||
45 | { |
||
46 | $adminSql = <<<EOF |
||
47 | -- auto-generated definition |
||
48 | create table test_admin |
||
49 | ( |
||
50 | id int auto_increment |
||
51 | primary key, |
||
52 | auth_key varchar(125) null, |
||
53 | avatar varchar(255) null comment '头像', |
||
54 | username varchar(20) not null comment '用户名', |
||
55 | name varchar(20) not null comment '姓名', |
||
56 | email varchar(64) not null comment '邮箱', |
||
57 | password_hash varchar(64) not null comment '密码', |
||
58 | password_reset_token varchar(255) null comment '重置密码Token', |
||
59 | status tinyint(1) default '10' not null comment '状态', |
||
60 | created_at int not null comment '创建时间', |
||
61 | updated_at int not null comment '更新时间' |
||
62 | ) |
||
63 | comment '管理员'; |
||
64 | INSERT INTO test.test_admin |
||
65 | ( |
||
66 | auth_key, avatar, username, name, email, password_hash, password_reset_token, status, created_at, updated_at |
||
67 | ) |
||
68 | VALUES |
||
69 | ( |
||
70 | 'CccLhn6aqp_Y-XYh-JzfXSCfxJNkKC8w', '', 'lianluo', '管理员', '[email protected]', '$2y$13\$dbGxVyj3kglcJNUEsKyiu.5KQ9We3AqAFncYkdAS1iNRYf/RA37Ay', null, 10, 1502856859, 1502856859 |
||
71 | ); |
||
72 | EOF; |
||
73 | $userSql = <<<EOF |
||
74 | -- auto-generated definition |
||
75 | create table `test_user` |
||
76 | ( |
||
77 | `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, |
||
78 | `username` varchar(32) NOT NULL, |
||
79 | `auth_key` varchar(32) NOT NULL, |
||
80 | `password_hash` varchar(256) NOT NULL, |
||
81 | `password_reset_token` varchar(256), |
||
82 | `email` varchar(256) NOT NULL, |
||
83 | `status` integer not null default 10, |
||
84 | `created_at` integer not null, |
||
85 | `updated_at` integer not null |
||
86 | )ENGINE=InnoDB DEFAULT CHARSET=utf8; |
||
87 | EOF; |
||
88 | try { |
||
89 | $db = Yii::$app->getDb(); |
||
90 | $db->createCommand($adminSql)->execute(); |
||
91 | $db->createCommand($userSql)->execute(); |
||
92 | } catch (yii\db\Exception $e) { |
||
93 | //var_dump($e->getMessage()); |
||
94 | return; |
||
95 | } |
||
96 | } |
||
97 | |||
159 |