Passed
Push — master ( dfa187...32ba6c )
by Glynn
04:44 queued 02:57
created
src/State_Event/Activation.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,4 +14,4 @@
 block discarded – undo
14 14
 
15 15
 use PinkCrab\Plugin_Lifecycle\Plugin_State_Change;
16 16
 
17
-interface Activation extends Plugin_State_Change{}
17
+interface Activation extends Plugin_State_Change {}
Please login to merge, or discard this patch.
src/State_Event/Deactivation.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,4 +14,4 @@
 block discarded – undo
14 14
 
15 15
 use PinkCrab\Plugin_Lifecycle\Plugin_State_Change;
16 16
 
17
-interface Deactivation extends Plugin_State_Change{}
17
+interface Deactivation extends Plugin_State_Change {}
Please login to merge, or discard this patch.
src/State_Change_Queue.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	protected $events;
26 26
 
27 27
 	/** @param Plugin_State_Change ...$event */
28
-	public function __construct( Plugin_State_Change ...$event ) {
28
+	public function __construct(Plugin_State_Change ...$event) {
29 29
 		$this->events = $event;
30 30
 	}
31 31
 
@@ -35,13 +35,13 @@  discard block
 block discarded – undo
35 35
 	 * @return void
36 36
 	 */
37 37
 	public function __invoke() {
38
-		foreach ( $this->events as $event ) {
38
+		foreach ($this->events as $event) {
39 39
 			try {
40 40
 				$event->run();
41
-			} catch ( \Throwable $th ) {
41
+			} catch (\Throwable $th) {
42 42
 				// If caught on Activation, throw Plugin_State_Exception
43
-				if ( is_a( $event, Activation::class ) ) {
44
-					throw Plugin_State_Exception::error_running_state_change_event( $event, $th );
43
+				if (is_a($event, Activation::class)) {
44
+					throw Plugin_State_Exception::error_running_state_change_event($event, $th);
45 45
 				}
46 46
 
47 47
 				continue;
Please login to merge, or discard this patch.
src/Plugin_State_Exception.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -24,13 +24,13 @@  discard block
 block discarded – undo
24 24
 	 * @param Throwable|null $exception
25 25
 	 * @return Plugin_State_Exception
26 26
 	 */
27
-	public static function failed_to_create_state_change_event( $event, ?Throwable $exception = null ): Plugin_State_Exception {
27
+	public static function failed_to_create_state_change_event($event, ?Throwable $exception = null): Plugin_State_Exception {
28 28
 		$message = \sprintf(
29 29
 			'Failed to construct %s using the DI Container. %s',
30
-			is_string( $event ) ? $event : get_class( $event ),
30
+			is_string($event) ? $event : get_class($event),
31 31
 			$exception ? $exception->getMessage() : ''
32 32
 		);
33
-		return new Plugin_State_Exception( $message, 101 );
33
+		return new Plugin_State_Exception($message, 101);
34 34
 	}
35 35
 
36 36
 	/**
@@ -39,12 +39,12 @@  discard block
 block discarded – undo
39 39
 	 * @param string|object $event
40 40
 	 * @return Plugin_State_Exception
41 41
 	 */
42
-	public static function invalid_state_change_event_type( $event ): Plugin_State_Exception {
42
+	public static function invalid_state_change_event_type($event): Plugin_State_Exception {
43 43
 		$message = \sprintf(
44 44
 			'%s is not a valid Plugin State Change Event class',
45
-			is_string( $event ) ? $event : get_class( $event )
45
+			is_string($event) ? $event : get_class($event)
46 46
 		);
47
-		return new Plugin_State_Exception( $message, 102 );
47
+		return new Plugin_State_Exception($message, 102);
48 48
 	}
49 49
 
50 50
 	/**
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 	 * @return Plugin_State_Exception
54 54
 	 */
55 55
 	public static function failed_to_locate_calling_file(): Plugin_State_Exception {
56
-		return new Plugin_State_Exception( 'Could not locate the file which created the Plugin State Controller. Please define this value manually using $controller->finalise( string $file )', 103 );
56
+		return new Plugin_State_Exception('Could not locate the file which created the Plugin State Controller. Please define this value manually using $controller->finalise( string $file )', 103);
57 57
 	}
58 58
 
59 59
 	/**
@@ -63,13 +63,13 @@  discard block
 block discarded – undo
63 63
 	 * @param Throwable $exception
64 64
 	 * @return Plugin_State_Exception
65 65
 	 */
66
-	public static function error_running_state_change_event( Plugin_State_Change $event, ?Throwable $exception = null ): Plugin_State_Exception {
66
+	public static function error_running_state_change_event(Plugin_State_Change $event, ?Throwable $exception = null): Plugin_State_Exception {
67 67
 		$message = \sprintf(
68 68
 			'Failed to run %s->run(), error thrown::%s',
69
-			get_class( $event ),
69
+			get_class($event),
70 70
 			$exception === null ? 'NO ERROR PASSED' : $exception->getMessage()
71 71
 		);
72
-		return new Plugin_State_Exception( $message, 104 );
72
+		return new Plugin_State_Exception($message, 104);
73 73
 	}
74 74
 
75 75
 	/**
@@ -78,8 +78,8 @@  discard block
 block discarded – undo
78 78
 	 * @param ?string $error
79 79
 	 * @return Plugin_State_Exception
80 80
 	 */
81
-	public static function invalid_plugin_base_file( $error = null ): Plugin_State_Exception {
82
-		return new Plugin_State_Exception( is_string( $error ) ? $error : 'No plugin base file name passed.', 105 );
81
+	public static function invalid_plugin_base_file($error = null): Plugin_State_Exception {
82
+		return new Plugin_State_Exception(is_string($error) ? $error : 'No plugin base file name passed.', 105);
83 83
 	}
84 84
 
85 85
 	/**
@@ -88,6 +88,6 @@  discard block
 block discarded – undo
88 88
 	 * @return Plugin_State_Exception
89 89
 	 */
90 90
 	public static function missing_controller(): Plugin_State_Exception {
91
-		return new Plugin_State_Exception( 'No Plugin State Controller passed.', 106 );
91
+		return new Plugin_State_Exception('No Plugin State Controller passed.', 106);
92 92
 	}
93 93
 }
Please login to merge, or discard this patch.
src/Plugin_Life_Cycle.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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 {
Please login to merge, or discard this patch.
src/Plugin_State_Controller.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.