Passed
Branch master (2944c0)
by Glynn
07:41
created
src/Plugin_State_Controller.php 1 patch
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,24 +90,24 @@  discard block
 block discarded – undo
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 {
94
-		if ( ! is_subclass_of( $state_event, Plugin_State_Change::class ) ) {
95
-			throw Plugin_State_Exception::invalid_state_change_event_type( $state_event );
93
+	public function event($state_event): self {
94
+		if ( ! is_subclass_of($state_event, Plugin_State_Change::class)) {
95
+			throw Plugin_State_Exception::invalid_state_change_event_type($state_event);
96 96
 		}
97 97
 		// If its a string, attempt to create via DI container.
98
-		if ( is_string( $state_event ) ) {
98
+		if (is_string($state_event)) {
99 99
 			$state_event_string = $state_event;
100 100
 
101 101
 			try {
102 102
 				/** @var Plugin_State_Change|null */
103
-				$state_event = $this->app->get_container()->create( $state_event );
104
-			} catch ( \Throwable $th ) {
105
-				throw Plugin_State_Exception::failed_to_create_state_change_event( $state_event_string );
103
+				$state_event = $this->app->get_container()->create($state_event);
104
+			} catch (\Throwable $th) {
105
+				throw Plugin_State_Exception::failed_to_create_state_change_event($state_event_string);
106 106
 			}
107 107
 
108 108
 			// Throw exception if failed to create
109
-			if ( null === $state_event || ! is_a( $state_event, Plugin_State_Change::class ) ) {
110
-				throw Plugin_State_Exception::failed_to_create_state_change_event( $state_event_string );
109
+			if (null === $state_event || ! is_a($state_event, Plugin_State_Change::class)) {
110
+				throw Plugin_State_Exception::failed_to_create_state_change_event($state_event_string);
111 111
 			}
112 112
 		}
113 113
 		$this->state_events[] = $state_event;
@@ -121,35 +121,35 @@  discard block
 block discarded – undo
121 121
 	 * @return self
122 122
 	 * @throws Plugin_State_Exception [103] failed_to_locate_calling_file()
123 123
 	 */
124
-	public function finalise( ?string $file = null ): self {
125
-		if ( null === $file ) {
124
+	public function finalise(?string $file = null): self {
125
+		if (null === $file) {
126 126
 			$file = $this->plugin_base_file ?? $this->get_called_file();
127 127
 		}
128 128
 
129 129
 		// Activation hooks if need adding.
130
-		if ( $this->has_events_for_state( Activation::class ) ) {
131
-			register_activation_hook( $file, $this->activation() );
130
+		if ($this->has_events_for_state(Activation::class)) {
131
+			register_activation_hook($file, $this->activation());
132 132
 		}
133 133
 
134 134
 		// Deactivation hooks.
135
-		if ( $this->has_events_for_state( Deactivation::class ) ) {
136
-			register_deactivation_hook( $file, $this->deactivation() );
135
+		if ($this->has_events_for_state(Deactivation::class)) {
136
+			register_deactivation_hook($file, $this->deactivation());
137 137
 		}
138 138
 
139 139
 		// If we have an uninstall events, add then during activation.
140
-		if ( $this->has_events_for_state( Uninstall::class ) ) {
140
+		if ($this->has_events_for_state(Uninstall::class)) {
141 141
 			$callback = $this->uninstall();
142 142
 
143 143
 			// Register the callback so itsits included (but wont run due to serialization issues).
144 144
 			register_activation_hook(
145 145
 				$file,
146
-				static function() use ( $file, $callback ): void {
147
-					register_uninstall_hook( $file, $callback );
146
+				static function() use ($file, $callback): void {
147
+					register_uninstall_hook($file, $callback);
148 148
 				}
149 149
 			);
150 150
 
151 151
 			// Manually re-add the uninstall hook.
152
-			add_action( 'uninstall_' . plugin_basename( $file ), $callback );
152
+			add_action('uninstall_'.plugin_basename($file), $callback);
153 153
 		}
154 154
 
155 155
 		return $this;
@@ -161,11 +161,11 @@  discard block
 block discarded – undo
161 161
 	 * @param string $state
162 162
 	 * @return Plugin_State_Change[]
163 163
 	 */
164
-	private function get_events_for_state( string $state ): array {
164
+	private function get_events_for_state(string $state): array {
165 165
 		return array_filter(
166 166
 			$this->state_events,
167
-			function( $e ) use ( $state ): bool {
168
-				return is_subclass_of( $e, $state );
167
+			function($e) use ($state): bool {
168
+				return is_subclass_of($e, $state);
169 169
 			}
170 170
 		);
171 171
 	}
@@ -176,8 +176,8 @@  discard block
 block discarded – undo
176 176
 	 * @param string $state
177 177
 	 * @return bool
178 178
 	 */
179
-	private function has_events_for_state( string $state ): bool {
180
-		return count( $this->get_events_for_state( $state ) ) !== 0;
179
+	private function has_events_for_state(string $state): bool {
180
+		return count($this->get_events_for_state($state)) !== 0;
181 181
 	}
182 182
 
183 183
 	/**
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 	 * @return State_Change_Queue
187 187
 	 */
188 188
 	public function activation(): State_Change_Queue {
189
-		return new State_Change_Queue( ...$this->get_events_for_state( Activation::class ) );
189
+		return new State_Change_Queue(...$this->get_events_for_state(Activation::class));
190 190
 	}
191 191
 
192 192
 	/**
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 	 * @return State_Change_Queue
196 196
 	 */
197 197
 	public function deactivation(): State_Change_Queue {
198
-		return new State_Change_Queue( ...$this->get_events_for_state( Deactivation::class ) );
198
+		return new State_Change_Queue(...$this->get_events_for_state(Deactivation::class));
199 199
 	}
200 200
 
201 201
 	/**
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 	 * @return State_Change_Queue
205 205
 	 */
206 206
 	public function uninstall(): State_Change_Queue {
207
-		return new State_Change_Queue( ...$this->get_events_for_state( Uninstall::class ) );
207
+		return new State_Change_Queue(...$this->get_events_for_state(Uninstall::class));
208 208
 	}
209 209
 
210 210
 	/**
@@ -216,16 +216,16 @@  discard block
 block discarded – undo
216 216
 	protected function get_called_file(): string {
217 217
 		$backtrace = debug_backtrace(); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace
218 218
 
219
-		$backtrace_count = count( $backtrace );
220
-		for ( $i = 0; $i < $backtrace_count; $i++ ) {
221
-			if ( $backtrace[ $i ]['function'] === __FUNCTION__
222
-			&& \array_key_exists( 'class', $backtrace[ $i ] )
223
-			&& $backtrace[ $i ]['class'] === get_class()
224
-			&& \array_key_exists( ( $i + 1 ), $backtrace )
225
-			&& \array_key_exists( 'file', $backtrace[ $i + 1 ] )
219
+		$backtrace_count = count($backtrace);
220
+		for ($i = 0; $i < $backtrace_count; $i++) {
221
+			if ($backtrace[$i]['function'] === __FUNCTION__
222
+			&& \array_key_exists('class', $backtrace[$i])
223
+			&& $backtrace[$i]['class'] === get_class()
224
+			&& \array_key_exists(($i + 1), $backtrace)
225
+			&& \array_key_exists('file', $backtrace[$i + 1])
226 226
 
227 227
 			) {
228
-				return $backtrace[ $i + 1 ]['file'];
228
+				return $backtrace[$i + 1]['file'];
229 229
 			}
230 230
 		}
231 231
 		// @codeCoverageIgnoreStart
Please login to merge, or discard this patch.