@@ -72,7 +72,7 @@ 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(); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @param string $log_key |
85 | 85 | * @return self |
86 | 86 | */ |
87 | - public function set_migration_log_key( string $log_key ): self { |
|
87 | + public function set_migration_log_key(string $log_key): self { |
|
88 | 88 | $this->migration_log_key = $log_key; |
89 | 89 | return $this; |
90 | 90 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @param Migration_Manager $migration_manager The migration manager instance. |
96 | 96 | * @return self |
97 | 97 | */ |
98 | - public function set_migration_manager( Migration_Manager $migration_manager ):self { |
|
98 | + public function set_migration_manager(Migration_Manager $migration_manager):self { |
|
99 | 99 | $this->migration_manager = $migration_manager; |
100 | 100 | return $this; |
101 | 101 | } |
@@ -106,14 +106,14 @@ discard block |
||
106 | 106 | * @param class-string<Migration>|Migration $migration |
107 | 107 | * @return self |
108 | 108 | */ |
109 | - public function add_migration( $migration ): self { |
|
110 | - if ( ! is_subclass_of( $migration, Migration::class ) ) { |
|
111 | - throw Migration_Exception::none_migration_type( \serialize( $migration ) ); //phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize, used for exception messages |
|
109 | + public function add_migration($migration): self { |
|
110 | + if ( ! is_subclass_of($migration, Migration::class)) { |
|
111 | + throw Migration_Exception::none_migration_type(\serialize($migration)); //phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize, used for exception messages |
|
112 | 112 | } |
113 | 113 | |
114 | - $migration = $this->maybe_construct_migration( $migration ); |
|
115 | - if ( null === $migration ) { |
|
116 | - throw Migration_Exception::failed_to_construct_migration( 'Invalid after construction' ); |
|
114 | + $migration = $this->maybe_construct_migration($migration); |
|
115 | + if (null === $migration) { |
|
116 | + throw Migration_Exception::failed_to_construct_migration('Invalid after construction'); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | $this->migrations[] = $migration; |
@@ -126,17 +126,17 @@ discard block |
||
126 | 126 | * @param class-string<Migration>|Migration $migration |
127 | 127 | * @return Migration|null |
128 | 128 | */ |
129 | - protected function maybe_construct_migration( $migration ): ?Migration { |
|
130 | - if ( is_string( $migration ) ) { |
|
129 | + protected function maybe_construct_migration($migration): ?Migration { |
|
130 | + if (is_string($migration)) { |
|
131 | 131 | $migration_string = $migration; |
132 | 132 | try { |
133 | - $migration = $this->di_container->create( $migration_string ); |
|
134 | - } catch ( \Throwable $th ) { |
|
135 | - throw Migration_Exception::failed_to_construct_migration( $migration_string ); |
|
133 | + $migration = $this->di_container->create($migration_string); |
|
134 | + } catch (\Throwable $th) { |
|
135 | + throw Migration_Exception::failed_to_construct_migration($migration_string); |
|
136 | 136 | } |
137 | 137 | } |
138 | 138 | |
139 | - return is_object( $migration ) && is_a( $migration, Migration::class ) |
|
139 | + return is_object($migration) && is_a($migration, Migration::class) |
|
140 | 140 | ? $migration |
141 | 141 | : null; |
142 | 142 | } |
@@ -148,13 +148,13 @@ discard block |
||
148 | 148 | */ |
149 | 149 | public function done(): self { |
150 | 150 | // Bail if no migrations. |
151 | - if ( 0 === count( $this->get_migrations() ) ) { |
|
151 | + if (0 === count($this->get_migrations())) { |
|
152 | 152 | return $this; |
153 | 153 | } |
154 | 154 | |
155 | 155 | // Set with a fallback Migration Manager if not set. |
156 | - if ( null === $this->migration_manager ) { |
|
157 | - $this->migration_manager = Factory::manager_with_db_delta( $this->migration_log_key ); |
|
156 | + if (null === $this->migration_manager) { |
|
157 | + $this->migration_manager = Factory::manager_with_db_delta($this->migration_log_key); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | // Register all migrations and hooks. |
@@ -172,8 +172,8 @@ discard block |
||
172 | 172 | * @return void |
173 | 173 | */ |
174 | 174 | private function populate_migration_manager(): void { |
175 | - foreach ( $this->migrations as $migration ) { |
|
176 | - $this->migration_manager->add_migration( $migration ); |
|
175 | + foreach ($this->migrations as $migration) { |
|
176 | + $this->migration_manager->add_migration($migration); |
|
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * @return void |
193 | 193 | */ |
194 | 194 | private function set_activation_calls(): void { |
195 | - $this->plugin_state_controller->event( new Activation( $this->migration_manager ) ); |
|
195 | + $this->plugin_state_controller->event(new Activation($this->migration_manager)); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -205,12 +205,12 @@ discard block |
||
205 | 205 | // Check we have valid deactivation calls. |
206 | 206 | $drop_on_deactivation_migrations = array_filter( |
207 | 207 | $this->migrations, |
208 | - function( Migration $migration ): bool { |
|
208 | + function(Migration $migration): bool { |
|
209 | 209 | return $migration->drop_on_deactivation() === true; |
210 | 210 | } |
211 | 211 | ); |
212 | - if ( count( $drop_on_deactivation_migrations ) >= 1 ) { |
|
213 | - $this->plugin_state_controller->event( new Deactivation( $this->migration_manager ) ); |
|
212 | + if (count($drop_on_deactivation_migrations) >= 1) { |
|
213 | + $this->plugin_state_controller->event(new Deactivation($this->migration_manager)); |
|
214 | 214 | } |
215 | 215 | } |
216 | 216 | |
@@ -224,14 +224,14 @@ discard block |
||
224 | 224 | // Check we have valid uninstall calls. |
225 | 225 | $drop_on_uninstall_migrations = array_filter( |
226 | 226 | $this->migrations, |
227 | - function( Migration $migration ): bool { |
|
227 | + function(Migration $migration): bool { |
|
228 | 228 | return $migration->drop_on_uninstall() === true; |
229 | 229 | } |
230 | 230 | ); |
231 | - if ( count( $drop_on_uninstall_migrations ) >= 1 ) { |
|
231 | + if (count($drop_on_uninstall_migrations) >= 1) { |
|
232 | 232 | // Get all table names to be dropped. |
233 | 233 | $table_names = \array_map( |
234 | - function( Migration $migration ): string { |
|
234 | + function(Migration $migration): string { |
|
235 | 235 | return $migration->get_table_name(); |
236 | 236 | }, |
237 | 237 | $drop_on_uninstall_migrations |