@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types=1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | /** |
6 | 6 | * Interface for all classes which act on a plugin state change. |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @return self |
46 | 46 | */ |
47 | - public function event( string $event ): self { |
|
47 | + public function event(string $event): self { |
|
48 | 48 | // Ensure the event is a valid class. |
49 | - if ( ! class_exists( $event ) ) { |
|
50 | - throw Plugin_State_Exception::invalid_state_change_event_type( $event ); |
|
49 | + if ( ! class_exists($event)) { |
|
50 | + throw Plugin_State_Exception::invalid_state_change_event_type($event); |
|
51 | 51 | } |
52 | 52 | $this->events[] = $event; |
53 | 53 | |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @return self |
63 | 63 | */ |
64 | - public function plugin_base_file( string $plugin_base_file ): self { |
|
64 | + public function plugin_base_file(string $plugin_base_file): self { |
|
65 | 65 | $this->plugin_base_file = $plugin_base_file; |
66 | 66 | |
67 | 67 | return $this; |
@@ -75,13 +75,13 @@ discard block |
||
75 | 75 | * @pram DI_Container $di_container |
76 | 76 | * @return void |
77 | 77 | */ |
78 | - public function pre_boot( App_Config $config, Hook_Loader $loader, DI_Container $di_container ): void { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed |
|
78 | + public function pre_boot(App_Config $config, Hook_Loader $loader, DI_Container $di_container): void { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed |
|
79 | 79 | |
80 | 80 | // Create the instance of the state controller. |
81 | - $this->state_controller = new Plugin_State_Controller( $di_container, $this->plugin_base_file ); |
|
81 | + $this->state_controller = new Plugin_State_Controller($di_container, $this->plugin_base_file); |
|
82 | 82 | |
83 | 83 | // Finalise the state controller. |
84 | - add_action( Hooks::APP_INIT_PRE_BOOT, array( $this, 'finalise' ), 999, 3 ); |
|
84 | + add_action(Hooks::APP_INIT_PRE_BOOT, array($this, 'finalise'), 999, 3); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -92,26 +92,26 @@ discard block |
||
92 | 92 | * @pram DI_Container $di_container |
93 | 93 | * @return void |
94 | 94 | */ |
95 | - public function finalise( App_Config $config, Hook_Loader $loader, DI_Container $di_container ): void { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceAfterLastUsed |
|
95 | + public function finalise(App_Config $config, Hook_Loader $loader, DI_Container $di_container): void { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceAfterLastUsed |
|
96 | 96 | |
97 | 97 | // Throw exception if controller not set. |
98 | - if ( null === $this->state_controller ) { |
|
98 | + if (null === $this->state_controller) { |
|
99 | 99 | throw Plugin_State_Exception::missing_controller(); |
100 | 100 | } |
101 | 101 | |
102 | 102 | // Trigger the pre action. |
103 | - do_action( self::PRE_FINALISE, $this ); |
|
103 | + do_action(self::PRE_FINALISE, $this); |
|
104 | 104 | |
105 | 105 | // Add events to the controller. |
106 | - foreach ( $this->get_events() as $event ) { |
|
107 | - $this->state_controller->event( $event ); |
|
106 | + foreach ($this->get_events() as $event) { |
|
107 | + $this->state_controller->event($event); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | // Register the state controller. |
111 | 111 | $this->state_controller->finalise(); |
112 | 112 | |
113 | 113 | // Trigger the post action. |
114 | - do_action( self::POST_FINALISE, $this ); |
|
114 | + do_action(self::POST_FINALISE, $this); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | |
@@ -121,10 +121,10 @@ discard block |
||
121 | 121 | * @return class-string<Plugin_State_Change>[] |
122 | 122 | */ |
123 | 123 | public function get_events(): array { |
124 | - $events = apply_filters( self::STATE_EVENTS, $this->events ); |
|
125 | - $events = array_unique( $events ); |
|
126 | - $events = array_filter( $events, 'is_string' ); |
|
127 | - $events = array_filter( $events, fn( $event ) => is_subclass_of( $event, Plugin_State_Change::class ) ); |
|
124 | + $events = apply_filters(self::STATE_EVENTS, $this->events); |
|
125 | + $events = array_unique($events); |
|
126 | + $events = array_filter($events, 'is_string'); |
|
127 | + $events = array_filter($events, fn($event) => is_subclass_of($event, Plugin_State_Change::class)); |
|
128 | 128 | |
129 | 129 | return $events; |
130 | 130 | } |
@@ -132,10 +132,10 @@ discard block |
||
132 | 132 | ## Unused methods |
133 | 133 | |
134 | 134 | /** @inheritDoc */ |
135 | - public function pre_register( App_Config $config, Hook_Loader $loader, DI_Container $di_container ): void {} // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed |
|
135 | + public function pre_register(App_Config $config, Hook_Loader $loader, DI_Container $di_container): void {} // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed |
|
136 | 136 | |
137 | 137 | /** @inheritDoc */ |
138 | - public function post_register( App_Config $config, Hook_Loader $loader, DI_Container $di_container ): void {} // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed |
|
138 | + public function post_register(App_Config $config, Hook_Loader $loader, DI_Container $di_container): void {} // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed |
|
139 | 139 | |
140 | 140 | /** @inheritDoc */ |
141 | 141 | public function get_middleware(): ?string { |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types=1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | /** |
6 | 6 | * Interface for all classes which act on a plugin state change. |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | protected $plugin_base_file; |
50 | 50 | |
51 | - public function __construct( DI_Container $container, ?string $plugin_base_file ) { |
|
51 | + public function __construct(DI_Container $container, ?string $plugin_base_file) { |
|
52 | 52 | $this->container = $container; |
53 | 53 | $this->plugin_base_file = $plugin_base_file ?? $this->get_instantiating_file(); |
54 | 54 | } |
@@ -61,25 +61,25 @@ discard block |
||
61 | 61 | * @return self |
62 | 62 | * @throws Plugin_State_Exception If none Plugin_State_Change (string or object) passed or fails to create instance from valid class name. |
63 | 63 | */ |
64 | - public function event( string $state_event ): self { |
|
64 | + public function event(string $state_event): self { |
|
65 | 65 | // Cache the event class name. |
66 | 66 | $state_event_string = $state_event; |
67 | 67 | |
68 | 68 | /* @phpstan-ignore-next-line, as this cannot be type hinted the check exists. */ |
69 | - if ( ! is_subclass_of( $state_event, Plugin_State_Change::class ) ) { |
|
70 | - throw Plugin_State_Exception::invalid_state_change_event_type( $state_event ); |
|
69 | + if ( ! is_subclass_of($state_event, Plugin_State_Change::class)) { |
|
70 | + throw Plugin_State_Exception::invalid_state_change_event_type($state_event); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | try { |
74 | 74 | /** @var Plugin_State_Change|null */ |
75 | - $state_event = $this->container->create( $state_event ); |
|
76 | - } catch ( \Throwable $th ) { |
|
77 | - throw Plugin_State_Exception::failed_to_create_state_change_event( $state_event_string ); |
|
75 | + $state_event = $this->container->create($state_event); |
|
76 | + } catch (\Throwable $th) { |
|
77 | + throw Plugin_State_Exception::failed_to_create_state_change_event($state_event_string); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | // Throw exception if failed to create |
81 | - if ( null === $state_event || ! is_a( $state_event, Plugin_State_Change::class ) ) { |
|
82 | - throw Plugin_State_Exception::failed_to_create_state_change_event( $state_event_string ); |
|
81 | + if (null === $state_event || ! is_a($state_event, Plugin_State_Change::class)) { |
|
82 | + throw Plugin_State_Exception::failed_to_create_state_change_event($state_event_string); |
|
83 | 83 | } |
84 | 84 | $this->state_events[] = $state_event; |
85 | 85 | |
@@ -97,29 +97,29 @@ discard block |
||
97 | 97 | $file = $this->plugin_base_file; |
98 | 98 | |
99 | 99 | // Activation hooks if need adding. |
100 | - if ( $this->has_events_for_state( Activation::class ) ) { |
|
101 | - register_activation_hook( $file, $this->activation() ); |
|
100 | + if ($this->has_events_for_state(Activation::class)) { |
|
101 | + register_activation_hook($file, $this->activation()); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | // Deactivation hooks. |
105 | - if ( $this->has_events_for_state( Deactivation::class ) ) { |
|
106 | - register_deactivation_hook( $file, $this->deactivation() ); |
|
105 | + if ($this->has_events_for_state(Deactivation::class)) { |
|
106 | + register_deactivation_hook($file, $this->deactivation()); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | // If we have an uninstall events, add then during activation. |
110 | - if ( $this->has_events_for_state( Uninstall::class ) ) { |
|
110 | + if ($this->has_events_for_state(Uninstall::class)) { |
|
111 | 111 | $callback = $this->uninstall(); |
112 | 112 | |
113 | 113 | // Register the callback so itsits included (but wont run due to serialization issues). |
114 | 114 | register_activation_hook( |
115 | 115 | $file, |
116 | - static function () use ( $file, $callback ): void { |
|
117 | - register_uninstall_hook( $file, $callback ); |
|
116 | + static function() use ($file, $callback): void { |
|
117 | + register_uninstall_hook($file, $callback); |
|
118 | 118 | } |
119 | 119 | ); |
120 | 120 | |
121 | 121 | // Manually re-add the uninstall hook. |
122 | - add_action( 'uninstall_' . plugin_basename( $file ), $callback ); |
|
122 | + add_action('uninstall_'.plugin_basename($file), $callback); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | return $this; |
@@ -132,12 +132,12 @@ discard block |
||
132 | 132 | * |
133 | 133 | * @return Plugin_State_Change[] |
134 | 134 | */ |
135 | - private function get_events_for_state( string $state ): array { |
|
135 | + private function get_events_for_state(string $state): array { |
|
136 | 136 | return array_filter( |
137 | - apply_filters( Plugin_Life_Cycle::EVENT_LIST, $this->state_events ), |
|
138 | - function ( $e ) use ( $state ): bool { |
|
137 | + apply_filters(Plugin_Life_Cycle::EVENT_LIST, $this->state_events), |
|
138 | + function($e) use ($state): bool { |
|
139 | 139 | /* @phpstan-ignore-next-line */ |
140 | - return is_subclass_of( $e, $state ); |
|
140 | + return is_subclass_of($e, $state); |
|
141 | 141 | } |
142 | 142 | ); |
143 | 143 | } |
@@ -149,8 +149,8 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @return bool |
151 | 151 | */ |
152 | - private function has_events_for_state( string $state ): bool { |
|
153 | - return count( $this->get_events_for_state( $state ) ) !== 0; |
|
152 | + private function has_events_for_state(string $state): bool { |
|
153 | + return count($this->get_events_for_state($state)) !== 0; |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | * @return State_Change_Queue |
160 | 160 | */ |
161 | 161 | public function activation(): State_Change_Queue { |
162 | - return new State_Change_Queue( ...$this->get_events_for_state( Activation::class ) ); |
|
162 | + return new State_Change_Queue(...$this->get_events_for_state(Activation::class)); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * @return State_Change_Queue |
169 | 169 | */ |
170 | 170 | public function deactivation(): State_Change_Queue { |
171 | - return new State_Change_Queue( ...$this->get_events_for_state( Deactivation::class ) ); |
|
171 | + return new State_Change_Queue(...$this->get_events_for_state(Deactivation::class)); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | * @return State_Change_Queue |
178 | 178 | */ |
179 | 179 | public function uninstall(): State_Change_Queue { |
180 | - return new State_Change_Queue( ...$this->get_events_for_state( Uninstall::class ) ); |
|
180 | + return new State_Change_Queue(...$this->get_events_for_state(Uninstall::class)); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -193,17 +193,17 @@ discard block |
||
193 | 193 | $source_trace = array_values( |
194 | 194 | array_filter( |
195 | 195 | $backtrace, |
196 | - function ( $bt ) { |
|
197 | - return array_key_exists( 'class', $bt ) && $bt['class'] === App_Factory::class; |
|
196 | + function($bt) { |
|
197 | + return array_key_exists('class', $bt) && $bt['class'] === App_Factory::class; |
|
198 | 198 | } |
199 | 199 | ) |
200 | 200 | ); |
201 | 201 | |
202 | - if ( 1 !== count( $source_trace ) ) { |
|
202 | + if (1 !== count($source_trace)) { |
|
203 | 203 | throw Plugin_State_Exception::failed_to_locate_calling_file(); |
204 | 204 | } |
205 | 205 | |
206 | - if ( ! \array_key_exists( 'file', $source_trace[0] ) ) { |
|
206 | + if ( ! \array_key_exists('file', $source_trace[0])) { |
|
207 | 207 | throw Plugin_State_Exception::failed_to_locate_calling_file(); |
208 | 208 | } |
209 | 209 |