@@ -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,11 +132,11 @@ 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 { |
|
135 | + public function pre_register(App_Config $config, Hook_Loader $loader, DI_Container $di_container): void { |
|
136 | 136 | } // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed |
137 | 137 | |
138 | 138 | /** @inheritDoc */ |
139 | - public function post_register( App_Config $config, Hook_Loader $loader, DI_Container $di_container ): void { |
|
139 | + public function post_register(App_Config $config, Hook_Loader $loader, DI_Container $di_container): void { |
|
140 | 140 | } // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed |
141 | 141 | |
142 | 142 | /** @inheritDoc */ |
@@ -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,34 +97,34 @@ discard block |
||
97 | 97 | $file = $this->plugin_base_file; |
98 | 98 | |
99 | 99 | // Fail if file hasn't been set. |
100 | - if ( null === $file ) { |
|
101 | - throw Plugin_State_Exception::invalid_plugin_base_file( $this->plugin_base_file ); |
|
100 | + if (null === $file) { |
|
101 | + throw Plugin_State_Exception::invalid_plugin_base_file($this->plugin_base_file); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | // Activation hooks if need adding. |
105 | - if ( $this->has_events_for_state( Activation::class ) ) { |
|
106 | - register_activation_hook( $file, $this->activation() ); |
|
105 | + if ($this->has_events_for_state(Activation::class)) { |
|
106 | + register_activation_hook($file, $this->activation()); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | // Deactivation hooks. |
110 | - if ( $this->has_events_for_state( Deactivation::class ) ) { |
|
111 | - register_deactivation_hook( $file, $this->deactivation() ); |
|
110 | + if ($this->has_events_for_state(Deactivation::class)) { |
|
111 | + register_deactivation_hook($file, $this->deactivation()); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | // If we have an uninstall events, add then during activation. |
115 | - if ( $this->has_events_for_state( Uninstall::class ) ) { |
|
115 | + if ($this->has_events_for_state(Uninstall::class)) { |
|
116 | 116 | $callback = $this->uninstall(); |
117 | 117 | |
118 | 118 | // Register the callback so itsits included (but wont run due to serialization issues). |
119 | 119 | register_activation_hook( |
120 | 120 | $file, |
121 | - static function () use ( $file, $callback ): void { |
|
122 | - register_uninstall_hook( $file, $callback ); |
|
121 | + static function() use ($file, $callback): void { |
|
122 | + register_uninstall_hook($file, $callback); |
|
123 | 123 | } |
124 | 124 | ); |
125 | 125 | |
126 | 126 | // Manually re-add the uninstall hook. |
127 | - add_action( 'uninstall_' . plugin_basename( $file ), $callback ); |
|
127 | + add_action('uninstall_'.plugin_basename($file), $callback); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | return $this; |
@@ -137,12 +137,12 @@ discard block |
||
137 | 137 | * |
138 | 138 | * @return Plugin_State_Change[] |
139 | 139 | */ |
140 | - private function get_events_for_state( string $state ): array { |
|
140 | + private function get_events_for_state(string $state): array { |
|
141 | 141 | return array_filter( |
142 | - apply_filters( Plugin_Life_Cycle::EVENT_LIST, $this->state_events ), |
|
143 | - function ( $e ) use ( $state ): bool { |
|
142 | + apply_filters(Plugin_Life_Cycle::EVENT_LIST, $this->state_events), |
|
143 | + function($e) use ($state): bool { |
|
144 | 144 | /* @phpstan-ignore-next-line */ |
145 | - return is_subclass_of( $e, $state ); |
|
145 | + return is_subclass_of($e, $state); |
|
146 | 146 | } |
147 | 147 | ); |
148 | 148 | } |
@@ -154,8 +154,8 @@ discard block |
||
154 | 154 | * |
155 | 155 | * @return bool |
156 | 156 | */ |
157 | - private function has_events_for_state( string $state ): bool { |
|
158 | - return count( $this->get_events_for_state( $state ) ) !== 0; |
|
157 | + private function has_events_for_state(string $state): bool { |
|
158 | + return count($this->get_events_for_state($state)) !== 0; |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * @return State_Change_Queue |
165 | 165 | */ |
166 | 166 | public function activation(): State_Change_Queue { |
167 | - return new State_Change_Queue( ...$this->get_events_for_state( Activation::class ) ); |
|
167 | + return new State_Change_Queue(...$this->get_events_for_state(Activation::class)); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | * @return State_Change_Queue |
174 | 174 | */ |
175 | 175 | public function deactivation(): State_Change_Queue { |
176 | - return new State_Change_Queue( ...$this->get_events_for_state( Deactivation::class ) ); |
|
176 | + return new State_Change_Queue(...$this->get_events_for_state(Deactivation::class)); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * @return State_Change_Queue |
183 | 183 | */ |
184 | 184 | public function uninstall(): State_Change_Queue { |
185 | - return new State_Change_Queue( ...$this->get_events_for_state( Uninstall::class ) ); |
|
185 | + return new State_Change_Queue(...$this->get_events_for_state(Uninstall::class)); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -198,17 +198,17 @@ discard block |
||
198 | 198 | $source_trace = array_values( |
199 | 199 | array_filter( |
200 | 200 | $backtrace, |
201 | - function ( $bt ) { |
|
202 | - return array_key_exists( 'class', $bt ) && $bt['class'] === App_Factory::class; |
|
201 | + function($bt) { |
|
202 | + return array_key_exists('class', $bt) && $bt['class'] === App_Factory::class; |
|
203 | 203 | } |
204 | 204 | ) |
205 | 205 | ); |
206 | 206 | |
207 | - if ( 1 !== count( $source_trace ) ) { |
|
207 | + if (1 !== count($source_trace)) { |
|
208 | 208 | throw Plugin_State_Exception::failed_to_locate_calling_file(); |
209 | 209 | } |
210 | 210 | |
211 | - if ( ! \array_key_exists( 'file', $source_trace[0] ) ) { |
|
211 | + if ( ! \array_key_exists('file', $source_trace[0])) { |
|
212 | 212 | throw Plugin_State_Exception::failed_to_locate_calling_file(); |
213 | 213 | } |
214 | 214 |