Passed
Branch master (268e27)
by Glynn
09:30
created
src/Column_Types.php 1 patch
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -36,10 +36,10 @@  discard block
 block discarded – undo
36 36
 	 * @param int|null $length
37 37
 	 * @return Column
38 38
 	 */
39
-	public function varchar( ?int $length = null ): Column {
40
-		$this->type( 'varchar' );
41
-		if ( $length ) {
42
-			$this->length( $length );
39
+	public function varchar(?int $length = null): Column {
40
+		$this->type('varchar');
41
+		if ($length) {
42
+			$this->length($length);
43 43
 		}
44 44
 		return $this;
45 45
 	}
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
 	 * @param int|null $length
52 52
 	 * @return Column
53 53
 	 */
54
-	public function text( ?int $length = null ): Column {
55
-		$this->type( 'text' );
56
-		if ( $length ) {
57
-			$this->length( $length );
54
+	public function text(?int $length = null): Column {
55
+		$this->type('text');
56
+		if ($length) {
57
+			$this->length($length);
58 58
 		}
59 59
 		return $this;
60 60
 	}
@@ -66,10 +66,10 @@  discard block
 block discarded – undo
66 66
 	 * @param int|null $length
67 67
 	 * @return Column
68 68
 	 */
69
-	public function int( ?int $length = null ): Column {
70
-		$this->type( 'int' );
71
-		if ( $length ) {
72
-			$this->length( $length );
69
+	public function int(?int $length = null): Column {
70
+		$this->type('int');
71
+		if ($length) {
72
+			$this->length($length);
73 73
 		}
74 74
 		return $this;
75 75
 	}
@@ -81,10 +81,10 @@  discard block
 block discarded – undo
81 81
 	 * @param int|null $length
82 82
 	 * @return Column
83 83
 	 */
84
-	public function float( ?int $length = null ): Column {
85
-		$this->type( 'float' );
86
-		if ( $length ) {
87
-			$this->length( $length );
84
+	public function float(?int $length = null): Column {
85
+		$this->type('float');
86
+		if ($length) {
87
+			$this->length($length);
88 88
 		}
89 89
 		return $this;
90 90
 	}
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
 	 * @param int|null $length
97 97
 	 * @return Column
98 98
 	 */
99
-	public function double( ?int $length = null ): Column {
100
-		$this->type( 'double' );
101
-		if ( $length ) {
102
-			$this->length( $length );
99
+	public function double(?int $length = null): Column {
100
+		$this->type('double');
101
+		if ($length) {
102
+			$this->length($length);
103 103
 		}
104 104
 		return $this;
105 105
 	}
@@ -111,10 +111,10 @@  discard block
 block discarded – undo
111 111
 	 * @param string|null $default
112 112
 	 * @return Column
113 113
 	 */
114
-	public function datetime( ?string $default = null ): Column {
115
-		$this->type( 'datetime' );
116
-		if ( $default ) {
117
-			$this->default( $default );
114
+	public function datetime(?string $default = null): Column {
115
+		$this->type('datetime');
116
+		if ($default) {
117
+			$this->default($default);
118 118
 		}
119 119
 		return $this;
120 120
 	}
@@ -126,10 +126,10 @@  discard block
 block discarded – undo
126 126
 	 * @param string|null $default
127 127
 	 * @return Column
128 128
 	 */
129
-	public function timestamp( ?string $default = null ): Column {
130
-		$this->type( 'timestamp' );
131
-		if ( $default ) {
132
-			$this->default( $default );
129
+	public function timestamp(?string $default = null): Column {
130
+		$this->type('timestamp');
131
+		if ($default) {
132
+			$this->default($default);
133 133
 		}
134 134
 		return $this;
135 135
 	}
@@ -141,11 +141,11 @@  discard block
 block discarded – undo
141 141
 	 * @param int|null $length
142 142
 	 * @return Column
143 143
 	 */
144
-	public function unsigned_int( ?int $length = null ): Column {
145
-		$this->type( 'int' );
144
+	public function unsigned_int(?int $length = null): Column {
145
+		$this->type('int');
146 146
 		$this->unsigned();
147
-		if ( $length ) {
148
-			$this->length( $length );
147
+		if ($length) {
148
+			$this->length($length);
149 149
 		}
150 150
 		return $this;
151 151
 	}
@@ -157,11 +157,11 @@  discard block
 block discarded – undo
157 157
 	 * @param int|null $length
158 158
 	 * @return Column
159 159
 	 */
160
-	public function unsigned_medium( ?int $length = null ): Column {
161
-		$this->type( 'mediumint' );
160
+	public function unsigned_medium(?int $length = null): Column {
161
+		$this->type('mediumint');
162 162
 		$this->unsigned();
163
-		if ( $length ) {
164
-			$this->length( $length );
163
+		if ($length) {
164
+			$this->length($length);
165 165
 		}
166 166
 		return $this;
167 167
 	}
Please login to merge, or discard this patch.
src/Schema.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -79,10 +79,10 @@  discard block
 block discarded – undo
79 79
 	 * @param string $table_name
80 80
 	 * @param callable(Schema):void|null $configure
81 81
 	 */
82
-	public function __construct( string $table_name, ?callable $configure = null ) {
82
+	public function __construct(string $table_name, ?callable $configure = null) {
83 83
 		$this->table_name = $table_name;
84
-		if ( is_callable( $configure ) ) {
85
-			$configure( $this );
84
+		if (is_callable($configure)) {
85
+			$configure($this);
86 86
 		}
87 87
 	}
88 88
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 	 * @param string|null $prefix
110 110
 	 * @return self
111 111
 	 */
112
-	public function prefix( ?string $prefix = null ): self {
112
+	public function prefix(?string $prefix = null): self {
113 113
 		$this->prefix = $prefix;
114 114
 		return $this;
115 115
 	}
@@ -142,10 +142,10 @@  discard block
 block discarded – undo
142 142
 	 * @param string $name
143 143
 	 * @return Column
144 144
 	 */
145
-	public function column( string $name ): Column {
146
-		$column = new Column( $name );
145
+	public function column(string $name): Column {
146
+		$column = new Column($name);
147 147
 
148
-		$this->columns[ $name ] = $column;
148
+		$this->columns[$name] = $column;
149 149
 		return $column;
150 150
 	}
151 151
 
@@ -167,11 +167,11 @@  discard block
 block discarded – undo
167 167
 	 * @param string $name
168 168
 	 * @return bool
169 169
 	 */
170
-	public function has_column( string $name ): bool {
170
+	public function has_column(string $name): bool {
171 171
 		return count(
172 172
 			array_filter(
173 173
 				$this->get_columns(),
174
-				function( Column $column ) use ( $name ): bool {
174
+				function(Column $column) use ($name): bool {
175 175
 					return $column->get_name() === $name;
176 176
 				}
177 177
 			)
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
 	 * @return self
187 187
 	 * @throws Exception If columnn doesnt exist.
188 188
 	 */
189
-	public function remove_column( string $name ): self {
190
-		if ( ! $this->has_column( $name ) ) {
189
+	public function remove_column(string $name): self {
190
+		if ( ! $this->has_column($name)) {
191 191
 			throw new Exception(
192 192
 				sprintf(
193 193
 					'%s doest exist in table %s',
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 			);
199 199
 		}
200 200
 
201
-		unset( $this->columns[ $name ] );
201
+		unset($this->columns[$name]);
202 202
 
203 203
 		return $this;
204 204
 	}
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
 	 * @param string|null $keyname if not set, will use the column name a tempalte.
212 212
 	 * @return \PinkCrab\Table_Builder\Foreign_Key
213 213
 	 */
214
-	public function foreign_key( string $column, ?string $keyname = null ): Foreign_Key {
215
-		$foreign_key = new Foreign_Key( $column, $keyname );
214
+	public function foreign_key(string $column, ?string $keyname = null): Foreign_Key {
215
+		$foreign_key = new Foreign_Key($column, $keyname);
216 216
 
217 217
 		$this->foreign_keys[] = $foreign_key;
218 218
 		return $foreign_key;
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 	 * @return bool
225 225
 	 */
226 226
 	public function has_foreign_keys(): bool {
227
-		return count( $this->foreign_keys ) !== 0;
227
+		return count($this->foreign_keys) !== 0;
228 228
 	}
229 229
 
230 230
 	/**
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 	 * @return bool
245 245
 	 */
246 246
 	public function has_indexes(): bool {
247
-		return count( $this->indexes ) !== 0;
247
+		return count($this->indexes) !== 0;
248 248
 	}
249 249
 
250 250
 	/**
@@ -254,8 +254,8 @@  discard block
 block discarded – undo
254 254
 	 * @param string $keyname
255 255
 	 * @return \PinkCrab\Table_Builder\Index
256 256
 	 */
257
-	public function index( string $column, ?string $keyname = null ): Index {
258
-		$index = new Index( $column, $keyname );
257
+	public function index(string $column, ?string $keyname = null): Index {
258
+		$index = new Index($column, $keyname);
259 259
 
260 260
 		$this->indexes[] = $index;
261 261
 		return $index;
Please login to merge, or discard this patch.
src/Column.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 	 */
93 93
 	protected $unsigned = null;
94 94
 
95
-	public function __construct( string $name ) {
95
+	public function __construct(string $name) {
96 96
 		$this->name = $name;
97 97
 	}
98 98
 
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	 * @param string $type
103 103
 	 * @return self
104 104
 	 */
105
-	public function type( string $type ): self {
105
+	public function type(string $type): self {
106 106
 		$this->type = $type;
107 107
 		return $this;
108 108
 	}
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 	 * @param integer $length
114 114
 	 * @return self
115 115
 	 */
116
-	public function length( int $length ): self {
116
+	public function length(int $length): self {
117 117
 		$this->length = $length;
118 118
 		return $this;
119 119
 	}
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 	 * @param boolean $nullable
125 125
 	 * @return self
126 126
 	 */
127
-	public function nullable( bool $nullable = true ): self {
127
+	public function nullable(bool $nullable = true): self {
128 128
 		$this->nullable = $nullable;
129 129
 		return $this;
130 130
 	}
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 	 * @param string $default
136 136
 	 * @return self
137 137
 	 */
138
-	public function default( string $default ): self {
138
+	public function default(string $default): self {
139 139
 		$this->default = $default;
140 140
 		return $this;
141 141
 	}
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 	 * @param boolean $auto_increment
147 147
 	 * @return self
148 148
 	 */
149
-	public function auto_increment( bool $auto_increment = true ): self {
149
+	public function auto_increment(bool $auto_increment = true): self {
150 150
 		$this->auto_increment = $auto_increment;
151 151
 		return $this;
152 152
 	}
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 	 * @param boolean $unsigned
158 158
 	 * @return self
159 159
 	 */
160
-	public function unsigned( bool $unsigned = true ): self {
160
+	public function unsigned(bool $unsigned = true): self {
161 161
 		$this->unsigned = $unsigned;
162 162
 		return $this;
163 163
 	}
Please login to merge, or discard this patch.
src/Builder.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -38,9 +38,9 @@  discard block
 block discarded – undo
38 38
 	 */
39 39
 	protected $engine;
40 40
 
41
-	public function __construct( Engine $engine, ?callable $engine_config = null ) {
41
+	public function __construct(Engine $engine, ?callable $engine_config = null) {
42 42
 		$this->engine = $engine_config
43
-			? $engine_config( $engine )
43
+			? $engine_config($engine)
44 44
 			: $engine;
45 45
 	}
46 46
 
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
 	 * @param Schema $schema
51 51
 	 * @return bool
52 52
 	 */
53
-	public function create_table( Schema $schema ): bool {
54
-		return $this->engine->create_table( $schema );
53
+	public function create_table(Schema $schema): bool {
54
+		return $this->engine->create_table($schema);
55 55
 	}
56 56
 
57 57
 	/**
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	 * @param Schema $schema
61 61
 	 * @return bool
62 62
 	 */
63
-	public function drop_table( Schema $schema ): bool {
64
-		return $this->engine->drop_table( $schema );
63
+	public function drop_table(Schema $schema): bool {
64
+		return $this->engine->drop_table($schema);
65 65
 	}
66 66
 }
Please login to merge, or discard this patch.
src/Foreign_Key.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -79,8 +79,8 @@  discard block
 block discarded – undo
79 79
 	 */
80 80
 	protected $on_delete = '';
81 81
 
82
-	public function __construct( string $column, ?string $keyname = null ) {
83
-		$this->keyname = $keyname ?? 'fk_' . $column;
82
+	public function __construct(string $column, ?string $keyname = null) {
83
+		$this->keyname = $keyname ?? 'fk_'.$column;
84 84
 		$this->column  = $column;
85 85
 	}
86 86
 
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	 * @param string $reference_column
92 92
 	 * @return self
93 93
 	 */
94
-	public function reference( string $reference_table, string $reference_column ): self {
94
+	public function reference(string $reference_table, string $reference_column): self {
95 95
 		$this->reference_column = $reference_column;
96 96
 		$this->reference_table  = $reference_table;
97 97
 		return $this;
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 	 * @param string $reference_table
105 105
 	 * @return self
106 106
 	 */
107
-	public function reference_table( string $reference_table ): self {
107
+	public function reference_table(string $reference_table): self {
108 108
 		$this->reference_table = $reference_table;
109 109
 		return $this;
110 110
 	}
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 	 * @param string $reference_column
117 117
 	 * @return self
118 118
 	 */
119
-	public function reference_column( string $reference_column ): self {
119
+	public function reference_column(string $reference_column): self {
120 120
 		$this->reference_column = $reference_column;
121 121
 		return $this;
122 122
 	}
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	 * @param string $action
129 129
 	 * @return self
130 130
 	 */
131
-	public function on_update( string $action ): self {
131
+	public function on_update(string $action): self {
132 132
 		$this->on_update = $action;
133 133
 		return $this;
134 134
 	}
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 	 * @param string $action
142 142
 	 * @return self
143 143
 	 */
144
-	public function on_delete( string $action ): self {
144
+	public function on_delete(string $action): self {
145 145
 		$this->on_delete = $action;
146 146
 		return $this;
147 147
 	}
Please login to merge, or discard this patch.
src/Engines/Engine.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	 * @param Schema $schema
36 36
 	 * @return bool
37 37
 	 */
38
-	public function create_table( Schema $schema ): bool;
38
+	public function create_table(Schema $schema): bool;
39 39
 
40 40
 	/**
41 41
 	 * Returns the query generated to create a table.
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	 * @param \PinkCrab\Table_Builder\Schema $schema
44 44
 	 * @return string
45 45
 	 */
46
-	public function create_table_query( Schema $schema ): string;
46
+	public function create_table_query(Schema $schema): string;
47 47
 
48 48
 	/**
49 49
 	 * Drops a table based on the schema passed.
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	 * @param Schema $schema
52 52
 	 * @return bool
53 53
 	 */
54
-	public function drop_table( Schema $schema): bool;
54
+	public function drop_table(Schema $schema): bool;
55 55
 
56 56
 	/**
57 57
 	 * Returns the query generated to drop a table.
@@ -59,5 +59,5 @@  discard block
 block discarded – undo
59 59
 	 * @param \PinkCrab\Table_Builder\Schema $schema
60 60
 	 * @return string
61 61
 	 */
62
-	public function drop_table_query( Schema $schema ): string;
62
+	public function drop_table_query(Schema $schema): string;
63 63
 }
Please login to merge, or discard this patch.
src/Engines/WPDB_DB_Delta/DB_Delta_Engine.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	 */
62 62
 	protected $schema;
63 63
 
64
-	public function __construct( \wpdb $wpdb ) {
64
+	public function __construct(\wpdb $wpdb) {
65 65
 		$this->wpdb = $wpdb;
66 66
 
67 67
 		// Set the translator and valiator
@@ -76,15 +76,15 @@  discard block
 block discarded – undo
76 76
 	 * @return void
77 77
 	 * @throws \Exception If fails validation. (code 1)
78 78
 	 */
79
-	private function set_query_for_create( Schema $schema ): void {
79
+	private function set_query_for_create(Schema $schema): void {
80 80
 		$this->schema = $schema;
81 81
 
82
-		if ( ! $this->validator->validate( $schema ) ) {
82
+		if ( ! $this->validator->validate($schema)) {
83 83
 			throw new \Exception(
84 84
 				sprintf(
85 85
 					'Failed to create table %s as failed validation: %s',
86 86
 					$schema->get_table_name(),
87
-					join( ', ' . PHP_EOL, $this->validator->get_errors() )
87
+					join(', '.PHP_EOL, $this->validator->get_errors())
88 88
 				),
89 89
 				1
90 90
 			);
@@ -99,14 +99,14 @@  discard block
 block discarded – undo
99 99
 	 * @return bool
100 100
 	 * @throws \Exception If fails validation. (code 1)
101 101
 	 */
102
-	public function create_table( Schema $schema ): bool {
102
+	public function create_table(Schema $schema): bool {
103 103
 
104 104
 		// Generate the query from the passed schema.
105
-		$query = $this->create_table_query( $schema );
105
+		$query = $this->create_table_query($schema);
106 106
 
107 107
 		// Include WP dbDelta.
108
-		require_once ABSPATH . 'wp-admin/includes/upgrade.php';
109
-		dbDelta( $query );
108
+		require_once ABSPATH.'wp-admin/includes/upgrade.php';
109
+		dbDelta($query);
110 110
 
111 111
 		return $this->wpdb->last_error === '';
112 112
 	}
@@ -118,8 +118,8 @@  discard block
 block discarded – undo
118 118
 	 * @return string
119 119
 	 * @throws \Exception If fails validation. (code 1)
120 120
 	 */
121
-	public function create_table_query( Schema $schema ): string {
122
-		$this->set_query_for_create( $schema );
121
+	public function create_table_query(Schema $schema): string {
122
+		$this->set_query_for_create($schema);
123 123
 		return $this->compile_create_sql_query();
124 124
 	}
125 125
 
@@ -130,15 +130,15 @@  discard block
 block discarded – undo
130 130
 	 * @return void
131 131
 	 * @throws \Exception If fails validation. (code 2)
132 132
 	 */
133
-	private function set_query_for_drop( Schema $schema ): void {
133
+	private function set_query_for_drop(Schema $schema): void {
134 134
 		$this->schema = $schema;
135 135
 
136
-		if ( ! $this->validator->validate( $schema ) ) {
136
+		if ( ! $this->validator->validate($schema)) {
137 137
 			throw new \Exception(
138 138
 				sprintf(
139 139
 					'Failed to drop table %s as failed validation: %s',
140 140
 					$schema->get_table_name(),
141
-					join( ', ' . PHP_EOL, $this->validator->get_errors() )
141
+					join(', '.PHP_EOL, $this->validator->get_errors())
142 142
 				),
143 143
 				2
144 144
 			);
@@ -152,11 +152,11 @@  discard block
 block discarded – undo
152 152
 	 * @return bool
153 153
 	 * @throws \Exception If fails validation. (code 2)
154 154
 	 */
155
-	public function drop_table( Schema $schema ): bool {
155
+	public function drop_table(Schema $schema): bool {
156 156
 
157
-		$query = $this->drop_table_query( $schema );
157
+		$query = $this->drop_table_query($schema);
158 158
 
159
-		$this->wpdb->get_results( $query ); // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
159
+		$this->wpdb->get_results($query); // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
160 160
 		return $this->wpdb->last_error === '';
161 161
 	}
162 162
 
@@ -167,8 +167,8 @@  discard block
 block discarded – undo
167 167
 	 * @return string
168 168
 	 * @throws \Exception If fails validation. (code 2)
169 169
 	 */
170
-	public function drop_table_query( Schema $schema ): string {
171
-		$this->set_query_for_drop( $schema );
170
+	public function drop_table_query(Schema $schema): string {
171
+		$this->set_query_for_drop($schema);
172 172
 		return "DROP TABLE IF EXISTS {$this->schema->get_table_name()};";
173 173
 	}
174 174
 
@@ -182,10 +182,10 @@  discard block
 block discarded – undo
182 182
 		// Compile query partials.
183 183
 		$table   = $this->schema->get_table_name();
184 184
 		$body    = join(
185
-			',' . PHP_EOL,
185
+			','.PHP_EOL,
186 186
 			array_merge(
187
-				$this->translator->translate_columns( $this->schema ),
188
-				$this->translator->translate_indexes( $this->schema )
187
+				$this->translator->translate_columns($this->schema),
188
+				$this->translator->translate_indexes($this->schema)
189 189
 			)
190 190
 		);
191 191
 		$collate = $this->wpdb->collate;
Please login to merge, or discard this patch.
src/Engines/WPDB_DB_Delta/DB_Delta_Translator.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -38,18 +38,18 @@  discard block
 block discarded – undo
38 38
 	 * @param \PinkCrab\Table_Builder\Schema $schema
39 39
 	 * @return array<string>
40 40
 	 */
41
-	public function translate_columns( Schema $schema ): array {
41
+	public function translate_columns(Schema $schema): array {
42 42
 		return array_map(
43
-			function( Column $column ): string {
43
+			function(Column $column): string {
44 44
 
45 45
 				return sprintf(
46 46
 					'%s %s%s%s%s%s',
47 47
 					$column->get_name(),
48
-					$this->type_mapper( $column->get_type() ?? '', $column->get_length() ),
48
+					$this->type_mapper($column->get_type() ?? '', $column->get_length()),
49 49
 					$column->is_unsigned() ? ' UNSIGNED' : '',
50 50
 					$column->is_nullable() ? ' NULL' : ' NOT NULL',
51 51
 					$column->is_auto_increment() ? ' AUTO_INCREMENT' : '',
52
-					$this->parse_default( $column->get_type() ?? '', $column->get_default() )
52
+					$this->parse_default($column->get_type() ?? '', $column->get_default())
53 53
 				);
54 54
 			},
55 55
 			$schema->get_columns()
@@ -63,11 +63,11 @@  discard block
 block discarded – undo
63 63
 	 * @param \PinkCrab\Table_Builder\Schema $schema
64 64
 	 * @return array<string>
65 65
 	 */
66
-	public function translate_indexes( Schema $schema ): array {
66
+	public function translate_indexes(Schema $schema): array {
67 67
 		return array_merge(
68
-			$this->transform_primary( $schema ),
69
-			$this->transform_indexes( $schema ),
70
-			$this->transform_foreign_keys( $schema )
68
+			$this->transform_primary($schema),
69
+			$this->transform_indexes($schema),
70
+			$this->transform_foreign_keys($schema)
71 71
 		);
72 72
 	}
73 73
 
@@ -78,9 +78,9 @@  discard block
 block discarded – undo
78 78
 	 * @param int|null $length
79 79
 	 * @return string
80 80
 	 */
81
-	protected function type_mapper( string $type, ?int $length ): string {
82
-		$type = strtoupper( $type );
83
-		switch ( $type ) {
81
+	protected function type_mapper(string $type, ?int $length): string {
82
+		$type = strtoupper($type);
83
+		switch ($type) {
84 84
 			// With length
85 85
 			case 'CHAR':
86 86
 			case 'VARCHAR':
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 			case 'DATETIME':
107 107
 			case 'TIMESTAMP':
108 108
 			case 'TIME':
109
-				return is_null( $length ) ? $type : "{$type}({$length})";
109
+				return is_null($length) ? $type : "{$type}({$length})";
110 110
 
111 111
 			default:
112 112
 				return $type;
@@ -120,15 +120,15 @@  discard block
 block discarded – undo
120 120
 	 * @param string|null $defualt
121 121
 	 * @return string
122 122
 	 */
123
-	protected function parse_default( string $type, ?string $defualt ): string {
124
-		if ( is_null( $defualt ) ) {
123
+	protected function parse_default(string $type, ?string $defualt): string {
124
+		if (is_null($defualt)) {
125 125
 			return '';
126 126
 		}
127 127
 
128
-		$type = strtoupper( $type );
128
+		$type = strtoupper($type);
129 129
 
130 130
 		// String values.
131
-		if ( in_array( $type, array( 'CHAR', 'VARCHAR', 'BINARY', 'VARBINARY', 'TEXT', 'BLOB' ), true ) ) {
131
+		if (in_array($type, array('CHAR', 'VARCHAR', 'BINARY', 'VARBINARY', 'TEXT', 'BLOB'), true)) {
132 132
 			return " DEFAULT '{$defualt}'";
133 133
 		}
134 134
 
@@ -143,14 +143,14 @@  discard block
 block discarded – undo
143 143
 	 * @param \PinkCrab\Table_Builder\Schema $schema
144 144
 	 * @return array<string>
145 145
 	 */
146
-	protected function transform_primary( Schema $schema ): array {
146
+	protected function transform_primary(Schema $schema): array {
147 147
 		return array_map(
148
-			function( $index ) {
148
+			function($index) {
149 149
 				return "PRIMARY KEY  ({$index->get_column()})";
150 150
 			},
151 151
 			array_filter(
152 152
 				$schema->get_indexes(),
153
-				function( $index ): bool {
153
+				function($index): bool {
154 154
 					return $index->is_primary();
155 155
 				}
156 156
 			)
@@ -163,16 +163,16 @@  discard block
 block discarded – undo
163 163
 	 * @param \PinkCrab\Table_Builder\Schema $schema
164 164
 	 * @return array<string>
165 165
 	 */
166
-	protected function transform_indexes( Schema $schema ): array {
166
+	protected function transform_indexes(Schema $schema): array {
167 167
 		return array_map(
168 168
 			/** @param Index[] $index_group */
169
-			function( array $index_group ): string {
169
+			function(array $index_group): string {
170 170
 
171 171
 				// Extract all parts from group.
172 172
 				$key_name   = $index_group[0]->get_keyname();
173 173
 				$index_type = $index_group[0]->get_type();
174 174
 				$columns    = array_map(
175
-					function( $e ) {
175
+					function($e) {
176 176
 						return $e->get_column();
177 177
 					},
178 178
 					$index_group
@@ -180,13 +180,13 @@  discard block
 block discarded – undo
180 180
 
181 181
 				return sprintf(
182 182
 					'%sINDEX %s (%s)',
183
-					\strlen( $index_type ) !== 0 ? \strtoupper( $index_type ) . ' ' : '',
183
+					\strlen($index_type) !== 0 ? \strtoupper($index_type).' ' : '',
184 184
 					$key_name,
185
-					join( ', ', $columns )
185
+					join(', ', $columns)
186 186
 				);
187 187
 
188 188
 			},
189
-			$this->group_indexes( $schema )
189
+			$this->group_indexes($schema)
190 190
 		);
191 191
 	}
192 192
 
@@ -196,17 +196,17 @@  discard block
 block discarded – undo
196 196
 	 * @param \PinkCrab\Table_Builder\Schema $schema
197 197
 	 * @return array<string>
198 198
 	 */
199
-	protected function transform_foreign_keys( Schema $schema ): array {
199
+	protected function transform_foreign_keys(Schema $schema): array {
200 200
 		return array_map(
201
-			function( Foreign_Key $foreign_key ): string {
201
+			function(Foreign_Key $foreign_key): string {
202 202
 				return \sprintf(
203 203
 					'FOREIGN KEY %s(%s) REFERENCES %s(%s)%s%s',
204 204
 					$foreign_key->get_keyname(),
205 205
 					$foreign_key->get_column(),
206 206
 					$foreign_key->get_reference_table(),
207 207
 					$foreign_key->get_reference_column(),
208
-					\strlen( $foreign_key->get_on_update() ) ? " ON UPDATE {$foreign_key->get_on_update()}" : '',
209
-					\strlen( $foreign_key->get_on_delete() ) ? " ON DELETE {$foreign_key->get_on_delete()}" : ''
208
+					\strlen($foreign_key->get_on_update()) ? " ON UPDATE {$foreign_key->get_on_update()}" : '',
209
+					\strlen($foreign_key->get_on_delete()) ? " ON DELETE {$foreign_key->get_on_delete()}" : ''
210 210
 				);
211 211
 			},
212 212
 			$schema->get_foreign_keys()
@@ -219,16 +219,16 @@  discard block
 block discarded – undo
219 219
 	 * @param \PinkCrab\Table_Builder\Schema $schema
220 220
 	 * @return array<string, Index[]>
221 221
 	 */
222
-	protected function group_indexes( Schema $schema ): array {
222
+	protected function group_indexes(Schema $schema): array {
223 223
 		return array_reduce(
224 224
 			$schema->get_indexes(),
225
-			function( array $carry, Index $index ): array {
225
+			function(array $carry, Index $index): array {
226 226
 				// Remove all primiary keys.
227
-				if ( $index->is_primary() ) {
227
+				if ($index->is_primary()) {
228 228
 					return $carry;
229 229
 				}
230 230
 
231
-				$carry[ $index->get_keyname() . '_' . $index->get_type() ][] = $index;
231
+				$carry[$index->get_keyname().'_'.$index->get_type()][] = $index;
232 232
 
233 233
 				return $carry;
234 234
 			},
Please login to merge, or discard this patch.
src/Engines/WPDB_DB_Delta/DB_Delta_Validator.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -45,14 +45,14 @@  discard block
 block discarded – undo
45 45
 	 * @param Schema $schema
46 46
 	 * @return bool
47 47
 	 */
48
-	public function validate( Schema $schema ): bool {
48
+	public function validate(Schema $schema): bool {
49 49
 		// Reset errors.
50 50
 		$this->errors = array();
51 51
 
52
-		$this->validate_columns( $schema );
53
-		$this->validate_primary_key( $schema );
54
-		$this->validate_index_columns( $schema );
55
-		$this->validate_foreign_keys( $schema );
52
+		$this->validate_columns($schema);
53
+		$this->validate_primary_key($schema);
54
+		$this->validate_index_columns($schema);
55
+		$this->validate_foreign_keys($schema);
56 56
 
57 57
 		return ! $this->has_errors();
58 58
 	}
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	 * @return bool
73 73
 	 */
74 74
 	public function has_errors(): bool {
75
-		return count( $this->errors ) !== 0;
75
+		return count($this->errors) !== 0;
76 76
 	}
77 77
 
78 78
 	/**
@@ -80,11 +80,11 @@  discard block
 block discarded – undo
80 80
 	 *
81 81
 	 * @return void
82 82
 	 */
83
-	protected function validate_columns( Schema $schema ): void {
83
+	protected function validate_columns(Schema $schema): void {
84 84
 		$result = array_reduce(
85 85
 			$schema->get_columns(),
86
-			function( array $result, Column $column ): array {
87
-				if ( is_null( $column->get_type() ) ) {
86
+			function(array $result, Column $column): array {
87
+				if (is_null($column->get_type())) {
88 88
 					$result[] = $column;
89 89
 				}
90 90
 				return $result;
@@ -92,12 +92,12 @@  discard block
 block discarded – undo
92 92
 			array()
93 93
 		);
94 94
 
95
-		if ( count( $result ) !== 0 ) {
95
+		if (count($result) !== 0) {
96 96
 			$this->errors = array_merge(
97 97
 				$this->errors,
98 98
 				array_map(
99
-					function( Column $column ): string {
100
-						return \sprintf( 'Column "%s" has no type defined', $column->get_name() );
99
+					function(Column $column): string {
100
+						return \sprintf('Column "%s" has no type defined', $column->get_name());
101 101
 					},
102 102
 					$result
103 103
 				)
@@ -111,17 +111,17 @@  discard block
 block discarded – undo
111 111
 	 * @param \PinkCrab\Table_Builder\Schema $schema
112 112
 	 * @return void
113 113
 	 */
114
-	protected function validate_primary_key( Schema $schema ): void {
114
+	protected function validate_primary_key(Schema $schema): void {
115 115
 
116 116
 		$primary_keys = array_filter(
117 117
 			$schema->get_indexes(),
118
-			function( Index $index ): bool {
118
+			function(Index $index): bool {
119 119
 				return $index->is_primary();
120 120
 			}
121 121
 		);
122 122
 
123
-		if ( count( $primary_keys ) > 1 ) {
124
-			$this->errors[] = \sprintf( '%d Primary keys are defined in schema, only a single primary key can be set.', count( $primary_keys ) );
123
+		if (count($primary_keys) > 1) {
124
+			$this->errors[] = \sprintf('%d Primary keys are defined in schema, only a single primary key can be set.', count($primary_keys));
125 125
 		}
126 126
 	}
127 127
 
@@ -131,21 +131,21 @@  discard block
 block discarded – undo
131 131
 	 * @param \PinkCrab\Table_Builder\Schema $schema
132 132
 	 * @return void
133 133
 	 */
134
-	protected function validate_index_columns( Schema $schema ): void {
134
+	protected function validate_index_columns(Schema $schema): void {
135 135
 		// All defined colum names.
136
-		$column_names = array_keys( $schema->get_columns() );
136
+		$column_names = array_keys($schema->get_columns());
137 137
 
138 138
 		/** @var array<Index> */
139 139
 		$missing_columns = array_filter(
140 140
 			$schema->get_indexes(),
141
-			function( Index $index ) use ( $column_names ): bool {
142
-				return ! in_array( $index->get_column(), $column_names, true );
141
+			function(Index $index) use ($column_names): bool {
142
+				return ! in_array($index->get_column(), $column_names, true);
143 143
 			}
144 144
 		);
145 145
 
146
-		if ( count( $missing_columns ) > 0 ) {
147
-			foreach ( $missing_columns as $missing_column ) {
148
-				$this->errors[] = \sprintf( 'Index column %s not defined as a column in schema', $missing_column->get_column() );
146
+		if (count($missing_columns) > 0) {
147
+			foreach ($missing_columns as $missing_column) {
148
+				$this->errors[] = \sprintf('Index column %s not defined as a column in schema', $missing_column->get_column());
149 149
 			}
150 150
 		}
151 151
 	}
@@ -156,23 +156,23 @@  discard block
 block discarded – undo
156 156
 	 * @param \PinkCrab\Table_Builder\Schema $schema
157 157
 	 * @return void
158 158
 	 */
159
-	public function validate_foreign_keys( Schema $schema ): void {
159
+	public function validate_foreign_keys(Schema $schema): void {
160 160
 		// All defined colum names.
161
-		$column_names = array_keys( $schema->get_columns() );
161
+		$column_names = array_keys($schema->get_columns());
162 162
 
163 163
 		// Missing columns in local table
164 164
 
165 165
 		/** @var array<Foreign_Key> */
166 166
 		$missing_columns = array_filter(
167 167
 			$schema->get_foreign_keys(),
168
-			function( Foreign_Key $foreign_key ) use ( $column_names ): bool {
169
-				return ! in_array( $foreign_key->get_column(), $column_names, true );
168
+			function(Foreign_Key $foreign_key) use ($column_names): bool {
169
+				return ! in_array($foreign_key->get_column(), $column_names, true);
170 170
 			}
171 171
 		);
172 172
 
173
-		if ( count( $missing_columns ) > 0 ) {
174
-			foreach ( $missing_columns as $missing_column ) {
175
-				$this->errors[] = \sprintf( 'Foreign Keys column %s not defined as a column in schema', $missing_column->get_column() );
173
+		if (count($missing_columns) > 0) {
174
+			foreach ($missing_columns as $missing_column) {
175
+				$this->errors[] = \sprintf('Foreign Keys column %s not defined as a column in schema', $missing_column->get_column());
176 176
 			}
177 177
 		}
178 178
 
@@ -181,14 +181,14 @@  discard block
 block discarded – undo
181 181
 		/** @var array<Foreign_Key> */
182 182
 		$missing_references = array_filter(
183 183
 			$schema->get_foreign_keys(),
184
-			function( Foreign_Key $foreign_key ) : bool {
184
+			function(Foreign_Key $foreign_key) : bool {
185 185
 				return $foreign_key->get_reference_table() === null || $foreign_key->get_reference_column() === null;
186 186
 			}
187 187
 		);
188 188
 
189
-		if ( count( $missing_references ) > 0 ) {
190
-			foreach ( $missing_references as $missing_reference ) {
191
-				$this->errors[] = \sprintf( 'Foreign Keys column %s has missing reference table or column details', $missing_reference->get_keyname() );
189
+		if (count($missing_references) > 0) {
190
+			foreach ($missing_references as $missing_reference) {
191
+				$this->errors[] = \sprintf('Foreign Keys column %s has missing reference table or column details', $missing_reference->get_keyname());
192 192
 			}
193 193
 		}
194 194
 	}
Please login to merge, or discard this patch.