@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | protected $plugin_base_file = null; |
| 49 | 49 | |
| 50 | - public function __construct( App $app, ?string $plugin_base_file = null ) { |
|
| 50 | + public function __construct(App $app, ?string $plugin_base_file = null) { |
|
| 51 | 51 | $this->app = $app; |
| 52 | 52 | $this->plugin_base_file = $plugin_base_file; |
| 53 | 53 | } |
@@ -58,8 +58,8 @@ discard block |
||
| 58 | 58 | * @param App $app |
| 59 | 59 | * @return self |
| 60 | 60 | */ |
| 61 | - public static function init( App $app, ?string $plugin_base_file = null ): self { |
|
| 62 | - $instance = new self( $app, $plugin_base_file ); |
|
| 61 | + public static function init(App $app, ?string $plugin_base_file = null): self { |
|
| 62 | + $instance = new self($app, $plugin_base_file); |
|
| 63 | 63 | return $instance; |
| 64 | 64 | } |
| 65 | 65 | |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * @param string $plugin_base_file Holds the location of the plugin base file. |
| 79 | 79 | * @return self |
| 80 | 80 | */ |
| 81 | - public function set_plugin_base_file( string $plugin_base_file ): self { |
|
| 81 | + public function set_plugin_base_file(string $plugin_base_file): self { |
|
| 82 | 82 | $this->plugin_base_file = $plugin_base_file; |
| 83 | 83 | return $this; |
| 84 | 84 | } |
@@ -90,25 +90,25 @@ discard block |
||
| 90 | 90 | * @return self |
| 91 | 91 | * @throws Plugin_State_Exception If none Plugin_State_Change (string or object) passed or fails to create instance from valid class name. |
| 92 | 92 | */ |
| 93 | - public function event( $state_event ): self { |
|
| 93 | + public function event($state_event): self { |
|
| 94 | 94 | /* @phpstan-ignore-next-line, as this cannot be type hinted the check exists. */ |
| 95 | - if ( ! is_subclass_of( $state_event, Plugin_State_Change::class ) ) { |
|
| 96 | - throw Plugin_State_Exception::invalid_state_change_event_type( $state_event ); |
|
| 95 | + if ( ! is_subclass_of($state_event, Plugin_State_Change::class)) { |
|
| 96 | + throw Plugin_State_Exception::invalid_state_change_event_type($state_event); |
|
| 97 | 97 | } |
| 98 | 98 | // If its a string, attempt to create via DI container. |
| 99 | - if ( is_string( $state_event ) ) { |
|
| 99 | + if (is_string($state_event)) { |
|
| 100 | 100 | $state_event_string = $state_event; |
| 101 | 101 | |
| 102 | 102 | try { |
| 103 | 103 | /** @var Plugin_State_Change|null */ |
| 104 | - $state_event = $this->app->get_container()->create( $state_event ); |
|
| 105 | - } catch ( \Throwable $th ) { |
|
| 106 | - throw Plugin_State_Exception::failed_to_create_state_change_event( $state_event_string ); |
|
| 104 | + $state_event = $this->app->get_container()->create($state_event); |
|
| 105 | + } catch (\Throwable $th) { |
|
| 106 | + throw Plugin_State_Exception::failed_to_create_state_change_event($state_event_string); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | // Throw exception if failed to create |
| 110 | - if ( null === $state_event || ! is_a( $state_event, Plugin_State_Change::class ) ) { |
|
| 111 | - throw Plugin_State_Exception::failed_to_create_state_change_event( $state_event_string ); |
|
| 110 | + if (null === $state_event || ! is_a($state_event, Plugin_State_Change::class)) { |
|
| 111 | + throw Plugin_State_Exception::failed_to_create_state_change_event($state_event_string); |
|
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | $this->state_events[] = $state_event; |
@@ -122,35 +122,35 @@ discard block |
||
| 122 | 122 | * @return self |
| 123 | 123 | * @throws Plugin_State_Exception [103] failed_to_locate_calling_file() |
| 124 | 124 | */ |
| 125 | - public function finalise( ?string $file = null ): self { |
|
| 126 | - if ( null === $file ) { |
|
| 125 | + public function finalise(?string $file = null): self { |
|
| 126 | + if (null === $file) { |
|
| 127 | 127 | $file = $this->plugin_base_file ?? $this->get_called_file(); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | // Activation hooks if need adding. |
| 131 | - if ( $this->has_events_for_state( Activation::class ) ) { |
|
| 132 | - register_activation_hook( $file, $this->activation() ); |
|
| 131 | + if ($this->has_events_for_state(Activation::class)) { |
|
| 132 | + register_activation_hook($file, $this->activation()); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | // Deactivation hooks. |
| 136 | - if ( $this->has_events_for_state( Deactivation::class ) ) { |
|
| 137 | - register_deactivation_hook( $file, $this->deactivation() ); |
|
| 136 | + if ($this->has_events_for_state(Deactivation::class)) { |
|
| 137 | + register_deactivation_hook($file, $this->deactivation()); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | // If we have an uninstall events, add then during activation. |
| 141 | - if ( $this->has_events_for_state( Uninstall::class ) ) { |
|
| 141 | + if ($this->has_events_for_state(Uninstall::class)) { |
|
| 142 | 142 | $callback = $this->uninstall(); |
| 143 | 143 | |
| 144 | 144 | // Register the callback so itsits included (but wont run due to serialization issues). |
| 145 | 145 | register_activation_hook( |
| 146 | 146 | $file, |
| 147 | - static function() use ( $file, $callback ): void { |
|
| 148 | - register_uninstall_hook( $file, $callback ); |
|
| 147 | + static function() use ($file, $callback): void { |
|
| 148 | + register_uninstall_hook($file, $callback); |
|
| 149 | 149 | } |
| 150 | 150 | ); |
| 151 | 151 | |
| 152 | 152 | // Manually re-add the uninstall hook. |
| 153 | - add_action( 'uninstall_' . plugin_basename( $file ), $callback ); |
|
| 153 | + add_action('uninstall_'.plugin_basename($file), $callback); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | return $this; |
@@ -162,12 +162,12 @@ discard block |
||
| 162 | 162 | * @param string $state |
| 163 | 163 | * @return Plugin_State_Change[] |
| 164 | 164 | */ |
| 165 | - private function get_events_for_state( string $state ): array { |
|
| 165 | + private function get_events_for_state(string $state): array { |
|
| 166 | 166 | return array_filter( |
| 167 | 167 | $this->state_events, |
| 168 | - function( $e ) use ( $state ): bool { |
|
| 168 | + function($e) use ($state): bool { |
|
| 169 | 169 | /* @phpstan-ignore-next-line */ |
| 170 | - return is_subclass_of( $e, $state ); |
|
| 170 | + return is_subclass_of($e, $state); |
|
| 171 | 171 | } |
| 172 | 172 | ); |
| 173 | 173 | } |
@@ -178,8 +178,8 @@ discard block |
||
| 178 | 178 | * @param string $state |
| 179 | 179 | * @return bool |
| 180 | 180 | */ |
| 181 | - private function has_events_for_state( string $state ): bool { |
|
| 182 | - return count( $this->get_events_for_state( $state ) ) !== 0; |
|
| 181 | + private function has_events_for_state(string $state): bool { |
|
| 182 | + return count($this->get_events_for_state($state)) !== 0; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | * @return State_Change_Queue |
| 189 | 189 | */ |
| 190 | 190 | public function activation(): State_Change_Queue { |
| 191 | - return new State_Change_Queue( ...$this->get_events_for_state( Activation::class ) ); |
|
| 191 | + return new State_Change_Queue(...$this->get_events_for_state(Activation::class)); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | * @return State_Change_Queue |
| 198 | 198 | */ |
| 199 | 199 | public function deactivation(): State_Change_Queue { |
| 200 | - return new State_Change_Queue( ...$this->get_events_for_state( Deactivation::class ) ); |
|
| 200 | + return new State_Change_Queue(...$this->get_events_for_state(Deactivation::class)); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | * @return State_Change_Queue |
| 207 | 207 | */ |
| 208 | 208 | public function uninstall(): State_Change_Queue { |
| 209 | - return new State_Change_Queue( ...$this->get_events_for_state( Uninstall::class ) ); |
|
| 209 | + return new State_Change_Queue(...$this->get_events_for_state(Uninstall::class)); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | /** |
@@ -218,16 +218,16 @@ discard block |
||
| 218 | 218 | protected function get_called_file(): string { |
| 219 | 219 | $backtrace = debug_backtrace(); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace |
| 220 | 220 | |
| 221 | - $backtrace_count = count( $backtrace ); |
|
| 222 | - for ( $i = 0; $i < $backtrace_count; $i++ ) { |
|
| 223 | - if ( $backtrace[ $i ]['function'] === __FUNCTION__ |
|
| 224 | - && \array_key_exists( 'class', $backtrace[ $i ] ) |
|
| 225 | - && $backtrace[ $i ]['class'] === get_class() |
|
| 226 | - && \array_key_exists( ( $i + 1 ), $backtrace ) |
|
| 227 | - && \array_key_exists( 'file', $backtrace[ $i + 1 ] ) |
|
| 221 | + $backtrace_count = count($backtrace); |
|
| 222 | + for ($i = 0; $i < $backtrace_count; $i++) { |
|
| 223 | + if ($backtrace[$i]['function'] === __FUNCTION__ |
|
| 224 | + && \array_key_exists('class', $backtrace[$i]) |
|
| 225 | + && $backtrace[$i]['class'] === get_class() |
|
| 226 | + && \array_key_exists(($i + 1), $backtrace) |
|
| 227 | + && \array_key_exists('file', $backtrace[$i + 1]) |
|
| 228 | 228 | |
| 229 | 229 | ) { |
| 230 | - return $backtrace[ $i + 1 ]['file']; |
|
| 230 | + return $backtrace[$i + 1]['file']; |
|
| 231 | 231 | } |
| 232 | 232 | } |
| 233 | 233 | // @codeCoverageIgnoreStart |