@@ -72,13 +72,13 @@ discard block |
||
| 72 | 72 | * |
| 73 | 73 | * @param Plugin_State_Controller $plugin_state_controller |
| 74 | 74 | */ |
| 75 | - public function __construct( Plugin_State_Controller $plugin_state_controller, ?string $migration_log_key = null ) { |
|
| 75 | + public function __construct(Plugin_State_Controller $plugin_state_controller, ?string $migration_log_key = null) { |
|
| 76 | 76 | $this->plugin_state_controller = $plugin_state_controller; |
| 77 | 77 | $this->migration_log_key = $migration_log_key; |
| 78 | 78 | $this->di_container = $plugin_state_controller->get_app()->get_container(); |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - public function set_migration_log_key( string $log_key ): self { |
|
| 81 | + public function set_migration_log_key(string $log_key): self { |
|
| 82 | 82 | $this->migration_log_key = $log_key; |
| 83 | 83 | return $this; |
| 84 | 84 | } |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | * @param Migration_Manager $migration_manager The migration manager instance. |
| 90 | 90 | * @return self |
| 91 | 91 | */ |
| 92 | - public function set_migration_manager( Migration_Manager $migration_manager ):self { |
|
| 92 | + public function set_migration_manager(Migration_Manager $migration_manager):self { |
|
| 93 | 93 | $this->migration_manager = $migration_manager; |
| 94 | 94 | return $this; |
| 95 | 95 | } |
@@ -100,14 +100,14 @@ discard block |
||
| 100 | 100 | * @param class-string<Migration>|Migration $migration |
| 101 | 101 | * @return self |
| 102 | 102 | */ |
| 103 | - public function add_migration( $migration ): self { |
|
| 104 | - if ( ! is_subclass_of( $migration, Migration::class ) ) { |
|
| 105 | - throw Migration_Exception::none_migration_type( \serialize( $migration ) ); //phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize, used for exception messages |
|
| 103 | + public function add_migration($migration): self { |
|
| 104 | + if ( ! is_subclass_of($migration, Migration::class)) { |
|
| 105 | + throw Migration_Exception::none_migration_type(\serialize($migration)); //phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize, used for exception messages |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - $migration = $this->maybe_construct_migration( $migration ); |
|
| 109 | - if ( null === $migration ) { |
|
| 110 | - throw Migration_Exception::failed_to_construct_migration( 'Invalid after construction' ); |
|
| 108 | + $migration = $this->maybe_construct_migration($migration); |
|
| 109 | + if (null === $migration) { |
|
| 110 | + throw Migration_Exception::failed_to_construct_migration('Invalid after construction'); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | $this->migrations[] = $migration; |
@@ -120,17 +120,17 @@ discard block |
||
| 120 | 120 | * @param class-string<Migration>|Migration $migration |
| 121 | 121 | * @return Migration|null |
| 122 | 122 | */ |
| 123 | - protected function maybe_construct_migration( $migration ): ?Migration { |
|
| 124 | - if ( is_string( $migration ) ) { |
|
| 123 | + protected function maybe_construct_migration($migration): ?Migration { |
|
| 124 | + if (is_string($migration)) { |
|
| 125 | 125 | $migration_string = $migration; |
| 126 | 126 | try { |
| 127 | - $migration = $this->di_container->create( $migration_string ); |
|
| 128 | - } catch ( \Throwable $th ) { |
|
| 129 | - throw Migration_Exception::failed_to_construct_migration( $migration_string ); |
|
| 127 | + $migration = $this->di_container->create($migration_string); |
|
| 128 | + } catch (\Throwable $th) { |
|
| 129 | + throw Migration_Exception::failed_to_construct_migration($migration_string); |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - return is_object( $migration ) && is_a( $migration, Migration::class ) |
|
| 133 | + return is_object($migration) && is_a($migration, Migration::class) |
|
| 134 | 134 | ? $migration |
| 135 | 135 | : null; |
| 136 | 136 | } |
@@ -142,13 +142,13 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | public function done(): self { |
| 144 | 144 | // Bail if no migrations. |
| 145 | - if ( 0 === count( $this->get_migrations() ) ) { |
|
| 145 | + if (0 === count($this->get_migrations())) { |
|
| 146 | 146 | return $this; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | // Set with a fallback Migration Manager if not set. |
| 150 | - if ( null === $this->migration_manager ) { |
|
| 151 | - $this->migration_manager = Factory::manager_with_db_delta( $this->migration_log_key ); |
|
| 150 | + if (null === $this->migration_manager) { |
|
| 151 | + $this->migration_manager = Factory::manager_with_db_delta($this->migration_log_key); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | // Register all migrations and hooks. |
@@ -166,8 +166,8 @@ discard block |
||
| 166 | 166 | * @return void |
| 167 | 167 | */ |
| 168 | 168 | private function populate_migration_manager(): void { |
| 169 | - foreach ( $this->migrations as $migration ) { |
|
| 170 | - $this->migration_manager->add_migration( $migration ); |
|
| 169 | + foreach ($this->migrations as $migration) { |
|
| 170 | + $this->migration_manager->add_migration($migration); |
|
| 171 | 171 | } |
| 172 | 172 | } |
| 173 | 173 | |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | * @return void |
| 187 | 187 | */ |
| 188 | 188 | private function set_activation_calls(): void { |
| 189 | - $this->plugin_state_controller->event( new Activation( $this->migration_manager ) ); |
|
| 189 | + $this->plugin_state_controller->event(new Activation($this->migration_manager)); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /** |
@@ -199,12 +199,12 @@ discard block |
||
| 199 | 199 | // Check we have valid deactivation calls. |
| 200 | 200 | $drop_on_deactivation_migrations = array_filter( |
| 201 | 201 | $this->migrations, |
| 202 | - function( Migration $migration ): bool { |
|
| 202 | + function(Migration $migration): bool { |
|
| 203 | 203 | return $migration->drop_on_deactivation() === true; |
| 204 | 204 | } |
| 205 | 205 | ); |
| 206 | - if ( count( $drop_on_deactivation_migrations ) >= 1 ) { |
|
| 207 | - $this->plugin_state_controller->event( new Deactivation( $this->migration_manager ) ); |
|
| 206 | + if (count($drop_on_deactivation_migrations) >= 1) { |
|
| 207 | + $this->plugin_state_controller->event(new Deactivation($this->migration_manager)); |
|
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | 210 | |
@@ -218,14 +218,14 @@ discard block |
||
| 218 | 218 | // Check we have valid uninstall calls. |
| 219 | 219 | $drop_on_uninstall_migrations = array_filter( |
| 220 | 220 | $this->migrations, |
| 221 | - function( Migration $migration ): bool { |
|
| 221 | + function(Migration $migration): bool { |
|
| 222 | 222 | return $migration->drop_on_uninstall() === true; |
| 223 | 223 | } |
| 224 | 224 | ); |
| 225 | - if ( count( $drop_on_uninstall_migrations ) >= 1 ) { |
|
| 225 | + if (count($drop_on_uninstall_migrations) >= 1) { |
|
| 226 | 226 | // Get all table names to be dropped. |
| 227 | 227 | $table_names = \array_map( |
| 228 | - function( Migration $migration ): string { |
|
| 228 | + function(Migration $migration): string { |
|
| 229 | 229 | return $migration->get_table_name(); |
| 230 | 230 | }, |
| 231 | 231 | $drop_on_uninstall_migrations |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | protected $migration_manager; |
| 27 | 27 | |
| 28 | - public function __construct( Migration_Manager $migration_manager ) { |
|
| 28 | + public function __construct(Migration_Manager $migration_manager) { |
|
| 29 | 29 | $this->migration_manager = $migration_manager; |
| 30 | 30 | } |
| 31 | 31 | |
@@ -70,13 +70,13 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | return array_values( |
| 72 | 72 | array_map( |
| 73 | - function( Migration $migration ): string { |
|
| 73 | + function(Migration $migration): string { |
|
| 74 | 74 | return $migration->get_table_name(); |
| 75 | 75 | }, |
| 76 | 76 | array_filter( |
| 77 | 77 | $migrations, |
| 78 | - function( Migration $migration ):bool { |
|
| 79 | - return count( $migration->get_seeds() ) === 0 |
|
| 78 | + function(Migration $migration):bool { |
|
| 79 | + return count($migration->get_seeds()) === 0 |
|
| 80 | 80 | || false === $migration->seed_on_inital_activation(); |
| 81 | 81 | } |
| 82 | 82 | ) |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | protected $migration_log_key; |
| 32 | 32 | |
| 33 | 33 | /** @param string[] $tables */ |
| 34 | - public function __construct( array $tables, string $migration_log_key ) { |
|
| 34 | + public function __construct(array $tables, string $migration_log_key) { |
|
| 35 | 35 | $this->tables = $tables; |
| 36 | 36 | $this->migration_log_key = $migration_log_key; |
| 37 | 37 | } |
@@ -68,14 +68,14 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | // Temp disable warnings. |
| 70 | 70 | $original_state = (bool) $wpdb->suppress_errors; |
| 71 | - $wpdb->suppress_errors( true ); |
|
| 71 | + $wpdb->suppress_errors(true); |
|
| 72 | 72 | |
| 73 | - foreach ( $this->tables as $table ) { |
|
| 74 | - $wpdb->get_results( "DROP TABLE IF EXISTS {$table}" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
| 73 | + foreach ($this->tables as $table) { |
|
| 74 | + $wpdb->get_results("DROP TABLE IF EXISTS {$table}"); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | // Reset warnings to initial state. |
| 78 | - $wpdb->suppress_errors( $original_state ); |
|
| 78 | + $wpdb->suppress_errors($original_state); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -84,6 +84,6 @@ discard block |
||
| 84 | 84 | * @return void |
| 85 | 85 | */ |
| 86 | 86 | protected function remove_migration_log(): void { |
| 87 | - \delete_option( $this->migration_log_key ); |
|
| 87 | + \delete_option($this->migration_log_key); |
|
| 88 | 88 | } |
| 89 | 89 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | protected $migration_manager; |
| 27 | 27 | |
| 28 | - public function __construct( Migration_Manager $migration_manager ) { |
|
| 28 | + public function __construct(Migration_Manager $migration_manager) { |
|
| 29 | 29 | $this->migration_manager = $migration_manager; |
| 30 | 30 | } |
| 31 | 31 | |
@@ -60,12 +60,12 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | return array_values( |
| 62 | 62 | array_map( |
| 63 | - function( Migration $migration ): string { |
|
| 63 | + function(Migration $migration): string { |
|
| 64 | 64 | return $migration->get_table_name(); |
| 65 | 65 | }, |
| 66 | 66 | array_filter( |
| 67 | 67 | $migrations, |
| 68 | - function( Migration $migration ):bool { |
|
| 68 | + function(Migration $migration):bool { |
|
| 69 | 69 | return false === $migration->drop_on_deactivation(); |
| 70 | 70 | } |
| 71 | 71 | ) |
@@ -22,9 +22,9 @@ discard block |
||
| 22 | 22 | * @code 101 |
| 23 | 23 | * @return Migration_Exception |
| 24 | 24 | */ |
| 25 | - public static function failed_to_construct_migration( string $migration_class_name ): Migration_Exception { |
|
| 26 | - $message = \sprintf( 'Failed to construct %s using the DI Container', $migration_class_name ); |
|
| 27 | - return new Migration_Exception( $message, 101 ); |
|
| 25 | + public static function failed_to_construct_migration(string $migration_class_name): Migration_Exception { |
|
| 26 | + $message = \sprintf('Failed to construct %s using the DI Container', $migration_class_name); |
|
| 27 | + return new Migration_Exception($message, 101); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
@@ -33,11 +33,11 @@ discard block |
||
| 33 | 33 | * @param mixed $var |
| 34 | 34 | * @return Migration_Exception |
| 35 | 35 | */ |
| 36 | - public static function none_migration_type( $var ): Migration_Exception { |
|
| 36 | + public static function none_migration_type($var): Migration_Exception { |
|
| 37 | 37 | $message = \sprintf( |
| 38 | 38 | 'Migration::class instance or class name expected, got %s', |
| 39 | - \is_string( $var ) ? $var : \gettype( $var ) |
|
| 39 | + \is_string($var) ? $var : \gettype($var) |
|
| 40 | 40 | ); |
| 41 | - return new Migration_Exception( $message, 102 ); |
|
| 41 | + return new Migration_Exception($message, 102); |
|
| 42 | 42 | } |
| 43 | 43 | } |
@@ -20,8 +20,8 @@ |
||
| 20 | 20 | |
| 21 | 21 | public function __construct() { |
| 22 | 22 | $this->table_name = $this->table_name(); |
| 23 | - $this->schema = new Schema( $this->table_name, array( $this, 'schema' ) ); |
|
| 24 | - $this->seed_data = $this->seed( array() ); |
|
| 23 | + $this->schema = new Schema($this->table_name, array($this, 'schema')); |
|
| 24 | + $this->seed_data = $this->seed(array()); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | abstract protected function table_name(): string; |