@@ -35,7 +35,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -80,10 +80,10 @@ discard block |
||
80 | 80 | * @param string $table_name |
81 | 81 | * @param callable(Schema):void|null $configure |
82 | 82 | */ |
83 | - public function __construct( string $table_name, ?callable $configure = null ) { |
|
83 | + public function __construct(string $table_name, ?callable $configure = null) { |
|
84 | 84 | $this->table_name = $table_name; |
85 | - if ( is_callable( $configure ) ) { |
|
86 | - $configure( $this ); |
|
85 | + if (is_callable($configure)) { |
|
86 | + $configure($this); |
|
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @param string|null $prefix |
111 | 111 | * @return self |
112 | 112 | */ |
113 | - public function prefix( ?string $prefix = null ): self { |
|
113 | + public function prefix(?string $prefix = null): self { |
|
114 | 114 | $this->prefix = $prefix; |
115 | 115 | return $this; |
116 | 116 | } |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | * @param string $name |
144 | 144 | * @return Column |
145 | 145 | */ |
146 | - public function column( string $name ): Column { |
|
147 | - $column = new Column( $name ); |
|
146 | + public function column(string $name): Column { |
|
147 | + $column = new Column($name); |
|
148 | 148 | |
149 | - $this->columns[ $name ] = $column; |
|
149 | + $this->columns[$name] = $column; |
|
150 | 150 | return $column; |
151 | 151 | } |
152 | 152 | |
@@ -168,11 +168,11 @@ discard block |
||
168 | 168 | * @param string $name |
169 | 169 | * @return bool |
170 | 170 | */ |
171 | - public function has_column( string $name ): bool { |
|
171 | + public function has_column(string $name): bool { |
|
172 | 172 | return count( |
173 | 173 | array_filter( |
174 | 174 | $this->get_columns(), |
175 | - function( Column $column ) use ( $name ): bool { |
|
175 | + function(Column $column) use ($name): bool { |
|
176 | 176 | return $column->get_name() === $name; |
177 | 177 | } |
178 | 178 | ) |
@@ -187,12 +187,12 @@ discard block |
||
187 | 187 | * @return self |
188 | 188 | * @throws Schema_Exception (301) If column doesn't exist. |
189 | 189 | */ |
190 | - public function remove_column( string $name ): self { |
|
191 | - if ( ! $this->has_column( $name ) ) { |
|
192 | - throw Schema_Exception::column_not_exist( $this, $name ); |
|
190 | + public function remove_column(string $name): self { |
|
191 | + if ( ! $this->has_column($name)) { |
|
192 | + throw Schema_Exception::column_not_exist($this, $name); |
|
193 | 193 | } |
194 | 194 | |
195 | - unset( $this->columns[ $name ] ); |
|
195 | + unset($this->columns[$name]); |
|
196 | 196 | |
197 | 197 | return $this; |
198 | 198 | } |
@@ -205,8 +205,8 @@ discard block |
||
205 | 205 | * @param string|null $key_name if not set, will use the column name a tempalte. |
206 | 206 | * @return \PinkCrab\Table_Builder\Foreign_Key |
207 | 207 | */ |
208 | - public function foreign_key( string $column, ?string $key_name = null ): Foreign_Key { |
|
209 | - $foreign_key = new Foreign_Key( $column, $key_name ); |
|
208 | + public function foreign_key(string $column, ?string $key_name = null): Foreign_Key { |
|
209 | + $foreign_key = new Foreign_Key($column, $key_name); |
|
210 | 210 | |
211 | 211 | $this->foreign_keys[] = $foreign_key; |
212 | 212 | return $foreign_key; |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | * @return bool |
219 | 219 | */ |
220 | 220 | public function has_foreign_keys(): bool { |
221 | - return count( $this->foreign_keys ) !== 0; |
|
221 | + return count($this->foreign_keys) !== 0; |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | * @return bool |
239 | 239 | */ |
240 | 240 | public function has_indexes(): bool { |
241 | - return count( $this->indexes ) !== 0; |
|
241 | + return count($this->indexes) !== 0; |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -248,8 +248,8 @@ discard block |
||
248 | 248 | * @param string $key_name |
249 | 249 | * @return \PinkCrab\Table_Builder\Index |
250 | 250 | */ |
251 | - public function index( string $column, ?string $key_name = null ): Index { |
|
252 | - $index = new Index( $column, $key_name ); |
|
251 | + public function index(string $column, ?string $key_name = null): Index { |
|
252 | + $index = new Index($column, $key_name); |
|
253 | 253 | |
254 | 254 | $this->indexes[] = $index; |
255 | 255 | return $index; |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | ?Throwable $previous = null |
46 | 46 | ) { |
47 | 47 | $this->schema = $schema; |
48 | - parent::__construct( $message, $code, $previous ); |
|
48 | + parent::__construct($message, $code, $previous); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -64,10 +64,10 @@ discard block |
||
64 | 64 | * @param string $column |
65 | 65 | * @return Schema_Exception |
66 | 66 | */ |
67 | - public static function column_not_exist( Schema $schema, string $column ): Schema_Exception { |
|
67 | + public static function column_not_exist(Schema $schema, string $column): Schema_Exception { |
|
68 | 68 | return new Schema_Exception( |
69 | 69 | $schema, |
70 | - \sprintf( 'column with name %s is not currently defined', $column ), |
|
70 | + \sprintf('column with name %s is not currently defined', $column), |
|
71 | 71 | 301 |
72 | 72 | ); |
73 | 73 | } |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | ) { |
62 | 62 | $this->schema = $schema; |
63 | 63 | $this->validation_errors = $validation_errors; |
64 | - parent::__construct( $message, $code, $previous ); |
|
64 | + parent::__construct($message, $code, $previous); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -72,11 +72,11 @@ discard block |
||
72 | 72 | * @return WPDB_Validator_Exception |
73 | 73 | * @code 201 |
74 | 74 | */ |
75 | - public static function failed_validation( Schema $schema, array $errors ): WPDB_Validator_Exception { |
|
75 | + public static function failed_validation(Schema $schema, array $errors): WPDB_Validator_Exception { |
|
76 | 76 | return new WPDB_Validator_Exception( |
77 | 77 | $schema, |
78 | 78 | $errors, |
79 | - sprintf( '%s failed with %d errors', $schema->get_table_name(), count( $errors ) ), |
|
79 | + sprintf('%s failed with %d errors', $schema->get_table_name(), count($errors)), |
|
80 | 80 | 201 |
81 | 81 | ); |
82 | 82 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | ?Throwable $previous = null |
46 | 46 | ) { |
47 | 47 | $this->schema = $schema; |
48 | - parent::__construct( $message, $code, $previous ); |
|
48 | + parent::__construct($message, $code, $previous); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | * @return Engine_Exception |
66 | 66 | * @code 101 |
67 | 67 | */ |
68 | - public static function create_table( Schema $schema, string $error ): Engine_Exception { |
|
69 | - return new self( $schema, $error, 101 ); |
|
68 | + public static function create_table(Schema $schema, string $error): Engine_Exception { |
|
69 | + return new self($schema, $error, 101); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @return Engine_Exception |
78 | 78 | * @code 102 |
79 | 79 | */ |
80 | - public static function drop_table( Schema $schema, string $error ): Engine_Exception { |
|
81 | - return new self( $schema, $error, 102 ); |
|
80 | + public static function drop_table(Schema $schema, string $error): Engine_Exception { |
|
81 | + return new self($schema, $error, 102); |
|
82 | 82 | } |
83 | 83 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | protected $unsigned = null; |
102 | 102 | |
103 | - public function __construct( string $name ) { |
|
103 | + public function __construct(string $name) { |
|
104 | 104 | $this->name = $name; |
105 | 105 | } |
106 | 106 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @param string $type |
111 | 111 | * @return self |
112 | 112 | */ |
113 | - public function type( string $type ): self { |
|
113 | + public function type(string $type): self { |
|
114 | 114 | $this->type = $type; |
115 | 115 | return $this; |
116 | 116 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * @param integer $length |
122 | 122 | * @return self |
123 | 123 | */ |
124 | - public function length( int $length ): self { |
|
124 | + public function length(int $length): self { |
|
125 | 125 | $this->length = $length; |
126 | 126 | return $this; |
127 | 127 | } |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * @param integer $precision |
135 | 135 | * @return self |
136 | 136 | */ |
137 | - public function precision( int $precision ): self { |
|
137 | + public function precision(int $precision): self { |
|
138 | 138 | $this->precision = $precision; |
139 | 139 | return $this; |
140 | 140 | } |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * @param boolean $nullable |
146 | 146 | * @return self |
147 | 147 | */ |
148 | - public function nullable( bool $nullable = true ): self { |
|
148 | + public function nullable(bool $nullable = true): self { |
|
149 | 149 | $this->nullable = $nullable; |
150 | 150 | return $this; |
151 | 151 | } |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * @param mixed $default |
157 | 157 | * @return self |
158 | 158 | */ |
159 | - public function default( $default ): self { |
|
159 | + public function default($default): self { |
|
160 | 160 | $this->default = $default; |
161 | 161 | return $this; |
162 | 162 | } |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | * @param boolean $auto_increment |
168 | 168 | * @return self |
169 | 169 | */ |
170 | - public function auto_increment( bool $auto_increment = true ): self { |
|
170 | + public function auto_increment(bool $auto_increment = true): self { |
|
171 | 171 | $this->auto_increment = $auto_increment; |
172 | 172 | return $this; |
173 | 173 | } |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * @param boolean $unsigned |
179 | 179 | * @return self |
180 | 180 | */ |
181 | - public function unsigned( bool $unsigned = true ): self { |
|
181 | + public function unsigned(bool $unsigned = true): self { |
|
182 | 182 | $this->unsigned = $unsigned; |
183 | 183 | return $this; |
184 | 184 | } |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | */ |
68 | 68 | protected $primary = false; |
69 | 69 | |
70 | - public function __construct( string $column, ?string $key_name = null ) { |
|
71 | - $this->key_name = $key_name ?? 'ix_' . $column; |
|
70 | + public function __construct(string $column, ?string $key_name = null) { |
|
71 | + $this->key_name = $key_name ?? 'ix_'.$column; |
|
72 | 72 | $this->column = $column; |
73 | 73 | } |
74 | 74 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @param bool $primary is primary key |
79 | 79 | * @return self |
80 | 80 | */ |
81 | - public function primary( bool $primary = true ): self { |
|
81 | + public function primary(bool $primary = true): self { |
|
82 | 82 | $this->primary = $primary; |
83 | 83 | return $this; |
84 | 84 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @param boolean $unique |
91 | 91 | * @return self |
92 | 92 | */ |
93 | - public function unique( bool $unique = true ): self { |
|
93 | + public function unique(bool $unique = true): self { |
|
94 | 94 | $this->unique = $unique; |
95 | 95 | return $this; |
96 | 96 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | * @param boolean $full_text |
103 | 103 | * @return self |
104 | 104 | */ |
105 | - public function full_text( bool $full_text = true ): self { |
|
105 | + public function full_text(bool $full_text = true): self { |
|
106 | 106 | $this->full_text = $full_text; |
107 | 107 | return $this; |
108 | 108 | } |
@@ -174,11 +174,11 @@ discard block |
||
174 | 174 | * @return string |
175 | 175 | */ |
176 | 176 | public function get_type(): string { |
177 | - if ( $this->is_primary() ) { |
|
177 | + if ($this->is_primary()) { |
|
178 | 178 | return 'primary'; |
179 | - } elseif ( $this->is_unique() ) { |
|
179 | + } elseif ($this->is_unique()) { |
|
180 | 180 | return 'unique'; |
181 | - } elseif ( $this->is_full_text() ) { |
|
181 | + } elseif ($this->is_full_text()) { |
|
182 | 182 | return 'fulltext'; |
183 | 183 | } else { |
184 | 184 | return ''; |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | */ |
64 | 64 | protected $schema; |
65 | 65 | |
66 | - public function __construct( \wpdb $wpdb ) { |
|
66 | + public function __construct(\wpdb $wpdb) { |
|
67 | 67 | $this->wpdb = $wpdb; |
68 | 68 | |
69 | 69 | // Set the translator and valiator |
@@ -78,10 +78,10 @@ discard block |
||
78 | 78 | * @return void |
79 | 79 | * @throws WPDB_Validator_Exception if fails validation (code 201) |
80 | 80 | */ |
81 | - private function set_query_for_create( Schema $schema ): void { |
|
81 | + private function set_query_for_create(Schema $schema): void { |
|
82 | 82 | $this->schema = $schema; |
83 | 83 | |
84 | - if ( ! $this->validator->validate( $schema ) ) { |
|
84 | + if ( ! $this->validator->validate($schema)) { |
|
85 | 85 | throw WPDB_Validator_Exception::failed_validation( |
86 | 86 | $schema, |
87 | 87 | $this->validator->get_errors() |
@@ -98,26 +98,26 @@ discard block |
||
98 | 98 | * @throws WPDB_Validator_Exception if fails validation (code 201) |
99 | 99 | * @throws Engine_Exception If errors thrown creating table (code 101) |
100 | 100 | */ |
101 | - public function create_table( Schema $schema ): bool { |
|
101 | + public function create_table(Schema $schema): bool { |
|
102 | 102 | |
103 | 103 | // Generate the query from the passed schema. |
104 | - $query = $this->create_table_query( $schema ); |
|
104 | + $query = $this->create_table_query($schema); |
|
105 | 105 | |
106 | 106 | // Include WP dbDelta. |
107 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
107 | + require_once ABSPATH.'wp-admin/includes/upgrade.php'; |
|
108 | 108 | |
109 | 109 | \ob_start(); |
110 | - dbDelta( $query ); |
|
110 | + dbDelta($query); |
|
111 | 111 | $output = \ob_get_clean(); |
112 | 112 | |
113 | 113 | // If output captured, throw. |
114 | - if ( '' !== $output ) { |
|
115 | - throw Engine_Exception::create_table( $schema, $output ?: '' ); |
|
114 | + if ('' !== $output) { |
|
115 | + throw Engine_Exception::create_table($schema, $output ?: ''); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | // Throw if WPDB has errors. |
119 | - if ( '' !== $this->wpdb->last_error ) { |
|
120 | - throw Engine_Exception::create_table( $schema, $this->wpdb->last_error ); |
|
119 | + if ('' !== $this->wpdb->last_error) { |
|
120 | + throw Engine_Exception::create_table($schema, $this->wpdb->last_error); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | return true; |
@@ -130,8 +130,8 @@ discard block |
||
130 | 130 | * @return string |
131 | 131 | * @throws WPDB_Validator_Exception if fails validation (code 201) |
132 | 132 | */ |
133 | - public function create_table_query( Schema $schema ): string { |
|
134 | - $this->set_query_for_create( $schema ); |
|
133 | + public function create_table_query(Schema $schema): string { |
|
134 | + $this->set_query_for_create($schema); |
|
135 | 135 | return $this->compile_create_sql_query(); |
136 | 136 | } |
137 | 137 | |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | * @return void |
143 | 143 | * @throws WPDB_Validator_Exception If fails schema validation (code 201) |
144 | 144 | */ |
145 | - private function set_query_for_drop( Schema $schema ): void { |
|
145 | + private function set_query_for_drop(Schema $schema): void { |
|
146 | 146 | $this->schema = $schema; |
147 | 147 | |
148 | - if ( ! $this->validator->validate( $schema ) ) { |
|
149 | - throw WPDB_Validator_Exception::failed_validation( $schema, $this->validator->get_errors() ); |
|
148 | + if ( ! $this->validator->validate($schema)) { |
|
149 | + throw WPDB_Validator_Exception::failed_validation($schema, $this->validator->get_errors()); |
|
150 | 150 | } |
151 | 151 | } |
152 | 152 | |
@@ -158,22 +158,22 @@ discard block |
||
158 | 158 | * @throws WPDB_Validator_Exception If fails schema validation (code 201) |
159 | 159 | * @throws Engine_Exception If error thrown dropping table. (code 102) |
160 | 160 | */ |
161 | - public function drop_table( Schema $schema ): bool { |
|
161 | + public function drop_table(Schema $schema): bool { |
|
162 | 162 | |
163 | - $query = $this->drop_table_query( $schema ); |
|
163 | + $query = $this->drop_table_query($schema); |
|
164 | 164 | |
165 | 165 | \ob_start(); |
166 | - $this->wpdb->get_results( $query ); // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared |
|
166 | + $this->wpdb->get_results($query); // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared |
|
167 | 167 | $output = \ob_get_clean(); |
168 | 168 | |
169 | 169 | // If output captured, throw. |
170 | - if ( '' !== $output ) { |
|
171 | - throw Engine_Exception::drop_table( $schema, $output ?: '' ); |
|
170 | + if ('' !== $output) { |
|
171 | + throw Engine_Exception::drop_table($schema, $output ?: ''); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | // Throw if WPDB has errors. |
175 | - if ( '' !== $this->wpdb->last_error ) { |
|
176 | - throw Engine_Exception::drop_table( $schema, $this->wpdb->last_error ); |
|
175 | + if ('' !== $this->wpdb->last_error) { |
|
176 | + throw Engine_Exception::drop_table($schema, $this->wpdb->last_error); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | return true; |
@@ -186,8 +186,8 @@ discard block |
||
186 | 186 | * @return string |
187 | 187 | * @throws WPDB_Validator_Exception If fails schema validation (code 201) |
188 | 188 | */ |
189 | - public function drop_table_query( Schema $schema ): string { |
|
190 | - $this->set_query_for_drop( $schema ); |
|
189 | + public function drop_table_query(Schema $schema): string { |
|
190 | + $this->set_query_for_drop($schema); |
|
191 | 191 | return "DROP TABLE IF EXISTS {$this->schema->get_table_name()};"; |
192 | 192 | } |
193 | 193 | |
@@ -201,10 +201,10 @@ discard block |
||
201 | 201 | // Compile query partials. |
202 | 202 | $table = $this->schema->get_table_name(); |
203 | 203 | $body = join( |
204 | - ',' . PHP_EOL, |
|
204 | + ','.PHP_EOL, |
|
205 | 205 | array_merge( |
206 | - $this->translator->translate_columns( $this->schema ), |
|
207 | - $this->translator->translate_indexes( $this->schema ) |
|
206 | + $this->translator->translate_columns($this->schema), |
|
207 | + $this->translator->translate_indexes($this->schema) |
|
208 | 208 | ) |
209 | 209 | ); |
210 | 210 | $collate = $this->wpdb->collate; |
@@ -38,18 +38,18 @@ discard block |
||
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(), $column->get_precision() ), |
|
48 | + $this->type_mapper($column->get_type() ?? '', $column->get_length(), $column->get_precision()), |
|
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 |
||
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 |
||
78 | 78 | * @param int|null $length |
79 | 79 | * @return string |
80 | 80 | */ |
81 | - protected function type_mapper( string $type, ?int $length, ?int $precision ): string { |
|
82 | - $type = strtoupper( $type ); |
|
83 | - switch ( $type ) { |
|
81 | + protected function type_mapper(string $type, ?int $length, ?int $precision): string { |
|
82 | + $type = strtoupper($type); |
|
83 | + switch ($type) { |
|
84 | 84 | // With length |
85 | 85 | case 'CHAR': |
86 | 86 | case 'VARCHAR': |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | case 'DATETIME': |
101 | 101 | case 'TIMESTAMP': |
102 | 102 | case 'TIME': |
103 | - return is_null( $length ) ? $type : "{$type}({$length})"; |
|
103 | + return is_null($length) ? $type : "{$type}({$length})"; |
|
104 | 104 | |
105 | 105 | // Floats |
106 | 106 | case 'FLOAT': |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | case 'DECIMAL': |
110 | 110 | case 'DEC': |
111 | 111 | $precision = $precision ?? 1; |
112 | - return is_null( $length ) ? $type : "{$type}({$length},{$precision})"; |
|
112 | + return is_null($length) ? $type : "{$type}({$length},{$precision})"; |
|
113 | 113 | |
114 | 114 | default: |
115 | 115 | return $type; |
@@ -123,15 +123,15 @@ discard block |
||
123 | 123 | * @param mixed|null $default |
124 | 124 | * @return string |
125 | 125 | */ |
126 | - protected function parse_default( string $type, $default ): string { |
|
127 | - if ( is_null( $default ) ) { |
|
126 | + protected function parse_default(string $type, $default): string { |
|
127 | + if (is_null($default)) { |
|
128 | 128 | return ''; |
129 | 129 | } |
130 | 130 | |
131 | - $type = strtoupper( $type ); |
|
131 | + $type = strtoupper($type); |
|
132 | 132 | |
133 | 133 | // String values. |
134 | - if ( in_array( $type, array( 'JSON', 'CHAR', 'VARCHAR', 'BINARY', 'VARBINARY', 'TEXT', 'BLOB' ), true ) ) { |
|
134 | + if (in_array($type, array('JSON', 'CHAR', 'VARCHAR', 'BINARY', 'VARBINARY', 'TEXT', 'BLOB'), true)) { |
|
135 | 135 | return " DEFAULT '{$default}'"; |
136 | 136 | } |
137 | 137 | |
@@ -146,14 +146,14 @@ discard block |
||
146 | 146 | * @param \PinkCrab\Table_Builder\Schema $schema |
147 | 147 | * @return array<string> |
148 | 148 | */ |
149 | - protected function transform_primary( Schema $schema ): array { |
|
149 | + protected function transform_primary(Schema $schema): array { |
|
150 | 150 | return array_map( |
151 | - function( $index ) { |
|
151 | + function($index) { |
|
152 | 152 | return "PRIMARY KEY ({$index->get_column()})"; |
153 | 153 | }, |
154 | 154 | array_filter( |
155 | 155 | $schema->get_indexes(), |
156 | - function( $index ): bool { |
|
156 | + function($index): bool { |
|
157 | 157 | return $index->is_primary(); |
158 | 158 | } |
159 | 159 | ) |
@@ -166,16 +166,16 @@ discard block |
||
166 | 166 | * @param \PinkCrab\Table_Builder\Schema $schema |
167 | 167 | * @return array<string> |
168 | 168 | */ |
169 | - protected function transform_indexes( Schema $schema ): array { |
|
169 | + protected function transform_indexes(Schema $schema): array { |
|
170 | 170 | return array_map( |
171 | 171 | /** @param Index[] $index_group */ |
172 | - function( array $index_group ): string { |
|
172 | + function(array $index_group): string { |
|
173 | 173 | |
174 | 174 | // Extract all parts from group. |
175 | 175 | $key_name = $index_group[0]->get_key_name(); |
176 | 176 | $index_type = $index_group[0]->get_type(); |
177 | 177 | $columns = array_map( |
178 | - function( $e ) { |
|
178 | + function($e) { |
|
179 | 179 | return $e->get_column(); |
180 | 180 | }, |
181 | 181 | $index_group |
@@ -183,13 +183,13 @@ discard block |
||
183 | 183 | |
184 | 184 | return sprintf( |
185 | 185 | '%sINDEX %s (%s)', |
186 | - \strlen( $index_type ) !== 0 ? \strtoupper( $index_type ) . ' ' : '', |
|
186 | + \strlen($index_type) !== 0 ? \strtoupper($index_type).' ' : '', |
|
187 | 187 | $key_name, |
188 | - join( ', ', $columns ) |
|
188 | + join(', ', $columns) |
|
189 | 189 | ); |
190 | 190 | |
191 | 191 | }, |
192 | - $this->group_indexes( $schema ) |
|
192 | + $this->group_indexes($schema) |
|
193 | 193 | ); |
194 | 194 | } |
195 | 195 | |
@@ -199,17 +199,17 @@ discard block |
||
199 | 199 | * @param \PinkCrab\Table_Builder\Schema $schema |
200 | 200 | * @return array<string> |
201 | 201 | */ |
202 | - protected function transform_foreign_keys( Schema $schema ): array { |
|
202 | + protected function transform_foreign_keys(Schema $schema): array { |
|
203 | 203 | return array_map( |
204 | - function( Foreign_Key $foreign_key ): string { |
|
204 | + function(Foreign_Key $foreign_key): string { |
|
205 | 205 | return \sprintf( |
206 | 206 | 'FOREIGN KEY %s(%s) REFERENCES %s(%s)%s%s', |
207 | 207 | $foreign_key->get_key_name(), |
208 | 208 | $foreign_key->get_column(), |
209 | 209 | $foreign_key->get_reference_table(), |
210 | 210 | $foreign_key->get_reference_column(), |
211 | - \strlen( $foreign_key->get_on_update() ) ? " ON UPDATE {$foreign_key->get_on_update()}" : '', |
|
212 | - \strlen( $foreign_key->get_on_delete() ) ? " ON DELETE {$foreign_key->get_on_delete()}" : '' |
|
211 | + \strlen($foreign_key->get_on_update()) ? " ON UPDATE {$foreign_key->get_on_update()}" : '', |
|
212 | + \strlen($foreign_key->get_on_delete()) ? " ON DELETE {$foreign_key->get_on_delete()}" : '' |
|
213 | 213 | ); |
214 | 214 | }, |
215 | 215 | $schema->get_foreign_keys() |
@@ -222,16 +222,16 @@ discard block |
||
222 | 222 | * @param \PinkCrab\Table_Builder\Schema $schema |
223 | 223 | * @return array<string, Index[]> |
224 | 224 | */ |
225 | - protected function group_indexes( Schema $schema ): array { |
|
225 | + protected function group_indexes(Schema $schema): array { |
|
226 | 226 | return array_reduce( |
227 | 227 | $schema->get_indexes(), |
228 | - function( array $carry, Index $index ): array { |
|
228 | + function(array $carry, Index $index): array { |
|
229 | 229 | // Remove all primiary keys. |
230 | - if ( $index->is_primary() ) { |
|
230 | + if ($index->is_primary()) { |
|
231 | 231 | return $carry; |
232 | 232 | } |
233 | 233 | |
234 | - $carry[ $index->get_key_name() . '_' . $index->get_type() ][] = $index; |
|
234 | + $carry[$index->get_key_name().'_'.$index->get_type()][] = $index; |
|
235 | 235 | |
236 | 236 | return $carry; |
237 | 237 | }, |