Completed
Push — master ( 6cab57...287bd7 )
by Sam
02:34
created
src/DB/Column.php 1 patch
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -144,33 +144,33 @@  discard block
 block discarded – undo
144 144
 	protected function parse_info( $info ) {
145 145
 
146 146
 		// Name.
147
-		$this->name = $info['Field'];
147
+		$this->name = $info[ 'Field' ];
148 148
 
149 149
 		// Type.
150
-		$this->parse_type( $info['Type'] );
150
+		$this->parse_type( $info[ 'Type' ] );
151 151
 
152 152
 		// Default.
153
-		$this->default_value = $info['Default'];
153
+		$this->default_value = $info[ 'Default' ];
154 154
 
155 155
 		// Primary key.
156
-		if ( 'PRI' === strtoupper( $info['Key'] ) ) {
156
+		if ( 'PRI' === strtoupper( $info[ 'Key' ] ) ) {
157 157
 			$this->is_primary_key = true;
158
-			if ( 'auto_increment' === $info['Extra'] ) {
158
+			if ( 'auto_increment' === $info[ 'Extra' ] ) {
159 159
 				$this->is_auto_increment = true;
160 160
 			}
161 161
 		}
162 162
 
163 163
 		// Unique key.
164
-		$this->is_unique = ( 'UNI' === strtoupper( $info['Key'] ) );
164
+		$this->is_unique = ( 'UNI' === strtoupper( $info[ 'Key' ] ) );
165 165
 
166 166
 		// Comment.
167
-		$this->comment = $info['Comment'];
167
+		$this->comment = $info[ 'Comment' ];
168 168
 
169 169
 		// Collation.
170
-		$this->collation = $info['Collation'];
170
+		$this->collation = $info[ 'Collation' ];
171 171
 
172 172
 		// Is this column NULL?
173
-		$this->nullable = ( 'YES' === $info['Null'] );
173
+		$this->nullable = ( 'YES' === $info[ 'Null' ] );
174 174
 
175 175
 		// Is this a foreign key?
176 176
 		if ( in_array( $this->get_name(), $this->get_table()->get_foreign_key_names(), true ) ) {
@@ -309,14 +309,14 @@  discard block
 block discarded – undo
309 309
 	public function get_xtype() {
310 310
 		$xtypes = self::get_xtypes();
311 311
 		if ( $this->is_foreign_key() ) {
312
-			return $xtypes['fk'];
312
+			return $xtypes[ 'fk' ];
313 313
 		}
314 314
 		if ( $this->is_boolean() ) {
315
-			return $xtypes['boolean'];
315
+			return $xtypes[ 'boolean' ];
316 316
 		}
317 317
 		// Otherwise fall back on the first xtype with a matching type.
318 318
 		foreach ( $xtypes as $xtype ) {
319
-			if ( strtoupper( $this->get_type() ) === $xtype['type'] ) {
319
+			if ( strtoupper( $this->get_type() ) === $xtype[ 'type' ] ) {
320 320
 				return $xtype;
321 321
 			}
322 322
 		}
@@ -516,22 +516,22 @@  discard block
 block discarded – undo
516 516
 		$this->scale = null;
517 517
 		$this->options = null;
518 518
 		if ( preg_match( $varchar_pattern, $type_string, $matches ) ) {
519
-			$this->type = $matches[1];
520
-			$this->size = (int) $matches[2];
519
+			$this->type = $matches[ 1 ];
520
+			$this->size = ( int ) $matches[ 2 ];
521 521
 		} elseif ( preg_match( $decimal_pattern, $type_string, $matches ) ) {
522 522
 			$this->type = 'decimal';
523
-			$this->precision = $matches[1];
524
-			$this->scale = $matches[2];
523
+			$this->precision = $matches[ 1 ];
524
+			$this->scale = $matches[ 2 ];
525 525
 		} elseif ( preg_match( $float_pattern, $type_string, $matches ) ) {
526 526
 			$this->type = 'float';
527
-			$this->precision = $matches[1];
528
-			$this->scale = $matches[2];
527
+			$this->precision = $matches[ 1 ];
528
+			$this->scale = $matches[ 2 ];
529 529
 		} elseif ( preg_match( $integer_pattern, $type_string, $matches ) ) {
530
-			$this->type = $matches[1];
531
-			$this->size = (int) $matches[2];
530
+			$this->type = $matches[ 1 ];
531
+			$this->size = ( int ) $matches[ 2 ];
532 532
 		} elseif ( preg_match( $enum_pattern, $type_string, $matches ) ) {
533
-			$this->type = $matches[1];
534
-			$values = explode( "','", $matches[2] );
533
+			$this->type = $matches[ 1 ];
534
+			$values = explode( "','", $matches[ 2 ] );
535 535
 			$this->options = array_combine( $values, $values );
536 536
 		}
537 537
 	}
@@ -542,14 +542,14 @@  discard block
 block discarded – undo
542 542
 	 * @return string
543 543
 	 */
544 544
 	public function __toString() {
545
-		$pk = ($this->is_primary_key) ? ' PK' : '';
546
-		$auto = ($this->is_auto_increment) ? ' AI' : '';
545
+		$pk = ( $this->is_primary_key ) ? ' PK' : '';
546
+		$auto = ( $this->is_auto_increment ) ? ' AI' : '';
547 547
 		if ( $this->references ) {
548 548
 			$ref = ' References ' . $this->references . '.';
549 549
 		} else {
550 550
 			$ref = '';
551 551
 		}
552
-		$size = ($this->size > 0) ? "($this->size)" : '';
552
+		$size = ( $this->size > 0 ) ? "($this->size)" : '';
553 553
 		return $this->name . ' ' . strtoupper( $this->type ) . $size . $pk . $auto . $ref;
554 554
 	}
555 555
 
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
 	public function get_current_column_definition() {
562 562
 		return self::get_column_definition(
563 563
 			$this->get_name(),
564
-			$this->get_xtype()['name'],
564
+			$this->get_xtype()[ 'name' ],
565 565
 			$this->get_size(),
566 566
 			$this->nullable(),
567 567
 			$this->get_default(),
@@ -589,14 +589,14 @@  discard block
 block discarded – undo
589 589
 	 */
590 590
 	public function alter( $new_name = null, $xtype_name = null, $size = null, $nullable = null, $default = null, $auto_increment = null, $unique = null, $comment = null, $target_table = null, $after = null ) {
591 591
 		// Any that have not been set explicitly should be unchanged.
592
-		$new_name = ! is_null( $new_name ) ? (string) $new_name : $this->get_name();
593
-		$xtype_name = ! is_null( $xtype_name ) ? (string) $xtype_name : $this->get_xtype()['name'];
592
+		$new_name = ! is_null( $new_name ) ? ( string ) $new_name : $this->get_name();
593
+		$xtype_name = ! is_null( $xtype_name ) ? ( string ) $xtype_name : $this->get_xtype()[ 'name' ];
594 594
 		$size = ! is_null( $size ) ? $size : $this->get_size();
595
-		$nullable = ! is_null( $nullable ) ? (boolean) $nullable : $this->nullable();
596
-		$default = ! is_null( $default ) ? (string) $default : $this->get_default();
597
-		$auto_increment = ! is_null( $auto_increment ) ? (boolean) $auto_increment : $this->is_auto_increment();
598
-		$unique = ! is_null( $unique ) ? (boolean) $unique : $this->is_unique();
599
-		$comment = ! is_null( $comment ) ? (string) $comment : $this->get_comment();
595
+		$nullable = ! is_null( $nullable ) ? ( boolean ) $nullable : $this->nullable();
596
+		$default = ! is_null( $default ) ? ( string ) $default : $this->get_default();
597
+		$auto_increment = ! is_null( $auto_increment ) ? ( boolean ) $auto_increment : $this->is_auto_increment();
598
+		$unique = ! is_null( $unique ) ? ( boolean ) $unique : $this->is_unique();
599
+		$comment = ! is_null( $comment ) ? ( string ) $comment : $this->get_comment();
600 600
 		$target_table = ! is_null( $target_table ) ? $target_table : $this->get_referenced_table();
601 601
 
602 602
 		// Check the current column definition.
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
 		if ( $this->is_unique() ) {
612 612
 			$sql = 'SHOW INDEXES FROM `' . $table->get_name() . '` WHERE Column_name LIKE "' . $this->get_name() . '"';
613 613
 			foreach ( $wpdb->get_results( $sql, ARRAY_A ) as $index ) {
614
-				$sql = "DROP INDEX `" . $index['Key_name'] . "` ON `" . $table->get_name() . "`";
614
+				$sql = "DROP INDEX `" . $index[ 'Key_name' ] . "` ON `" . $table->get_name() . "`";
615 615
 				$wpdb->query( $sql );
616 616
 			}
617 617
 		}
@@ -669,12 +669,12 @@  discard block
 block discarded – undo
669 669
 	public static function get_column_definition( $name, $xtype_name = null, $size = null, $nullable = true, $default = null, $auto_increment = null, $unique = null, $comment = null, $target_table = null, $after = null ) {
670 670
 		// Type.
671 671
 		$xtypes = self::get_xtypes();
672
-		$xtype = ( isset( $xtypes[ $xtype_name ] ) ) ? $xtypes[ $xtype_name ] : $xtypes['text_short'];
673
-		$type_str = $xtype['type'];
672
+		$xtype = ( isset( $xtypes[ $xtype_name ] ) ) ? $xtypes[ $xtype_name ] : $xtypes[ 'text_short' ];
673
+		$type_str = $xtype[ 'type' ];
674 674
 		// Size or options.
675 675
 		$size_str = '';
676
-		if ( is_numeric( $xtype['sizes'] ) && $xtype['sizes'] > 0 ) {
677
-			$size_str = '(' . ( $size ? : 50 ) . ')';
676
+		if ( is_numeric( $xtype[ 'sizes' ] ) && $xtype[ 'sizes' ] > 0 ) {
677
+			$size_str = '(' . ( $size ?: 50 ) . ')';
678 678
 		}
679 679
 		if ( 'enum' === $xtype_name ) {
680 680
 			// If not already wraped in quotes, explode and quote each option.
@@ -687,14 +687,14 @@  discard block
 block discarded – undo
687 687
 			$size_str = '(1)';
688 688
 		}
689 689
 		// Nullable.
690
-		$null_str = (true === $nullable) ? 'NULL' : 'NOT NULL';
690
+		$null_str = ( true === $nullable ) ? 'NULL' : 'NOT NULL';
691 691
 		// Default.
692 692
 		$default_str = '';
693 693
 		if ( 'text_long' !== $xtype_name ) {
694 694
 			$default_str = ! empty( $default ) ? "DEFAULT '$default'" : ( $nullable ? 'DEFAULT NULL' : '' );
695 695
 		}
696 696
 		$auto_increment_str = '';
697
-		if ( $auto_increment && 'integer' === $xtype['name'] ) {
697
+		if ( $auto_increment && 'integer' === $xtype[ 'name' ] ) {
698 698
 			$auto_increment_str = 'AUTO_INCREMENT';
699 699
 		}
700 700
 		$unique_str = $unique ? 'UNIQUE' : '';
@@ -715,7 +715,7 @@  discard block
 block discarded – undo
715 715
 				. ' (`' . $pk_col->get_name() . '`)';
716 716
 			$type_str = $pk_col->get_type();
717 717
 			$size_str = '(' . $pk_col->get_size() . ')';
718
-			$sign_str = ($pk_col->is_unsigned()) ? 'UNSIGNED' : '';
718
+			$sign_str = ( $pk_col->is_unsigned() ) ? 'UNSIGNED' : '';
719 719
 		}
720 720
 
721 721
 		// Put it all together.
Please login to merge, or discard this patch.