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

CreateRiverTable::change()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 124
Code Lines 78

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 78
nc 2
nop 0
dl 0
loc 124
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 CreateRiverTable 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("river")) {
31
			return;
32
		}
33
34
		$table = $this->table("river", [
35
			'engine' => "InnoDB",
36
			'encoding' => "utf8mb4",
37
			'collation' => "utf8mb4_general_ci",
38
		]);
39
40
		$table->addColumn('type', 'string', [
41
			'null' => false,
42
			'limit' => 8,
43
		]);
44
45
		$table->addColumn('subtype', 'string', [
46
			'null' => false,
47
			'limit' => 32,
48
		]);
49
50
		$table->addColumn('action_type', 'string', [
51
			'null' => false,
52
			'limit' => 32,
53
		]);
54
55
		$table->addColumn('access_id', 'integer', [
56
			'null' => false,
57
			'limit' => MysqlAdapter::INT_REGULAR,
58
			'precision' => 10,
59
		]);
60
61
		$table->addColumn('view', 'text', [
62
			'null' => false,
63
			'limit' => 65535,
64
		]);
65
66
		$table->addColumn('subject_guid', 'integer', [
67
			'null' => false,
68
			'limit' => MysqlAdapter::INT_BIG,
69
			'precision' => 20,
70
			'signed' => false,
71
		]);
72
73
		$table->addColumn('object_guid', 'integer', [
74
			'null' => false,
75
			'limit' => MysqlAdapter::INT_BIG,
76
			'precision' => 20,
77
			'signed' => false,
78
		]);
79
80
		$table->addColumn('target_guid', 'integer', [
81
			'null' => false,
82
			'limit' => MysqlAdapter::INT_BIG,
83
			'precision' => 20,
84
			'signed' => false,
85
		]);
86
87
		$table->addColumn('annotation_id', 'integer', [
88
			'null' => false,
89
			'limit' => MysqlAdapter::INT_REGULAR,
90
			'precision' => 10,
91
		]);
92
93
		$table->addColumn('posted', 'integer', [
94
			'null' => false,
95
			'limit' => MysqlAdapter::INT_REGULAR,
96
			'precision' => 10,
97
		]);
98
99
		$table->addColumn('enabled', 'enum', [
100
			'null' => false,
101
			'default' => 'yes',
102
			'limit' => 3,
103
			'values' => [
104
				'yes',
105
				'no'
106
			],
107
		]);
108
109
		$table->addIndex(['type'], [
110
			'name' => "type",
111
			'unique' => false,
112
		]);
113
		
114
		$table->addIndex(['action_type'], [
115
			'name' => "action_type",
116
			'unique' => false,
117
		]);
118
119
		$table->addIndex(['access_id'], [
120
			'name' => "access_id",
121
			'unique' => false,
122
		]);
123
124
		$table->addIndex(['subject_guid'], [
125
			'name' => "subject_guid",
126
			'unique' => false,
127
		]);
128
129
		$table->addIndex(['object_guid'], [
130
			'name' => "object_guid",
131
			'unique' => false,
132
		]);
133
134
		$table->addIndex(['target_guid'], [
135
			'name' => "target_guid",
136
			'unique' => false,
137
		]);
138
139
		$table->addIndex(['annotation_id'], [
140
			'name' => "annotation_id",
141
			'unique' => false,
142
		]);
143
144
		$table->addIndex(['posted'], [
145
			'name' => "posted",
146
			'unique' => false,
147
		]);
148
149
		$table->save();
150
151
	}
152
}
153