@@ -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 string $var |
34 | 34 | * @return Migration_Exception |
35 | 35 | */ |
36 | - public static function none_migration_type( string $var ): Migration_Exception { |
|
36 | + public static function none_migration_type(string $var): Migration_Exception { |
|
37 | 37 | $message = \sprintf( |
38 | 38 | 'Only valid Migration Class names can be passed as migrations, "%s" was passed to Perique_Migrations::add_module()', |
39 | - esc_attr( $var ) |
|
39 | + esc_attr($var) |
|
40 | 40 | ); |
41 | - return new Migration_Exception( $message, 102 ); |
|
41 | + return new Migration_Exception($message, 102); |
|
42 | 42 | } |
43 | 43 | } |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | * @param class-string<Migration> $migration |
39 | 39 | * @return self |
40 | 40 | */ |
41 | - public function add_migration( string $migration ): self { |
|
42 | - if ( ! is_subclass_of( $migration, Migration::class ) ) { |
|
43 | - throw Migration_Exception::none_migration_type( $migration ); |
|
41 | + public function add_migration(string $migration): self { |
|
42 | + if ( ! is_subclass_of($migration, Migration::class)) { |
|
43 | + throw Migration_Exception::none_migration_type($migration); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | $this->migrations[] = $migration; |
@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | * @param string $migration_log_key |
54 | 54 | * @return self |
55 | 55 | */ |
56 | - public function set_migration_log_key( string $migration_log_key ): self { |
|
57 | - $this->migration_log_key = \sanitize_title( $migration_log_key ); |
|
56 | + public function set_migration_log_key(string $migration_log_key): self { |
|
57 | + $this->migration_log_key = \sanitize_title($migration_log_key); |
|
58 | 58 | return $this; |
59 | 59 | } |
60 | 60 | |
@@ -76,18 +76,18 @@ discard block |
||
76 | 76 | * @pram DI_Container $di_container |
77 | 77 | * @return void |
78 | 78 | */ |
79 | - public function pre_boot( App_Config $config, Hook_Loader $loader, DI_Container $di_container ): void { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed |
|
79 | + public function pre_boot(App_Config $config, Hook_Loader $loader, DI_Container $di_container): void { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed |
|
80 | 80 | // Set the migration manager. |
81 | - $migration_manager = Factory::manager_with_db_delta( $this->migration_log_key ); |
|
81 | + $migration_manager = Factory::manager_with_db_delta($this->migration_log_key); |
|
82 | 82 | |
83 | 83 | // Add the migrations to the manager. |
84 | - foreach ( $this->generate_migrations( $di_container ) as $migration ) { |
|
85 | - $migration_manager->add_migration( $migration ); |
|
84 | + foreach ($this->generate_migrations($di_container) as $migration) { |
|
85 | + $migration_manager->add_migration($migration); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | // Add to the events. |
89 | - if ( \class_exists( Plugin_Life_Cycle::class ) ) { |
|
90 | - add_filter( Plugin_Life_Cycle::EVENT_LIST, $this->generate_migration_events_callback( $migration_manager ) ); |
|
89 | + if (\class_exists(Plugin_Life_Cycle::class)) { |
|
90 | + add_filter(Plugin_Life_Cycle::EVENT_LIST, $this->generate_migration_events_callback($migration_manager)); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | } |
@@ -98,21 +98,21 @@ discard block |
||
98 | 98 | * @param Migration_Manager $migration_manager |
99 | 99 | * @return \Closure(array<Plugin_State_Change>):array<Plugin_State_Change> |
100 | 100 | */ |
101 | - protected function generate_migration_events_callback( Migration_Manager $migration_manager ): \Closure { |
|
101 | + protected function generate_migration_events_callback(Migration_Manager $migration_manager): \Closure { |
|
102 | 102 | /** |
103 | 103 | * @param array<Plugin_State_Change> $events |
104 | 104 | * @return array<Plugin_State_Change> |
105 | 105 | */ |
106 | - return function( array $events ) use ( $migration_manager ): array { |
|
106 | + return function(array $events) use ($migration_manager): array { |
|
107 | 107 | static $cached = null; |
108 | - if ( is_null( $cached ) ) { |
|
108 | + if (is_null($cached)) { |
|
109 | 109 | $cached = array( |
110 | - new Activation( $migration_manager ), |
|
111 | - new Deactivation( $migration_manager ), |
|
112 | - new Uninstall( $migration_manager ), |
|
110 | + new Activation($migration_manager), |
|
111 | + new Deactivation($migration_manager), |
|
112 | + new Uninstall($migration_manager), |
|
113 | 113 | ); |
114 | 114 | } |
115 | - return array_merge( $events, $cached ); |
|
115 | + return array_merge($events, $cached); |
|
116 | 116 | }; |
117 | 117 | } |
118 | 118 | |
@@ -123,19 +123,19 @@ discard block |
||
123 | 123 | * @return array<Migration> |
124 | 124 | * @throws Migration_Exception |
125 | 125 | */ |
126 | - protected function generate_migrations( DI_Container $container ): array { |
|
126 | + protected function generate_migrations(DI_Container $container): array { |
|
127 | 127 | $migrations = array(); |
128 | - foreach ( $this->migrations as $migration ) { |
|
129 | - if ( is_string( $migration ) ) { |
|
128 | + foreach ($this->migrations as $migration) { |
|
129 | + if (is_string($migration)) { |
|
130 | 130 | try { |
131 | - $instance = $container->create( $migration ); |
|
132 | - } catch ( \Throwable $th ) { |
|
133 | - throw Migration_Exception::failed_to_construct_migration( $migration ); |
|
131 | + $instance = $container->create($migration); |
|
132 | + } catch (\Throwable $th) { |
|
133 | + throw Migration_Exception::failed_to_construct_migration($migration); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | // Add to the list if valid. |
137 | - if ( ! is_object( $instance ) || ! is_a( $instance, Migration::class ) ) { |
|
138 | - throw Migration_Exception::failed_to_construct_migration( $migration ); |
|
137 | + if ( ! is_object($instance) || ! is_a($instance, Migration::class)) { |
|
138 | + throw Migration_Exception::failed_to_construct_migration($migration); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | $migrations[] = $instance; |
@@ -147,10 +147,10 @@ discard block |
||
147 | 147 | ## Unused methods |
148 | 148 | |
149 | 149 | /** @inheritDoc */ |
150 | - public function pre_register( App_Config $config, Hook_Loader $loader, DI_Container $di_container ): void {} // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed |
|
150 | + public function pre_register(App_Config $config, Hook_Loader $loader, DI_Container $di_container): void {} // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed |
|
151 | 151 | |
152 | 152 | /** @inheritDoc */ |
153 | - public function post_register( App_Config $config, Hook_Loader $loader, DI_Container $di_container ): void {} // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed |
|
153 | + public function post_register(App_Config $config, Hook_Loader $loader, DI_Container $di_container): void {} // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed |
|
154 | 154 | |
155 | 155 | /** @inheritDoc */ |
156 | 156 | public function get_middleware(): ?string { |
@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | */ |
34 | 34 | protected string $migration_log_key; |
35 | 35 | |
36 | - public function __construct( Migration_Manager $migration_manager ) { |
|
37 | - $this->set_tables( $migration_manager->get_migrations() ); |
|
36 | + public function __construct(Migration_Manager $migration_manager) { |
|
37 | + $this->set_tables($migration_manager->get_migrations()); |
|
38 | 38 | $this->migration_log_key = $migration_manager->migration_log()->get_log_key(); |
39 | 39 | } |
40 | 40 | |
@@ -45,10 +45,10 @@ discard block |
||
45 | 45 | * @param Database_Migration[] $migrations |
46 | 46 | * @return void |
47 | 47 | */ |
48 | - public function set_tables( array $migrations ): void { |
|
48 | + public function set_tables(array $migrations): void { |
|
49 | 49 | $this->tables = \array_filter( |
50 | 50 | $migrations, |
51 | - fn( Database_Migration $migration ) => is_a( $migration, Migration::class ) && $migration->drop_on_uninstall() |
|
51 | + fn(Database_Migration $migration) => is_a($migration, Migration::class) && $migration->drop_on_uninstall() |
|
52 | 52 | ); |
53 | 53 | } |
54 | 54 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function run(): void { |
73 | 73 | // If no tables, return. |
74 | - if ( empty( $this->tables ) ) { |
|
74 | + if (empty($this->tables)) { |
|
75 | 75 | return; |
76 | 76 | } |
77 | 77 | |
@@ -91,15 +91,15 @@ discard block |
||
91 | 91 | |
92 | 92 | // Temp disable warnings. |
93 | 93 | $original_state = (bool) $wpdb->suppress_errors; |
94 | - $wpdb->suppress_errors( true ); |
|
94 | + $wpdb->suppress_errors(true); |
|
95 | 95 | |
96 | - foreach ( $this->tables as $table ) { |
|
96 | + foreach ($this->tables as $table) { |
|
97 | 97 | $table_name = $table->get_table_name(); |
98 | - $wpdb->get_results( "DROP TABLE IF EXISTS {$table_name}" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
98 | + $wpdb->get_results("DROP TABLE IF EXISTS {$table_name}"); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | // Reset warnings to initial state. |
102 | - $wpdb->suppress_errors( $original_state ); |
|
102 | + $wpdb->suppress_errors($original_state); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -108,6 +108,6 @@ discard block |
||
108 | 108 | * @return void |
109 | 109 | */ |
110 | 110 | protected function remove_migration_log(): void { |
111 | - \delete_option( $this->migration_log_key ); |
|
111 | + \delete_option($this->migration_log_key); |
|
112 | 112 | } |
113 | 113 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | */ |
26 | 26 | protected Migration_Manager $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 | ) |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | */ |
26 | 26 | protected Migration_Manager $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 | ) |