@@ -87,10 +87,10 @@ discard block |
||
| 87 | 87 | * @param \PinkCrab\Table_Builder\Schema $schema |
| 88 | 88 | * @return self |
| 89 | 89 | */ |
| 90 | - public static function new_from_schema( Schema $schema ): self { |
|
| 90 | + public static function new_from_schema(Schema $schema): self { |
|
| 91 | 91 | return new self( |
| 92 | 92 | $schema->get_table_name(), |
| 93 | - self::compose_column_hash( $schema ), |
|
| 93 | + self::compose_column_hash($schema), |
|
| 94 | 94 | false, |
| 95 | 95 | new DateTimeImmutable(), |
| 96 | 96 | new DateTimeImmutable() |
@@ -103,10 +103,10 @@ discard block |
||
| 103 | 103 | * @param \DateTimeImmutable|null $updated_on |
| 104 | 104 | * @return self |
| 105 | 105 | */ |
| 106 | - public function as_updated( Schema $schema, ?DateTimeImmutable $updated_on = null ): self { |
|
| 106 | + public function as_updated(Schema $schema, ?DateTimeImmutable $updated_on = null): self { |
|
| 107 | 107 | return new self( |
| 108 | 108 | $this->table_name(), |
| 109 | - self::compose_column_hash( $schema ), |
|
| 109 | + self::compose_column_hash($schema), |
|
| 110 | 110 | $this->is_seeded(), |
| 111 | 111 | $this->created_on(), |
| 112 | 112 | $updated_on ?? new DateTimeImmutable() |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * @param \DateTimeImmutable|null $updated_on |
| 120 | 120 | * @return self |
| 121 | 121 | */ |
| 122 | - public function as_seeded( ?DateTimeImmutable $updated_on = null ): self { |
|
| 122 | + public function as_seeded(?DateTimeImmutable $updated_on = null): self { |
|
| 123 | 123 | return new self( |
| 124 | 124 | $this->table_name(), |
| 125 | 125 | $this->schema_hash(), |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * @param \PinkCrab\Table_Builder\Schema $schema |
| 136 | 136 | * @return string |
| 137 | 137 | */ |
| 138 | - public static function compose_column_hash( Schema $schema ): string { |
|
| 138 | + public static function compose_column_hash(Schema $schema): string { |
|
| 139 | 139 | $export = array( |
| 140 | 140 | 'name' => $schema->get_table_name(), |
| 141 | 141 | 'columns' => $schema->get_columns(), |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | 'foreign_keys' => $schema->get_foreign_keys(), |
| 144 | 144 | ); |
| 145 | 145 | |
| 146 | - return md5( \serialize( $export ) ?: $schema->get_table_name() ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize, Serialised to preserve types |
|
| 146 | + return md5(\serialize($export) ?: $schema->get_table_name()); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize, Serialised to preserve types |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** GETTERS */ |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | * @throws Exception If table name not defiend. |
| 54 | 54 | */ |
| 55 | 55 | public function __construct() { |
| 56 | - $this->schema = new Schema( $this->table_name, array( $this, 'schema' ) ); |
|
| 57 | - $this->seed_data = $this->seed( array() ); |
|
| 56 | + $this->schema = new Schema($this->table_name, array($this, 'schema')); |
|
| 57 | + $this->seed_data = $this->seed(array()); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | * @param Schema $schema_config |
| 64 | 64 | * @return void |
| 65 | 65 | */ |
| 66 | - abstract public function schema( Schema $schema_config ): void; |
|
| 66 | + abstract public function schema(Schema $schema_config): void; |
|
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * Defines the data to be seeded. |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * @param array<string, mixed> $seeds |
| 72 | 72 | * @return array<string, mixed> |
| 73 | 73 | */ |
| 74 | - public function seed( array $seeds ): array { |
|
| 74 | + public function seed(array $seeds): array { |
|
| 75 | 75 | return $seeds; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -36,9 +36,9 @@ discard block |
||
| 36 | 36 | * @return Migration_Exception |
| 37 | 37 | * @code 1 |
| 38 | 38 | */ |
| 39 | - public static function seed_column_doesnt_exist( string $column, string $table_name ): Migration_Exception { |
|
| 39 | + public static function seed_column_doesnt_exist(string $column, string $table_name): Migration_Exception { |
|
| 40 | 40 | return new Migration_Exception( |
| 41 | - \sprintf( 'Could not find column %s in %s schema definition', $column, $table_name ), |
|
| 41 | + \sprintf('Could not find column %s in %s schema definition', $column, $table_name), |
|
| 42 | 42 | 1 |
| 43 | 43 | ); |
| 44 | 44 | } |
@@ -51,9 +51,9 @@ discard block |
||
| 51 | 51 | * @return Migration_Exception |
| 52 | 52 | * @code 2 |
| 53 | 53 | */ |
| 54 | - public static function failed_to_insert_seed( string $wpdb_error, string $table_name ): Migration_Exception { |
|
| 54 | + public static function failed_to_insert_seed(string $wpdb_error, string $table_name): Migration_Exception { |
|
| 55 | 55 | return new Migration_Exception( |
| 56 | - \sprintf( 'Could not insert seed into %s, failed with error: %s', $table_name, $wpdb_error ), |
|
| 56 | + \sprintf('Could not insert seed into %s, failed with error: %s', $table_name, $wpdb_error), |
|
| 57 | 57 | 2 |
| 58 | 58 | ); |
| 59 | 59 | } |
@@ -65,9 +65,9 @@ discard block |
||
| 65 | 65 | * @return Migration_Exception |
| 66 | 66 | * @code 3 |
| 67 | 67 | */ |
| 68 | - public static function failed_to_drop_table( string $table_name ): Migration_Exception { |
|
| 68 | + public static function failed_to_drop_table(string $table_name): Migration_Exception { |
|
| 69 | 69 | return new Migration_Exception( |
| 70 | - \sprintf( 'Failed to drop %d', $table_name ), |
|
| 70 | + \sprintf('Failed to drop %d', $table_name), |
|
| 71 | 71 | 3 |
| 72 | 72 | ); |
| 73 | 73 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | protected $wpdb; |
| 38 | 38 | |
| 39 | - public function __construct( wpdb $wpdb ) { |
|
| 39 | + public function __construct(wpdb $wpdb) { |
|
| 40 | 40 | $this->wpdb = $wpdb; |
| 41 | 41 | } |
| 42 | 42 | |
@@ -47,11 +47,11 @@ discard block |
||
| 47 | 47 | * @param array<array<string, mixed>> $seed_data |
| 48 | 48 | * @return array<string, int> |
| 49 | 49 | */ |
| 50 | - public function seed( Schema $schema, array $seed_data ): array { |
|
| 50 | + public function seed(Schema $schema, array $seed_data): array { |
|
| 51 | 51 | $results = array(); |
| 52 | 52 | |
| 53 | - foreach ( $seed_data as $key => $seed ) { |
|
| 54 | - $results[ $key ] = $this->insert_seed( $schema, $seed ); |
|
| 53 | + foreach ($seed_data as $key => $seed) { |
|
| 54 | + $results[ $key ] = $this->insert_seed($schema, $seed); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | return $results; |
@@ -65,13 +65,13 @@ discard block |
||
| 65 | 65 | * @return int The new row ID. |
| 66 | 66 | * @throws Migration_Exception |
| 67 | 67 | */ |
| 68 | - protected function insert_seed( Schema $schema, array $seed ): int { |
|
| 68 | + protected function insert_seed(Schema $schema, array $seed): int { |
|
| 69 | 69 | // Get format for each column based on the type. |
| 70 | 70 | $format = array_map( |
| 71 | - function( string $column_name ) use ( $schema ): string { |
|
| 72 | - return $this->column_type( $schema, $column_name ); |
|
| 71 | + function(string $column_name) use ($schema): string { |
|
| 72 | + return $this->column_type($schema, $column_name); |
|
| 73 | 73 | }, |
| 74 | - array_keys( $seed ) |
|
| 74 | + array_keys($seed) |
|
| 75 | 75 | ); |
| 76 | 76 | |
| 77 | 77 | $this->wpdb->insert( |
@@ -81,8 +81,8 @@ discard block |
||
| 81 | 81 | ); |
| 82 | 82 | |
| 83 | 83 | // Check any errors inserting. |
| 84 | - if ( $this->wpdb->last_error !== '' ) { |
|
| 85 | - throw Migration_Exception::failed_to_insert_seed( $this->wpdb->last_error, $schema->get_table_name() ); |
|
| 84 | + if ($this->wpdb->last_error !== '') { |
|
| 85 | + throw Migration_Exception::failed_to_insert_seed($this->wpdb->last_error, $schema->get_table_name()); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | return $this->wpdb->insert_id; |
@@ -96,15 +96,15 @@ discard block |
||
| 96 | 96 | * @return string |
| 97 | 97 | * @throws Migration_Exception If a column cant be found. |
| 98 | 98 | */ |
| 99 | - protected function column_type( Schema $schema, string $column ): string { |
|
| 99 | + protected function column_type(Schema $schema, string $column): string { |
|
| 100 | 100 | $schema_columns = $schema->get_columns(); |
| 101 | 101 | |
| 102 | 102 | // If colum doesnt exist, thorw exception. |
| 103 | - if ( ! array_key_exists( $column, $schema_columns ) ) { |
|
| 104 | - throw Migration_Exception::seed_column_doesnt_exist( $column, $schema->get_table_name() ); |
|
| 103 | + if ( ! array_key_exists($column, $schema_columns)) { |
|
| 104 | + throw Migration_Exception::seed_column_doesnt_exist($column, $schema->get_table_name()); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - return $this->column_type_format( $schema_columns[ $column ]->get_type() ?? '' ); |
|
| 107 | + return $this->column_type_format($schema_columns[ $column ]->get_type() ?? ''); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -113,8 +113,8 @@ discard block |
||
| 113 | 113 | * @param string $type |
| 114 | 114 | * @return string |
| 115 | 115 | */ |
| 116 | - protected function column_type_format( string $type ): string { |
|
| 117 | - switch ( \strtoupper( $type ) ) { |
|
| 116 | + protected function column_type_format(string $type): string { |
|
| 117 | + switch (\strtoupper($type)) { |
|
| 118 | 118 | case 'CHAR': |
| 119 | 119 | case 'VARCHAR': |
| 120 | 120 | case 'BINARY': |
@@ -38,13 +38,13 @@ discard block |
||
| 38 | 38 | * @param \wpdb|null $wpdb Can pass custom wpdb instance |
| 39 | 39 | * @return Migration_Manager |
| 40 | 40 | */ |
| 41 | - public static function manager_with_db_delta( ?string $option_key = null, ?\wpdb $wpdb = null ): Migration_Manager { |
|
| 42 | - if ( $wpdb === null ) { |
|
| 41 | + public static function manager_with_db_delta(?string $option_key = null, ?\wpdb $wpdb = null): Migration_Manager { |
|
| 42 | + if ($wpdb === null) { |
|
| 43 | 43 | global $wpdb; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - $builder = new Builder( new DB_Delta_Engine( $wpdb ) ); |
|
| 47 | - return new Migration_Manager( $builder, $wpdb, $option_key ); |
|
| 46 | + $builder = new Builder(new DB_Delta_Engine($wpdb)); |
|
| 47 | + return new Migration_Manager($builder, $wpdb, $option_key); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * @param string|null $option_key |
| 56 | 56 | * @return \PinkCrab\DB_Migration\Log\Migration_Log_Manager |
| 57 | 57 | */ |
| 58 | - public static function migration_log( ?string $option_key = null ): Migration_Log_Manager { |
|
| 59 | - return new Migration_Log_Manager( $option_key ); |
|
| 58 | + public static function migration_log(?string $option_key = null): Migration_Log_Manager { |
|
| 59 | + return new Migration_Log_Manager($option_key); |
|
| 60 | 60 | } |
| 61 | 61 | } |
@@ -59,10 +59,10 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | protected $migration_log; |
| 61 | 61 | |
| 62 | - public function __construct( Builder $builder, wpdb $wpdb, ?string $migration_log_key = null ) { |
|
| 62 | + public function __construct(Builder $builder, wpdb $wpdb, ?string $migration_log_key = null) { |
|
| 63 | 63 | $this->builder = $builder; |
| 64 | 64 | $this->wpdb = $wpdb; |
| 65 | - $this->migration_log = new Migration_Log_Manager( $migration_log_key ); |
|
| 65 | + $this->migration_log = new Migration_Log_Manager($migration_log_key); |
|
| 66 | 66 | |
| 67 | 67 | } |
| 68 | 68 | |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * @param \PinkCrab\DB_Migration\Database_Migration $migration |
| 95 | 95 | * @return self |
| 96 | 96 | */ |
| 97 | - public function add_migration( Database_Migration $migration ): self { |
|
| 97 | + public function add_migration(Database_Migration $migration): self { |
|
| 98 | 98 | $this->migrations[ $migration->get_table_name() ] = $migration; |
| 99 | 99 | return $this; |
| 100 | 100 | } |
@@ -114,22 +114,22 @@ discard block |
||
| 114 | 114 | * @param string ...$excluded_table Table names to exclude. |
| 115 | 115 | * @return self |
| 116 | 116 | */ |
| 117 | - public function create_tables( string ...$excluded_table ): self { |
|
| 117 | + public function create_tables(string ...$excluded_table): self { |
|
| 118 | 118 | |
| 119 | 119 | // Remove excluded tables. |
| 120 | 120 | $to_create = array_filter( |
| 121 | 121 | $this->migrations, |
| 122 | - function( Database_Migration $migration ) use ( $excluded_table ): bool { |
|
| 123 | - return ! in_array( $migration->get_table_name(), $excluded_table, true ) |
|
| 124 | - && $this->migration_log->can_migrate( $migration->get_schema() ); |
|
| 122 | + function(Database_Migration $migration) use ($excluded_table): bool { |
|
| 123 | + return ! in_array($migration->get_table_name(), $excluded_table, true) |
|
| 124 | + && $this->migration_log->can_migrate($migration->get_schema()); |
|
| 125 | 125 | } |
| 126 | 126 | ); |
| 127 | 127 | |
| 128 | 128 | // Upsert Tables. |
| 129 | - foreach ( $to_create as $migration ) { |
|
| 130 | - $result = $this->builder->create_table( $migration->get_schema() ); |
|
| 131 | - if ( $result === true ) { |
|
| 132 | - $this->migration_log->upsert_migration( $migration->get_schema() ); |
|
| 129 | + foreach ($to_create as $migration) { |
|
| 130 | + $result = $this->builder->create_table($migration->get_schema()); |
|
| 131 | + if ($result === true) { |
|
| 132 | + $this->migration_log->upsert_migration($migration->get_schema()); |
|
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | |
@@ -143,23 +143,23 @@ discard block |
||
| 143 | 143 | * @param string ...$excluded_table Table names to exclude. |
| 144 | 144 | * @return self |
| 145 | 145 | */ |
| 146 | - public function seed_tables( string ...$excluded_table ): self { |
|
| 146 | + public function seed_tables(string ...$excluded_table): self { |
|
| 147 | 147 | |
| 148 | 148 | // Remove excluded tables. |
| 149 | 149 | $to_seed = array_filter( |
| 150 | 150 | $this->migrations, |
| 151 | - function( Database_Migration $migration ) use ( $excluded_table ): bool { |
|
| 152 | - return ! in_array( $migration->get_table_name(), $excluded_table, true ) |
|
| 153 | - && ! $this->migration_log->is_seeded( $migration->get_schema() ); |
|
| 151 | + function(Database_Migration $migration) use ($excluded_table): bool { |
|
| 152 | + return ! in_array($migration->get_table_name(), $excluded_table, true) |
|
| 153 | + && ! $this->migration_log->is_seeded($migration->get_schema()); |
|
| 154 | 154 | } |
| 155 | 155 | ); |
| 156 | 156 | |
| 157 | - $seeder = new Migration_Seeder( $this->wpdb ); |
|
| 157 | + $seeder = new Migration_Seeder($this->wpdb); |
|
| 158 | 158 | |
| 159 | - foreach ( $to_seed as $migration ) { |
|
| 160 | - $row = $seeder->seed( $migration->get_schema(), $migration->get_seeds() ); |
|
| 161 | - if ( count( $row ) !== 0 ) { |
|
| 162 | - $this->migration_log->mark_table_seeded( $migration->get_schema() ); |
|
| 159 | + foreach ($to_seed as $migration) { |
|
| 160 | + $row = $seeder->seed($migration->get_schema(), $migration->get_seeds()); |
|
| 161 | + if (count($row) !== 0) { |
|
| 162 | + $this->migration_log->mark_table_seeded($migration->get_schema()); |
|
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | |
@@ -172,26 +172,26 @@ discard block |
||
| 172 | 172 | * @param string ...$excluded_table Table names to exclude. |
| 173 | 173 | * @return self |
| 174 | 174 | */ |
| 175 | - public function drop_tables( string ...$excluded_table ): self { |
|
| 175 | + public function drop_tables(string ...$excluded_table): self { |
|
| 176 | 176 | // Remove excluded tables. |
| 177 | 177 | $to_seed = array_filter( |
| 178 | 178 | $this->migrations, |
| 179 | - function( Database_Migration $migration ) use ( $excluded_table ): bool { |
|
| 180 | - return ! in_array( $migration->get_table_name(), $excluded_table, true ); |
|
| 179 | + function(Database_Migration $migration) use ($excluded_table): bool { |
|
| 180 | + return ! in_array($migration->get_table_name(), $excluded_table, true); |
|
| 181 | 181 | } |
| 182 | 182 | ); |
| 183 | 183 | |
| 184 | - foreach ( $to_seed as $migration ) { |
|
| 184 | + foreach ($to_seed as $migration) { |
|
| 185 | 185 | |
| 186 | - $result = $this->builder->drop_table( $migration->get_schema() ); |
|
| 186 | + $result = $this->builder->drop_table($migration->get_schema()); |
|
| 187 | 187 | |
| 188 | 188 | // Throw exception if fails. |
| 189 | - if ( $result === false ) { |
|
| 190 | - throw Migration_Exception::failed_to_drop_table( $migration->get_table_name() ); |
|
| 189 | + if ($result === false) { |
|
| 190 | + throw Migration_Exception::failed_to_drop_table($migration->get_table_name()); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | // Remove migration from log. |
| 194 | - $this->migration_log->remove_migration( $migration->get_schema() ); |
|
| 194 | + $this->migration_log->remove_migration($migration->get_schema()); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | return $this; |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | protected $migration_details = array(); |
| 47 | 47 | |
| 48 | - public function __construct( string $option_key = null ) { |
|
| 48 | + public function __construct(string $option_key = null) { |
|
| 49 | 49 | $this->option_key = $option_key ?? 'pinkcrab_migration_log'; |
| 50 | 50 | $this->set_migration_details(); |
| 51 | 51 | } |
@@ -57,19 +57,19 @@ discard block |
||
| 57 | 57 | * @throws InvalidArgumentException If can not unserialize |
| 58 | 58 | */ |
| 59 | 59 | protected function set_migration_details(): void { |
| 60 | - $migrations = get_option( $this->option_key, null ); |
|
| 60 | + $migrations = get_option($this->option_key, null); |
|
| 61 | 61 | |
| 62 | - if ( $migrations === null ) { |
|
| 62 | + if ($migrations === null) { |
|
| 63 | 63 | return; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | // Handle errors as exceptions. |
| 67 | 67 | set_error_handler( // phpcs:ignore |
| 68 | - function ( int $errno, string $errstr ) { // phpcs:ignore |
|
| 69 | - throw new InvalidArgumentException( 'Migration details as unserialize from options, failed to be decoded.' ); |
|
| 68 | + function(int $errno, string $errstr) { // phpcs:ignore |
|
| 69 | + throw new InvalidArgumentException('Migration details as unserialize from options, failed to be decoded.'); |
|
| 70 | 70 | } |
| 71 | 71 | ); |
| 72 | - $migrations = \unserialize( $migrations ); // phpcs:ignore |
|
| 72 | + $migrations = \unserialize($migrations); // phpcs:ignore |
|
| 73 | 73 | restore_error_handler(); |
| 74 | 74 | |
| 75 | 75 | $this->migration_details = $migrations; |
@@ -81,8 +81,8 @@ discard block |
||
| 81 | 81 | * @param \PinkCrab\Table_Builder\Schema $schema |
| 82 | 82 | * @return boolean |
| 83 | 83 | */ |
| 84 | - public function has_migration( Schema $schema ): bool { |
|
| 85 | - return array_key_exists( $schema->get_table_name(), $this->migration_details ); |
|
| 84 | + public function has_migration(Schema $schema): bool { |
|
| 85 | + return array_key_exists($schema->get_table_name(), $this->migration_details); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -90,8 +90,8 @@ discard block |
||
| 90 | 90 | * |
| 91 | 91 | * @return \PinkCrab\DB_Migration\Log\Migration_Log|null |
| 92 | 92 | */ |
| 93 | - public function get_migration( Schema $schema ): ?Migration_Log { |
|
| 94 | - return $this->has_migration( $schema ) |
|
| 93 | + public function get_migration(Schema $schema): ?Migration_Log { |
|
| 94 | + return $this->has_migration($schema) |
|
| 95 | 95 | ? $this->migration_details[ $schema->get_table_name() ] |
| 96 | 96 | : null; |
| 97 | 97 | } |
@@ -102,8 +102,8 @@ discard block |
||
| 102 | 102 | * @param \PinkCrab\Table_Builder\Schema $schema |
| 103 | 103 | * @return bool |
| 104 | 104 | */ |
| 105 | - public function can_migrate( Schema $schema ): bool { |
|
| 106 | - return ! $this->check_hash( $schema ); |
|
| 105 | + public function can_migrate(Schema $schema): bool { |
|
| 106 | + return ! $this->check_hash($schema); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -112,8 +112,8 @@ discard block |
||
| 112 | 112 | * @param \PinkCrab\Table_Builder\Schema $schema |
| 113 | 113 | * @return bool |
| 114 | 114 | */ |
| 115 | - public function is_seeded( Schema $schema ): bool { |
|
| 116 | - return $this->has_migration( $schema ) |
|
| 115 | + public function is_seeded(Schema $schema): bool { |
|
| 116 | + return $this->has_migration($schema) |
|
| 117 | 117 | && $this->migration_details[ $schema->get_table_name() ]->is_seeded(); |
| 118 | 118 | } |
| 119 | 119 | |
@@ -123,15 +123,15 @@ discard block |
||
| 123 | 123 | * @param \PinkCrab\Table_Builder\Schema $schema |
| 124 | 124 | * @return bool |
| 125 | 125 | */ |
| 126 | - private function check_hash( Schema $schema ): bool { |
|
| 126 | + private function check_hash(Schema $schema): bool { |
|
| 127 | 127 | // If table doesnt exist, return false; |
| 128 | - if ( ! $this->has_migration( $schema ) ) { |
|
| 128 | + if ( ! $this->has_migration($schema)) { |
|
| 129 | 129 | return false; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - $schema_hash = Migration_Log::compose_column_hash( $schema ); |
|
| 132 | + $schema_hash = Migration_Log::compose_column_hash($schema); |
|
| 133 | 133 | $migration = $this->migration_details[ $schema->get_table_name() ]; |
| 134 | - return strcmp( $schema_hash, $migration->schema_hash() ) === 0; |
|
| 134 | + return strcmp($schema_hash, $migration->schema_hash()) === 0; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -145,20 +145,20 @@ discard block |
||
| 145 | 145 | * @param \PinkCrab\Table_Builder\Schema $schema |
| 146 | 146 | * @return self |
| 147 | 147 | */ |
| 148 | - public function upsert_migration( Schema $schema ): self { |
|
| 148 | + public function upsert_migration(Schema $schema): self { |
|
| 149 | 149 | // Update if table exists and we have a new schema defined. |
| 150 | - if ( $this->has_migration( $schema ) |
|
| 151 | - && ! $this->check_hash( $schema ) ) { |
|
| 150 | + if ($this->has_migration($schema) |
|
| 151 | + && ! $this->check_hash($schema)) { |
|
| 152 | 152 | $this->migration_details[ $schema->get_table_name() ] = |
| 153 | - $this->migration_details[ $schema->get_table_name() ]->as_updated( $schema ); |
|
| 153 | + $this->migration_details[ $schema->get_table_name() ]->as_updated($schema); |
|
| 154 | 154 | |
| 155 | 155 | $this->save(); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | // If a new hash. |
| 159 | - if ( $this->has_migration( $schema ) === false ) { |
|
| 159 | + if ($this->has_migration($schema) === false) { |
|
| 160 | 160 | $this->migration_details[ $schema->get_table_name() ] = |
| 161 | - Migration_Log::new_from_schema( $schema ); |
|
| 161 | + Migration_Log::new_from_schema($schema); |
|
| 162 | 162 | |
| 163 | 163 | $this->save(); |
| 164 | 164 | } |
@@ -172,9 +172,9 @@ discard block |
||
| 172 | 172 | * @param \PinkCrab\Table_Builder\Schema $schema |
| 173 | 173 | * @return self |
| 174 | 174 | */ |
| 175 | - public function remove_migration( Schema $schema ): self { |
|
| 176 | - if ( $this->has_migration( $schema ) ) { |
|
| 177 | - unset( $this->migration_details[ $schema->get_table_name() ] ); |
|
| 175 | + public function remove_migration(Schema $schema): self { |
|
| 176 | + if ($this->has_migration($schema)) { |
|
| 177 | + unset($this->migration_details[ $schema->get_table_name() ]); |
|
| 178 | 178 | |
| 179 | 179 | $this->save(); |
| 180 | 180 | } |
@@ -187,8 +187,8 @@ discard block |
||
| 187 | 187 | * @param \PinkCrab\Table_Builder\Schema $schema |
| 188 | 188 | * @return self |
| 189 | 189 | */ |
| 190 | - public function mark_table_seeded( Schema $schema ): self { |
|
| 191 | - if ( ! $this->is_seeded( $schema ) ) { |
|
| 190 | + public function mark_table_seeded(Schema $schema): self { |
|
| 191 | + if ( ! $this->is_seeded($schema)) { |
|
| 192 | 192 | $this->migration_details[ $schema->get_table_name() ] = |
| 193 | 193 | $this->migration_details[ $schema->get_table_name() ]->as_seeded(); |
| 194 | 194 | |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | * @return void |
| 205 | 205 | */ |
| 206 | 206 | protected function save(): void { |
| 207 | - \update_option( $this->option_key, serialize( $this->migration_details ), false ); // phpcs:ignore |
|
| 207 | + \update_option($this->option_key, serialize($this->migration_details), false); // phpcs:ignore |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -222,6 +222,6 @@ discard block |
||
| 222 | 222 | * @return void |
| 223 | 223 | */ |
| 224 | 224 | public function clear_log(): void { |
| 225 | - \delete_option( $this->option_key ); |
|
| 225 | + \delete_option($this->option_key); |
|
| 226 | 226 | } |
| 227 | 227 | } |