Completed
Push — master ( 92ff78...57630a )
by Steve
20:35 queued 09:38
created

CreateUsersEntityTable::change()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 120
Code Lines 80

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 80
nc 2
nop 0
dl 0
loc 120
rs 8.2857
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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:

1
<?php
2
3
use Phinx\Migration\AbstractMigration;
4
use Phinx\Db\Adapter\MysqlAdapter;
5
6
class CreateUsersEntityTable extends AbstractMigration {
7
	/**
8
	 * Change Method.
9
	 *
10
	 * Write your reversible migrations using this method.
11
	 *
12
	 * More information on writing migrations is available here:
13
	 * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
14
	 *
15
	 * The following commands can be used in this method and Phinx will
16
	 * automatically reverse them when rolling back:
17
	 *
18
	 *    createTable
19
	 *    renameTable
20
	 *    addColumn
21
	 *    renameColumn
22
	 *    addIndex
23
	 *    addForeignKey
24
	 *
25
	 * Remember to call "create()" or "update()" and NOT "save()" when working
26
	 * with the Table class.
27
	 */
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