Conditions | 2 |
Paths | 2 |
Total Lines | 120 |
Code Lines | 80 |
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 |
||
28 | public function change() { |
||
29 | |||
30 | if ($this->hasTable("users_entity")) { |
||
31 | return; |
||
32 | } |
||
33 | |||
34 | $table = $this->table("users_entity", [ |
||
35 | 'id' => false, |
||
36 | 'primary_key' => ["guid"], |
||
37 | 'engine' => "InnoDB", |
||
38 | 'encoding' => "utf8mb4", |
||
39 | 'collation' => "utf8mb4_general_ci", |
||
40 | ]); |
||
41 | |||
42 | $table->addColumn('guid', 'integer', [ |
||
43 | 'null' => false, |
||
44 | 'limit' => MysqlAdapter::INT_BIG, |
||
45 | 'precision' => 20, |
||
46 | 'signed' => false, |
||
47 | ]); |
||
48 | |||
49 | $table->addColumn('name', 'text', [ |
||
50 | 'null' => false, |
||
51 | 'limit' => 65535, |
||
52 | ]); |
||
53 | |||
54 | $table->addColumn('username', 'string', [ |
||
55 | 'null' => false, |
||
56 | 'default' => '', |
||
57 | 'limit' => 128, |
||
58 | ]); |
||
59 | |||
60 | $table->addColumn('password_hash', 'string', [ |
||
61 | 'null' => false, |
||
62 | 'default' => '', |
||
63 | 'limit' => 255, |
||
64 | ]); |
||
65 | |||
66 | $table->addColumn('email', 'text', [ |
||
67 | 'null' => false, |
||
68 | 'limit' => 65535, |
||
69 | ]); |
||
70 | |||
71 | $table->addColumn('language', 'string', [ |
||
72 | 'null' => false, |
||
73 | 'default' => '', |
||
74 | 'limit' => 6, |
||
75 | ]); |
||
76 | |||
77 | $table->addColumn('banned', 'enum', [ |
||
78 | 'null' => false, |
||
79 | 'default' => 'no', |
||
80 | 'limit' => 3, |
||
81 | 'values' => [ |
||
82 | 'yes', |
||
83 | 'no' |
||
84 | ], |
||
85 | ]); |
||
86 | |||
87 | $table->addColumn('admin', 'enum', [ |
||
88 | 'null' => false, |
||
89 | 'default' => 'no', |
||
90 | 'limit' => 3, |
||
91 | 'values' => [ |
||
92 | 'yes', |
||
93 | 'no' |
||
94 | ], |
||
95 | ]); |
||
96 | |||
97 | $table->addColumn('last_action', 'integer', [ |
||
98 | 'null' => false, |
||
99 | 'default' => '0', |
||
100 | 'limit' => MysqlAdapter::INT_REGULAR, |
||
101 | 'precision' => 10, |
||
102 | ]); |
||
103 | |||
104 | $table->addColumn('prev_last_action', 'integer', [ |
||
105 | 'null' => false, |
||
106 | 'default' => '0', |
||
107 | 'limit' => MysqlAdapter::INT_REGULAR, |
||
108 | 'precision' => 10, |
||
109 | ]); |
||
110 | |||
111 | $table->addColumn('last_login', 'integer', [ |
||
112 | 'null' => false, |
||
113 | 'default' => '0', |
||
114 | 'limit' => MysqlAdapter::INT_REGULAR, |
||
115 | 'precision' => 10, |
||
116 | ]); |
||
117 | |||
118 | $table->addColumn('prev_last_login', 'integer', [ |
||
119 | 'null' => false, |
||
120 | 'default' => '0', |
||
121 | 'limit' => MysqlAdapter::INT_REGULAR, |
||
122 | 'precision' => 10, |
||
123 | ]); |
||
124 | |||
125 | $table->addIndex(['username'], [ |
||
126 | 'name' => "username", |
||
127 | 'unique' => true, |
||
128 | ]); |
||
129 | |||
130 | $table->addIndex(['email'], [ |
||
131 | 'name' => "email", |
||
132 | 'unique' => false, |
||
133 | 'limit' => 50, |
||
134 | ]); |
||
135 | |||
136 | $table->addIndex(['last_login'], [ |
||
137 | 'name' => "last_login", |
||
138 | 'unique' => false, |
||
139 | ]); |
||
140 | |||
141 | $table->addIndex(['admin'], [ |
||
142 | 'name' => "admin", |
||
143 | 'unique' => false |
||
144 | ]); |
||
145 | |||
146 | $table->save(); |
||
147 | } |
||
148 | } |
||
149 |