Conditions | 1 |
Paths | 1 |
Total Lines | 75 |
Code Lines | 49 |
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 |
||
5 | public function initInverter(\execut\yii\migration\Inverter $i) |
||
6 | { |
||
7 | $i = $this->inverter; |
||
8 | $i->createTable('import_files', array_merge($this->defaultColumns(), [ |
||
9 | 'name' => $this->string()->notNull(), |
||
10 | 'extension' => $this->string()->notNull(), |
||
11 | 'mime_type' => $this->string()->notNull(), |
||
12 | 'content' => $this->data()->notNull(), |
||
13 | 'md5' => $this->string(64)->notNull(), |
||
14 | ])); |
||
15 | $i->createTable('import_files_sources', array_merge($this->defaultColumns(), [ |
||
16 | 'name' => $this->string()->notNull(), |
||
17 | 'key' => $this->string()->notNull(), |
||
18 | ])); |
||
19 | $i->batchInsert('import_files_sources', [ |
||
20 | 'id', |
||
21 | 'name', |
||
22 | 'key', |
||
23 | ], [ |
||
24 | [ |
||
25 | 'id' => 1, |
||
26 | 'name' => 'Email', |
||
27 | 'key' => 'email', |
||
28 | ], |
||
29 | [ |
||
30 | 'id' => 2, |
||
31 | 'name' => 'Вручную', |
||
32 | 'key' => 'manual', |
||
33 | ], |
||
34 | ]); |
||
35 | |||
36 | $i->createTable('import_files_statuses', array_merge($this->defaultColumns(), [ |
||
37 | 'name' => $this->string()->notNull(), |
||
38 | 'key' => $this->string()->notNull(), |
||
39 | ])); |
||
40 | |||
41 | |||
42 | $i->table('import_files') |
||
43 | ->addForeignColumn('import_files_sources', true) |
||
44 | ->addForeignColumn('user') |
||
45 | ->addForeignColumn('import_files_statuses', true); |
||
46 | $i->batchInsert('import_files_statuses', [ |
||
47 | 'id', |
||
48 | 'name', |
||
49 | 'key', |
||
50 | ], [ |
||
51 | [ |
||
52 | 'id' => 1, |
||
53 | 'name' => 'New', |
||
54 | 'key' => 'new', |
||
55 | ], |
||
56 | [ |
||
57 | 'id' => 2, |
||
58 | 'name' => 'Reload', |
||
59 | 'key' => 'reload', |
||
60 | ], |
||
61 | [ |
||
62 | 'id' => 3, |
||
63 | 'name' => 'Delete', |
||
64 | 'key' => 'delete', |
||
65 | ], |
||
66 | [ |
||
67 | 'id' => 4, |
||
68 | 'name' => 'Loaded', |
||
69 | 'key' => 'loaded', |
||
70 | ], |
||
71 | [ |
||
72 | 'id' => 5, |
||
73 | 'name' => 'Loading', |
||
74 | 'key' => 'loading', |
||
75 | ], |
||
76 | [ |
||
77 | 'id' => 6, |
||
78 | 'name' => 'Deleting', |
||
79 | 'key' => 'deleting', |
||
80 | ] |
||
84 |