Passed
Pull Request — master (#198)
by Glynn
09:05
created
src/Application/App.php 1 patch
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -106,11 +106,11 @@  discard block
 block discarded – undo
106 106
 	 *
107 107
 	 * @param string $base_path
108 108
 	 */
109
-	public function __construct( string $base_path ) {
109
+	public function __construct(string $base_path) {
110 110
 		$this->base_path = $base_path;
111 111
 
112 112
 		// Assume the view path.
113
-		$this->view_path = rtrim( $this->base_path, '/\\' ) . \DIRECTORY_SEPARATOR . 'views';
113
+		$this->view_path = rtrim($this->base_path, '/\\') . \DIRECTORY_SEPARATOR . 'views';
114 114
 	}
115 115
 
116 116
 	/**
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	 * @param string $view_path
120 120
 	 * @return self
121 121
 	 */
122
-	public function set_view_path( string $view_path ): self {
122
+	public function set_view_path(string $view_path): self {
123 123
 		$this->view_path = $view_path;
124 124
 		return $this;
125 125
 	}
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
 	 * @return self
132 132
 	 * @throws App_Initialization_Exception Code 2
133 133
 	 */
134
-	public function set_container( DI_Container $container ): self {
135
-		if ( self::$container !== null ) {
134
+	public function set_container(DI_Container $container): self {
135
+		if (self::$container !== null) {
136 136
 			throw App_Initialization_Exception::di_container_exists();
137 137
 		}
138 138
 
@@ -157,28 +157,28 @@  discard block
 block discarded – undo
157 157
 	 * @return self
158 158
 	 * @throws App_Initialization_Exception Code 5
159 159
 	 */
160
-	public function set_app_config( array $settings ): self {
161
-		if ( self::$app_config !== null ) {
160
+	public function set_app_config(array $settings): self {
161
+		if (self::$app_config !== null) {
162 162
 			throw App_Initialization_Exception::app_config_exists();
163 163
 		}
164 164
 
165 165
 		// Run through the filter to allow for config changes.
166
-		$settings = apply_filters( Hooks::APP_INIT_CONFIG_VALUES, $settings );
166
+		$settings = apply_filters(Hooks::APP_INIT_CONFIG_VALUES, $settings);
167 167
 
168 168
 		// Ensure the base path and url are defined from app.
169 169
 		$settings['path']           = $settings['path'] ?? array();
170 170
 		$settings['path']['plugin'] = $this->base_path;
171
-		$settings['path']['view']   = $this->view_path ?? App_Config_Path_Helper::assume_view_path( $this->base_path );
171
+		$settings['path']['view']   = $this->view_path ?? App_Config_Path_Helper::assume_view_path($this->base_path);
172 172
 
173 173
 		// Get the url from the base path.
174 174
 		$settings['url']           = $settings['url'] ?? array();
175
-		$settings['url']['plugin'] = App_Config_Path_Helper::assume_base_url( $this->base_path );
175
+		$settings['url']['plugin'] = App_Config_Path_Helper::assume_base_url($this->base_path);
176 176
 		$settings['url']['view']   = App_Config_Path_Helper::assume_view_url(
177 177
 			$this->base_path,
178
-			$this->view_path ?? App_Config_Path_Helper::assume_view_path( $this->base_path )
178
+			$this->view_path ?? App_Config_Path_Helper::assume_view_path($this->base_path)
179 179
 		);
180 180
 
181
-		self::$app_config = new App_Config( $settings );
181
+		self::$app_config = new App_Config($settings);
182 182
 		return $this;
183 183
 	}
184 184
 
@@ -189,8 +189,8 @@  discard block
 block discarded – undo
189 189
 	 * @return self
190 190
 	 * @throws App_Initialization_Exception Code 10
191 191
 	 */
192
-	public function set_module_manager( Module_Manager $module_manager ): self {
193
-		if ( $this->module_manager !== null ) {
192
+	public function set_module_manager(Module_Manager $module_manager): self {
193
+		if ($this->module_manager !== null) {
194 194
 			throw App_Initialization_Exception::module_manager_exists();
195 195
 		}
196 196
 
@@ -204,8 +204,8 @@  discard block
 block discarded – undo
204 204
 	 * @param \PinkCrab\Loader\Hook_Loader $loader
205 205
 	 * @return self
206 206
 	 */
207
-	public function set_loader( Hook_Loader $loader ): self {
208
-		if ( $this->loader !== null ) {
207
+	public function set_loader(Hook_Loader $loader): self {
208
+		if ($this->loader !== null) {
209 209
 			throw App_Initialization_Exception::loader_exists();
210 210
 		}
211 211
 		$this->loader = $loader;
@@ -220,11 +220,11 @@  discard block
 block discarded – undo
220 220
 	 * @return self
221 221
 	 * @throws App_Initialization_Exception Code 1
222 222
 	 */
223
-	public function container_config( callable $callback ): self {
224
-		if ( self::$container === null ) {
223
+	public function container_config(callable $callback): self {
224
+		if (self::$container === null) {
225 225
 			throw App_Initialization_Exception::requires_di_container();
226 226
 		}
227
-		$callback( self::$container );
227
+		$callback(self::$container);
228 228
 		return $this;
229 229
 	}
230 230
 
@@ -235,13 +235,13 @@  discard block
 block discarded – undo
235 235
 	 * @return self
236 236
 	 * @throws App_Initialization_Exception Code 3
237 237
 	 */
238
-	public function registration_classes( array $class_list ): self {
239
-		if ( $this->module_manager === null ) {
238
+	public function registration_classes(array $class_list): self {
239
+		if ($this->module_manager === null) {
240 240
 			throw App_Initialization_Exception::requires_module_manager();
241 241
 		}
242 242
 
243
-		foreach ( $class_list as $class ) {
244
-			$this->module_manager->register_class( $class );
243
+		foreach ($class_list as $class) {
244
+			$this->module_manager->register_class($class);
245 245
 		}
246 246
 		return $this;
247 247
 	}
@@ -256,17 +256,17 @@  discard block
 block discarded – undo
256 256
 	 * @throws App_Initialization_Exception Code 1 If DI container not registered
257 257
 	 * @throws App_Initialization_Exception Code 3 If module manager not defined.
258 258
 	 */
259
-	public function module( string $module, ?callable $callback = null ): self {
259
+	public function module(string $module, ?callable $callback = null): self {
260 260
 		// Check if module manager exists.
261
-		if ( $this->module_manager === null ) {
261
+		if ($this->module_manager === null) {
262 262
 			throw App_Initialization_Exception::requires_module_manager();
263 263
 		}
264 264
 
265
-		if ( self::$container === null ) {
265
+		if (self::$container === null) {
266 266
 			throw App_Initialization_Exception::requires_di_container();
267 267
 		}
268 268
 
269
-		$this->module_manager->push_module( $module, $callback );
269
+		$this->module_manager->push_module($module, $callback);
270 270
 
271 271
 		return $this;
272 272
 	}
@@ -280,9 +280,9 @@  discard block
 block discarded – undo
280 280
 	public function boot(): self {
281 281
 
282 282
 		// Validate.
283
-		$validate = new App_Validation( $this );
284
-		if ( $validate->validate() === false ) {
285
-			throw App_Initialization_Exception::failed_boot_validation( array_map( 'esc_attr', $validate->errors ) );
283
+		$validate = new App_Validation($this);
284
+		if ($validate->validate() === false) {
285
+			throw App_Initialization_Exception::failed_boot_validation(array_map('esc_attr', $validate->errors));
286 286
 		}
287 287
 
288 288
 		// Run the final process, where all are loaded in via
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 			Inject_Hook_Loader::class,
332 332
 			array(
333 333
 				'call' => array(
334
-					array( 'set_hook_loader', array( $this->loader ) ),
334
+					array('set_hook_loader', array($this->loader)),
335 335
 				),
336 336
 			)
337 337
 		);
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
 			Inject_App_Config::class,
342 342
 			array(
343 343
 				'call' => array(
344
-					array( 'set_app_config', array( self::$app_config ) ),
344
+					array('set_app_config', array(self::$app_config)),
345 345
 				),
346 346
 			)
347 347
 		);
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 			Inject_DI_Container::class,
352 352
 			array(
353 353
 				'call' => array(
354
-					array( 'set_di_container', array( self::$container ) ),
354
+					array('set_di_container', array(self::$container)),
355 355
 				),
356 356
 			)
357 357
 		);
@@ -362,15 +362,15 @@  discard block
 block discarded – undo
362 362
 		/**
363 363
  * @hook{string, App_Config, Loader, DI_Container}
364 364
 */
365
-		do_action( Hooks::APP_INIT_PRE_BOOT, self::$app_config, $this->loader, self::$container ); // phpcs:disable WordPress.NamingConventions.ValidHookName.*
365
+		do_action(Hooks::APP_INIT_PRE_BOOT, self::$app_config, $this->loader, self::$container); // phpcs:disable WordPress.NamingConventions.ValidHookName.*
366 366
 
367 367
 		// Initialise on init
368 368
 		add_action(
369 369
 			'init',
370
-			function () {
371
-				do_action( Hooks::APP_INIT_PRE_REGISTRATION, self::$app_config, $this->loader, self::$container );
370
+			function() {
371
+				do_action(Hooks::APP_INIT_PRE_REGISTRATION, self::$app_config, $this->loader, self::$container);
372 372
 				$this->module_manager->process_middleware(); // @phpstan-ignore-line, already verified if not null
373
-				do_action( Hooks::APP_INIT_POST_REGISTRATION, self::$app_config, $this->loader, self::$container );
373
+				do_action(Hooks::APP_INIT_POST_REGISTRATION, self::$app_config, $this->loader, self::$container);
374 374
 				$this->loader->register_hooks(); // @phpstan-ignore-line, if loader is not defined, exception will be thrown above
375 375
 			},
376 376
 			1
@@ -390,11 +390,11 @@  discard block
 block discarded – undo
390 390
 	 * @return object|null
391 391
 	 * @throws App_Initialization_Exception Code 4
392 392
 	 */
393
-	public static function make( string $class_string, array $args = array() ): ?object {
394
-		if ( self::$booted === false ) {
395
-			throw App_Initialization_Exception::app_not_initialized( DI_Container::class );
393
+	public static function make(string $class_string, array $args = array()): ?object {
394
+		if (self::$booted === false) {
395
+			throw App_Initialization_Exception::app_not_initialized(DI_Container::class);
396 396
 		}
397
-		return self::$container->create( $class_string, $args ); // @phpstan-ignore-line, already verified if not null
397
+		return self::$container->create($class_string, $args); // @phpstan-ignore-line, already verified if not null
398 398
 	}
399 399
 
400 400
 	/**
@@ -405,11 +405,11 @@  discard block
 block discarded – undo
405 405
 	 * @return mixed
406 406
 	 * @throws App_Initialization_Exception Code 4
407 407
 	 */
408
-	public static function config( string $key, string ...$child ) {
409
-		if ( self::$booted === false ) {
410
-			throw App_Initialization_Exception::app_not_initialized( App_Config::class );
408
+	public static function config(string $key, string ...$child) {
409
+		if (self::$booted === false) {
410
+			throw App_Initialization_Exception::app_not_initialized(App_Config::class);
411 411
 		}
412
-		return self::$app_config->{$key}( ...$child );
412
+		return self::$app_config->{$key}(...$child);
413 413
 	}
414 414
 
415 415
 	/**
@@ -419,13 +419,13 @@  discard block
 block discarded – undo
419 419
 	 * @throws App_Initialization_Exception Code 4
420 420
 	 */
421 421
 	public static function view(): ?View {
422
-		if ( self::$booted === false ) {
423
-			throw App_Initialization_Exception::app_not_initialized( View::class );
422
+		if (self::$booted === false) {
423
+			throw App_Initialization_Exception::app_not_initialized(View::class);
424 424
 		}
425 425
 		/**
426 426
  * @var ?View
427 427
 */
428
-		return self::$container->create( View::class ); // @phpstan-ignore-line, already verified if not null
428
+		return self::$container->create(View::class); // @phpstan-ignore-line, already verified if not null
429 429
 	}
430 430
 
431 431
 	/**
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
 	 * @return boolean
458 458
 	 */
459 459
 	public function has_app_config(): bool {
460
-		return Object_Helper::is_a( self::$app_config, App_Config::class );
460
+		return Object_Helper::is_a(self::$app_config, App_Config::class);
461 461
 	}
462 462
 
463 463
 	/**
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
 	 * @throws App_Initialization_Exception (Code 1)
468 468
 	 */
469 469
 	public function get_container(): DI_Container {
470
-		if ( self::$container === null ) {
470
+		if (self::$container === null) {
471 471
 			// Throw container not set.
472 472
 			throw App_Initialization_Exception::requires_di_container();
473 473
 		}
Please login to merge, or discard this patch.
src/Application/App_Config.php 1 patch
Spacing   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -95,9 +95,9 @@  discard block
 block discarded – undo
95 95
 	/**
96 96
 	 * @param array<string, mixed> $settings
97 97
 	 */
98
-	public function __construct( array $settings = array() ) {
99
-		$settings = $this->set_defaults( $settings );
100
-		$this->set_props( $settings );
98
+	public function __construct(array $settings = array()) {
99
+		$settings = $this->set_defaults($settings);
100
+		$this->set_props($settings);
101 101
 	}
102 102
 
103 103
 	/**
@@ -106,8 +106,8 @@  discard block
 block discarded – undo
106 106
 	 * @param array<string, mixed> $settings
107 107
 	 * @return array<string, mixed>
108 108
 	 */
109
-	private function set_defaults( array $settings ): array {
110
-		return array_replace_recursive( $this->settings_defaults(), $settings );
109
+	private function set_defaults(array $settings): array {
110
+		return array_replace_recursive($this->settings_defaults(), $settings);
111 111
 	}
112 112
 
113 113
 	/**
@@ -117,17 +117,17 @@  discard block
 block discarded – undo
117 117
 	 *
118 118
 	 * @return void
119 119
 	 */
120
-	private function set_props( array $settings ): void {
120
+	private function set_props(array $settings): void {
121 121
 		$this->paths['url']  = $settings['url'];
122 122
 		$this->paths['path'] = $settings['path'];
123
-		$this->namespaces    = $this->filter_key_value_pair( $settings['namespaces'] );
123
+		$this->namespaces    = $this->filter_key_value_pair($settings['namespaces']);
124 124
 		$this->plugin        = $settings['plugin'];
125 125
 		$this->additional    = $settings['additional'];
126
-		$this->db_tables     = $this->filter_key_value_pair( $settings['db_tables'] );
127
-		$this->post_types    = $this->filter_key_value_pair( $settings['post_types'] );
128
-		$this->taxonomies    = $this->filter_key_value_pair( $settings['taxonomies'] );
126
+		$this->db_tables     = $this->filter_key_value_pair($settings['db_tables']);
127
+		$this->post_types    = $this->filter_key_value_pair($settings['post_types']);
128
+		$this->taxonomies    = $this->filter_key_value_pair($settings['taxonomies']);
129 129
 
130
-		$this->set_meta( $settings['meta'] );
130
+		$this->set_meta($settings['meta']);
131 131
 	}
132 132
 
133 133
 	/**
@@ -138,14 +138,14 @@  discard block
 block discarded – undo
138 138
 	 *
139 139
 	 * @return array<string, mixed>|string|null
140 140
 	 */
141
-	public function path( ?string $path = null, ?string $default_value = null ) {
141
+	public function path(?string $path = null, ?string $default_value = null) {
142 142
 
143
-		if ( is_null( $path ) ) {
143
+		if (is_null($path)) {
144 144
 			return $this->paths['path'];
145 145
 		}
146 146
 
147
-		return \array_key_exists( $path, $this->paths['path'] )
148
-			? trailingslashit( $this->paths['path'][ $path ] )
147
+		return \array_key_exists($path, $this->paths['path'])
148
+			? trailingslashit($this->paths['path'][$path])
149 149
 			: $default_value;
150 150
 	}
151 151
 
@@ -157,14 +157,14 @@  discard block
 block discarded – undo
157 157
 	 *
158 158
 	 * @return array<string, mixed>|string|null
159 159
 	 */
160
-	public function url( ?string $url = null, ?string $default_value = null ) {
160
+	public function url(?string $url = null, ?string $default_value = null) {
161 161
 
162
-		if ( is_null( $url ) ) {
162
+		if (is_null($url)) {
163 163
 			return $this->paths['url'];
164 164
 		}
165 165
 
166
-		return \array_key_exists( $url, $this->paths['url'] )
167
-			? trailingslashit( $this->paths['url'][ $url ] )
166
+		return \array_key_exists($url, $this->paths['url'])
167
+			? trailingslashit($this->paths['url'][$url])
168 168
 			: $default_value;
169 169
 	}
170 170
 
@@ -194,9 +194,9 @@  discard block
 block discarded – undo
194 194
 	 *
195 195
 	 * @return string|null
196 196
 	 */
197
-	public function namespace( string $key, ?string $default_value = null ): ?string {
198
-		return array_key_exists( $key, $this->namespaces )
199
-			? $this->namespaces[ $key ] : $default_value;
197
+	public function namespace(string $key, ?string $default_value = null) : ?string {
198
+		return array_key_exists($key, $this->namespaces)
199
+			? $this->namespaces[$key] : $default_value;
200 200
 	}
201 201
 
202 202
 	/**
@@ -207,9 +207,9 @@  discard block
 block discarded – undo
207 207
 	 *
208 208
 	 * @return mixed
209 209
 	 */
210
-	public function additional( string $key, ?string $default_value = null ) {
211
-		return array_key_exists( $key, $this->additional )
212
-			? $this->additional[ $key ] : $default_value;
210
+	public function additional(string $key, ?string $default_value = null) {
211
+		return array_key_exists($key, $this->additional)
212
+			? $this->additional[$key] : $default_value;
213 213
 	}
214 214
 
215 215
 	/**
@@ -237,12 +237,12 @@  discard block
 block discarded – undo
237 237
 	 * @return string
238 238
 	 * @throws OutOfBoundsException
239 239
 	 */
240
-	public function post_types( string $key ) {
241
-		if ( ! array_key_exists( $key, $this->post_types ) ) {
242
-			throw new OutOfBoundsException( 'App Config :: "' . esc_html( $key ) . '" is not a defined post type' );
240
+	public function post_types(string $key) {
241
+		if ( ! array_key_exists($key, $this->post_types)) {
242
+			throw new OutOfBoundsException('App Config :: "' . esc_html($key) . '" is not a defined post type');
243 243
 		}
244 244
 
245
-		return $this->post_types[ $key ];
245
+		return $this->post_types[$key];
246 246
 	}
247 247
 
248 248
 	/**
@@ -253,17 +253,17 @@  discard block
 block discarded – undo
253 253
 	 * @return string
254 254
 	 * @throws OutOfBoundsException
255 255
 	 */
256
-	public function meta( string $key, string $type = self::POST_META ): string {
256
+	public function meta(string $key, string $type = self::POST_META): string {
257 257
 		// Check meta type.
258
-		if ( ! array_key_exists( $type, $this->meta ) ) {
259
-			throw new OutOfBoundsException( 'App Config :: "' . esc_html( $type ) . '" is not a valid meta type and cant be fetched' );
258
+		if ( ! array_key_exists($type, $this->meta)) {
259
+			throw new OutOfBoundsException('App Config :: "' . esc_html($type) . '" is not a valid meta type and cant be fetched');
260 260
 		}
261 261
 		// Check key.
262
-		if ( ! array_key_exists( $key, $this->meta[ $type ] ) ) {
263
-			throw new OutOfBoundsException( 'App Config :: "' . esc_html( $key ) . '" is not a defined ' . esc_html( $type ) . 'meta key' );
262
+		if ( ! array_key_exists($key, $this->meta[$type])) {
263
+			throw new OutOfBoundsException('App Config :: "' . esc_html($key) . '" is not a defined ' . esc_html($type) . 'meta key');
264 264
 		}
265 265
 
266
-		return $this->meta[ $type ][ $key ];
266
+		return $this->meta[$type][$key];
267 267
 	}
268 268
 
269 269
 	/**
@@ -273,8 +273,8 @@  discard block
 block discarded – undo
273 273
 	 * @param string $key
274 274
 	 * @return string
275 275
 	 */
276
-	public function post_meta( string $key ): string {
277
-		return $this->meta( $key, self::POST_META );
276
+	public function post_meta(string $key): string {
277
+		return $this->meta($key, self::POST_META);
278 278
 	}
279 279
 
280 280
 	/**
@@ -284,8 +284,8 @@  discard block
 block discarded – undo
284 284
 	 * @param string $key
285 285
 	 * @return string
286 286
 	 */
287
-	public function user_meta( string $key ): string {
288
-		return $this->meta( $key, self::USER_META );
287
+	public function user_meta(string $key): string {
288
+		return $this->meta($key, self::USER_META);
289 289
 	}
290 290
 
291 291
 	/**
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
 	 * @param string $key
296 296
 	 * @return string
297 297
 	 */
298
-	public function term_meta( string $key ): string {
299
-		return $this->meta( $key, self::TERM_META );
298
+	public function term_meta(string $key): string {
299
+		return $this->meta($key, self::TERM_META);
300 300
 	}
301 301
 
302 302
 	/**
@@ -305,15 +305,15 @@  discard block
 block discarded – undo
305 305
 	 * @param array<string, array<string,string>> $meta
306 306
 	 * @return void
307 307
 	 */
308
-	public function set_meta( array $meta ): void {
309
-		$valid_meta_types = array( self::POST_META, self::USER_META, self::TERM_META );
310
-		foreach ( $meta as $meta_type => $pairs ) {
311
-			if ( ! in_array( $meta_type, $valid_meta_types, true ) ) {
312
-				throw new OutOfBoundsException( 'App Config :: "' . esc_html( $meta_type ) . '" is not a valid meta type and cant be defined' );
308
+	public function set_meta(array $meta): void {
309
+		$valid_meta_types = array(self::POST_META, self::USER_META, self::TERM_META);
310
+		foreach ($meta as $meta_type => $pairs) {
311
+			if ( ! in_array($meta_type, $valid_meta_types, true)) {
312
+				throw new OutOfBoundsException('App Config :: "' . esc_html($meta_type) . '" is not a valid meta type and cant be defined');
313 313
 			}
314 314
 
315 315
 			// Set all pairs which have both valid key and values.
316
-			$this->meta[ $meta_type ] = $this->filter_key_value_pair( $pairs );
316
+			$this->meta[$meta_type] = $this->filter_key_value_pair($pairs);
317 317
 		}
318 318
 	}
319 319
 
@@ -324,12 +324,12 @@  discard block
 block discarded – undo
324 324
 	 * @return string
325 325
 	 * @throws OutOfBoundsException
326 326
 	 */
327
-	public function taxonomies( string $key ): string {
328
-		if ( ! array_key_exists( $key, $this->taxonomies ) ) {
329
-			throw new OutOfBoundsException( 'App Config :: "' . esc_html( $key ) . '" is not a defined taxonomy' );
327
+	public function taxonomies(string $key): string {
328
+		if ( ! array_key_exists($key, $this->taxonomies)) {
329
+			throw new OutOfBoundsException('App Config :: "' . esc_html($key) . '" is not a defined taxonomy');
330 330
 		}
331 331
 
332
-		return $this->taxonomies[ $key ];
332
+		return $this->taxonomies[$key];
333 333
 	}
334 334
 
335 335
 
@@ -340,11 +340,11 @@  discard block
 block discarded – undo
340 340
 	 * @return string
341 341
 	 * @throws OutOfBoundsException
342 342
 	 */
343
-	public function db_tables( string $name ): string {
344
-		if ( ! array_key_exists( $name, $this->db_tables ) ) {
345
-			throw new OutOfBoundsException( 'App Config :: "' . esc_html( $name ) . '" is not a defined DB table' );
343
+	public function db_tables(string $name): string {
344
+		if ( ! array_key_exists($name, $this->db_tables)) {
345
+			throw new OutOfBoundsException('App Config :: "' . esc_html($name) . '" is not a defined DB table');
346 346
 		}
347
-		return $this->db_tables[ $name ];
347
+		return $this->db_tables[$name];
348 348
 	}
349 349
 
350 350
 	/**
@@ -353,8 +353,8 @@  discard block
 block discarded – undo
353 353
 	 * @param string $name
354 354
 	 * @return mixed
355 355
 	 */
356
-	public function __get( $name ) {
357
-		return $this->additional( $name );
356
+	public function __get($name) {
357
+		return $this->additional($name);
358 358
 	}
359 359
 
360 360
 	/**
@@ -363,11 +363,11 @@  discard block
 block discarded – undo
363 363
 	 * @return array<string, mixed>
364 364
 	 */
365 365
 	private function settings_defaults(): array {
366
-		$base_path  = \dirname( __DIR__, 2 );
366
+		$base_path  = \dirname(__DIR__, 2);
367 367
 		$wp_uploads = \wp_upload_dir();
368 368
 
369
-		$base_path = App_Config_Path_Helper::normalise_path( $base_path );
370
-		$view_path = App_Config_Path_Helper::assume_view_path( $base_path );
369
+		$base_path = App_Config_Path_Helper::normalise_path($base_path);
370
+		$view_path = App_Config_Path_Helper::assume_view_path($base_path);
371 371
 
372 372
 		global $wpdb;
373 373
 
@@ -384,9 +384,9 @@  discard block
 block discarded – undo
384 384
 				'upload_current' => $wp_uploads['path'],
385 385
 			),
386 386
 			'url'        => array(
387
-				'plugin'         => App_Config_Path_Helper::assume_base_url( $base_path ),
388
-				'view'           => App_Config_Path_Helper::assume_view_url( $base_path, $view_path ),
389
-				'assets'         => App_Config_Path_Helper::assume_base_url( $base_path ) . '/assets',
387
+				'plugin'         => App_Config_Path_Helper::assume_base_url($base_path),
388
+				'view'           => App_Config_Path_Helper::assume_view_url($base_path, $view_path),
389
+				'assets'         => App_Config_Path_Helper::assume_base_url($base_path) . '/assets',
390 390
 				'upload_root'    => $wp_uploads['baseurl'],
391 391
 				'upload_current' => $wp_uploads['url'],
392 392
 			),
@@ -408,17 +408,17 @@  discard block
 block discarded – undo
408 408
 	 * @param array<int|string, mixed> $pairs
409 409
 	 * @return array<string, string>
410 410
 	 */
411
-	private function filter_key_value_pair( array $pairs ): array {
411
+	private function filter_key_value_pair(array $pairs): array {
412 412
 		/**
413 413
 		 * @var array<string, string> (as per filter function)
414 414
 		 */
415 415
 		return array_filter(
416 416
 			$pairs,
417
-			function ( $value, $key ): bool {
418
-				return is_string( $value )
419
-				&& \strlen( $value ) > 0
420
-				&& is_string( $key )
421
-				&& \strlen( $key ) > 0;
417
+			function($value, $key): bool {
418
+				return is_string($value)
419
+				&& \strlen($value) > 0
420
+				&& is_string($key)
421
+				&& \strlen($key) > 0;
422 422
 			},
423 423
 			ARRAY_FILTER_USE_BOTH
424 424
 		);
@@ -449,8 +449,8 @@  discard block
 block discarded – undo
449 449
 	 * @return string
450 450
 	 */
451 451
 	public function asset_path(): string {
452
-		$paths = $this->path( 'assets' );
453
-		return is_string( $paths ) ? $paths : '';
452
+		$paths = $this->path('assets');
453
+		return is_string($paths) ? $paths : '';
454 454
 	}
455 455
 
456 456
 	/**
@@ -459,8 +459,8 @@  discard block
 block discarded – undo
459 459
 	 * @return string
460 460
 	 */
461 461
 	public function view_path(): string {
462
-		$paths = $this->path( 'view' );
463
-		return is_string( $paths ) ? $paths : '';
462
+		$paths = $this->path('view');
463
+		return is_string($paths) ? $paths : '';
464 464
 	}
465 465
 
466 466
 	/**
@@ -469,8 +469,8 @@  discard block
 block discarded – undo
469 469
 	 * @return string
470 470
 	 */
471 471
 	public function plugin_path(): string {
472
-		$paths = $this->path( 'plugin' );
473
-		return is_string( $paths ) ? $paths : '';
472
+		$paths = $this->path('plugin');
473
+		return is_string($paths) ? $paths : '';
474 474
 	}
475 475
 
476 476
 	/**
@@ -479,8 +479,8 @@  discard block
 block discarded – undo
479 479
 	 * @return string
480 480
 	 */
481 481
 	public function asset_url(): string {
482
-		$url = $this->url( 'assets' );
483
-		return is_string( $url ) ? $url : '';
482
+		$url = $this->url('assets');
483
+		return is_string($url) ? $url : '';
484 484
 	}
485 485
 
486 486
 	/**
@@ -489,8 +489,8 @@  discard block
 block discarded – undo
489 489
 	 * @return string
490 490
 	 */
491 491
 	public function view_url(): string {
492
-		$url = $this->url( 'view' );
493
-		return is_string( $url ) ? $url : '';
492
+		$url = $this->url('view');
493
+		return is_string($url) ? $url : '';
494 494
 	}
495 495
 
496 496
 	/**
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
 	 * @return string
500 500
 	 */
501 501
 	public function plugin_url(): string {
502
-		$url = $this->url( 'plugin' );
503
-		return is_string( $url ) ? $url : '';
502
+		$url = $this->url('plugin');
503
+		return is_string($url) ? $url : '';
504 504
 	}
505 505
 }
Please login to merge, or discard this patch.
src/Application/App_Factory.php 1 patch
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -62,17 +62,17 @@  discard block
 block discarded – undo
62 62
 	 */
63 63
 	protected array $modules = array();
64 64
 
65
-	public function __construct( ?string $base_path = null ) {
65
+	public function __construct(?string $base_path = null) {
66 66
 
67
-		if ( null === $base_path ) {
67
+		if (null === $base_path) {
68 68
 			$file_index      = 0;
69 69
 			$trace           = debug_backtrace(); //phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace
70
-			$this->base_path = isset( $trace[ $file_index ]['file'] ) ? \trailingslashit( dirname( $trace[ $file_index ]['file'] ) ) : __DIR__;
70
+			$this->base_path = isset($trace[$file_index]['file']) ? \trailingslashit(dirname($trace[$file_index]['file'])) : __DIR__;
71 71
 		} else {
72
-			$this->base_path = \trailingslashit( $base_path );
72
+			$this->base_path = \trailingslashit($base_path);
73 73
 		}
74 74
 
75
-		$this->app = new App( $this->base_path );
75
+		$this->app = new App($this->base_path);
76 76
 	}
77 77
 
78 78
 		/**
@@ -92,11 +92,11 @@  discard block
 block discarded – undo
92 92
 	 * @param string $base_view_path
93 93
 	 * @return self
94 94
 	 */
95
-	public function set_base_view_path( string $base_view_path ): self {
96
-		$this->base_view_path = \trailingslashit( $base_view_path );
95
+	public function set_base_view_path(string $base_view_path): self {
96
+		$this->base_view_path = \trailingslashit($base_view_path);
97 97
 
98 98
 		// Set the view base path on the app.
99
-		$this->app->set_view_path( $this->base_view_path );
99
+		$this->app->set_view_path($this->base_view_path);
100 100
 
101 101
 		return $this;
102 102
 	}
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	public function get_base_view_path(): string {
111 111
 		return null !== $this->base_view_path
112 112
 			? $this->base_view_path
113
-			: \trailingslashit( $this->default_config_paths()['path']['view'] );
113
+			: \trailingslashit($this->default_config_paths()['path']['view']);
114 114
 	}
115 115
 
116 116
 	/**
@@ -122,12 +122,12 @@  discard block
 block discarded – undo
122 122
 	 * @infection-ignore-all
123 123
 	 * @return self
124 124
 	 */
125
-	public function with_wp_dice( bool $include_default_rules = false ): self {
125
+	public function with_wp_dice(bool $include_default_rules = false): self {
126 126
 		// If the view path is not set, set it to the same as base path.
127
-		if ( null === $this->base_view_path ) {
127
+		if (null === $this->base_view_path) {
128 128
 			$this->base_view_path = $this->base_path;
129 129
 		}
130
-		return $this->default_setup( $include_default_rules );
130
+		return $this->default_setup($include_default_rules);
131 131
 	}
132 132
 
133 133
 	/**
@@ -142,29 +142,29 @@  discard block
 block discarded – undo
142 142
 	 * @param bool $include_default_rules
143 143
 	 * @return self
144 144
 	 */
145
-	public function default_setup( bool $include_default_rules = true ): self {
145
+	public function default_setup(bool $include_default_rules = true): self {
146 146
 		$loader = new Hook_Loader();
147 147
 
148 148
 		// Setup DI Container
149
-		$container = PinkCrab_Dice::withDice( new Dice() );
149
+		$container = PinkCrab_Dice::withDice(new Dice());
150 150
 
151
-		if ( $include_default_rules === true ) {
152
-			$container->addRules( $this->default_di_rules() );
151
+		if ($include_default_rules === true) {
152
+			$container->addRules($this->default_di_rules());
153 153
 		}
154 154
 
155
-		$this->app->set_container( $container );
156
-		$this->app->set_loader( $loader );
155
+		$this->app->set_container($container);
156
+		$this->app->set_loader($loader);
157 157
 
158 158
 		// Set registration middleware
159
-		$module_manager = new Module_Manager( $container, new Registration_Service( $container ) );
160
-		$module_manager->push_module( Hookable_Module::class );
159
+		$module_manager = new Module_Manager($container, new Registration_Service($container));
160
+		$module_manager->push_module(Hookable_Module::class);
161 161
 
162 162
 		// Push any modules that have been added before the module manager was set.
163
-		foreach ( $this->modules as $module ) {
164
-			$module_manager->push_module( $module[0], $module[1] );
163
+		foreach ($this->modules as $module) {
164
+			$module_manager->push_module($module[0], $module[1]);
165 165
 		}
166 166
 
167
-		$this->app->set_module_manager( $module_manager );
167
+		$this->app->set_module_manager($module_manager);
168 168
 
169 169
 		return $this;
170 170
 	}
@@ -177,15 +177,15 @@  discard block
 block discarded – undo
177 177
 	 * @param ?callable(Module, ?Registration_Middleware):Module $callback
178 178
 	 * @return self
179 179
 	 */
180
-	public function module( string $module, ?callable $callback = null ): self {
180
+	public function module(string $module, ?callable $callback = null): self {
181 181
 
182 182
 		// If the Module_Manager has been set in app, add the module to app.
183
-		if ( $this->app->has_module_manager() ) {
184
-			$this->app->module( $module, $callback );
183
+		if ($this->app->has_module_manager()) {
184
+			$this->app->module($module, $callback);
185 185
 			return $this;
186 186
 		}
187 187
 
188
-		$this->modules[] = array( $module, $callback );
188
+		$this->modules[] = array($module, $callback);
189 189
 		return $this;
190 190
 	}
191 191
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 				'shared'     => true,
208 208
 			),
209 209
 			Component_Compiler::class => array(
210
-				'constructParams' => array( 'components' ),
210
+				'constructParams' => array('components'),
211 211
 			),
212 212
 		);
213 213
 	}
@@ -218,10 +218,10 @@  discard block
 block discarded – undo
218 218
 	 * @param array<string,array<string,string|object|callable|null|false|\Closure>> $rules
219 219
 	 * @return self
220 220
 	 */
221
-	public function di_rules( array $rules ): self {
221
+	public function di_rules(array $rules): self {
222 222
 		$this->app->container_config(
223
-			function ( DI_Container $container ) use ( $rules ): void {
224
-				$container->addRules( $rules );
223
+			function(DI_Container $container) use ($rules): void {
224
+				$container->addRules($rules);
225 225
 			}
226 226
 		);
227 227
 		return $this;
@@ -233,8 +233,8 @@  discard block
 block discarded – undo
233 233
 	 * @param array<class-string> $class_list Array of fully namespaced class names.
234 234
 	 * @return self
235 235
 	 */
236
-	public function registration_classes( array $class_list ): self {
237
-		$this->app->registration_classes( $class_list );
236
+	public function registration_classes(array $class_list): self {
237
+		$this->app->registration_classes($class_list);
238 238
 		return $this;
239 239
 	}
240 240
 
@@ -244,8 +244,8 @@  discard block
 block discarded – undo
244 244
 	 * @param array<string, mixed> $app_config
245 245
 	 * @return self
246 246
 	 */
247
-	public function app_config( array $app_config ): self {
248
-		$this->app->set_app_config( \array_replace_recursive( $this->default_config_paths(), $app_config ) );
247
+	public function app_config(array $app_config): self {
248
+		$this->app->set_app_config(\array_replace_recursive($this->default_config_paths(), $app_config));
249 249
 		return $this;
250 250
 	}
251 251
 
@@ -265,8 +265,8 @@  discard block
 block discarded – undo
265 265
 	 */
266 266
 	public function boot(): App {
267 267
 		// Sets default settings if not already set.
268
-		if ( ! $this->app->has_app_config() ) {
269
-			$this->app_config( $this->default_config_paths() );
268
+		if ( ! $this->app->has_app_config()) {
269
+			$this->app_config($this->default_config_paths());
270 270
 		}
271 271
 
272 272
 		return $this->app->boot();
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
 	private function default_config_paths(): array {
296 296
 		$wp_uploads = \wp_upload_dir();
297 297
 
298
-		$base_path = App_Config_Path_Helper::normalise_path( $this->base_path );
299
-		$view_path = $this->base_view_path ?? App_Config_Path_Helper::assume_view_path( $base_path );
298
+		$base_path = App_Config_Path_Helper::normalise_path($this->base_path);
299
+		$view_path = $this->base_view_path ?? App_Config_Path_Helper::assume_view_path($base_path);
300 300
 
301 301
 		return array(
302 302
 			'path' => array(
@@ -307,9 +307,9 @@  discard block
 block discarded – undo
307 307
 				'upload_current' => $wp_uploads['path'],
308 308
 			),
309 309
 			'url'  => array(
310
-				'plugin'         => App_Config_Path_Helper::assume_base_url( $base_path ),
311
-				'view'           => App_Config_Path_Helper::assume_view_url( $base_path, $view_path ),
312
-				'assets'         => App_Config_Path_Helper::assume_base_url( $base_path ) . '/assets',
310
+				'plugin'         => App_Config_Path_Helper::assume_base_url($base_path),
311
+				'view'           => App_Config_Path_Helper::assume_view_url($base_path, $view_path),
312
+				'assets'         => App_Config_Path_Helper::assume_base_url($base_path) . '/assets',
313 313
 				'upload_root'    => $wp_uploads['baseurl'],
314 314
 				'upload_current' => $wp_uploads['url'],
315 315
 			),
Please login to merge, or discard this patch.
src/Services/Dice/PinkCrab_Dice.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	 *
44 44
 	 * @param Dice $dice
45 45
 	 */
46
-	public function __construct( Dice $dice ) {
46
+	public function __construct(Dice $dice) {
47 47
 		$this->dice = $dice;
48 48
 	}
49 49
 
@@ -53,8 +53,8 @@  discard block
 block discarded – undo
53 53
 	 * @param Dice $dice
54 54
 	 * @return self
55 55
 	 */
56
-	public static function withDice( Dice $dice ): self { // phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
57
-		return new PinkCrab_Dice( $dice );
56
+	public static function withDice(Dice $dice): self { // phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
57
+		return new PinkCrab_Dice($dice);
58 58
 	}
59 59
 
60 60
 	/**
@@ -64,11 +64,11 @@  discard block
 block discarded – undo
64 64
 	 * @param string $id Class name (fully namespaced.)
65 65
 	 * @return object|null
66 66
 	 */
67
-	public function get( string $id ): ?object {
68
-		if ( ! $this->has( $id ) ) {
69
-			throw new DI_Container_Exception( esc_html( "{$id} not defined in container" ), 1 );
67
+	public function get(string $id): ?object {
68
+		if ( ! $this->has($id)) {
69
+			throw new DI_Container_Exception(esc_html("{$id} not defined in container"), 1);
70 70
 		}
71
-		return $this->create( $id );
71
+		return $this->create($id);
72 72
 	}
73 73
 
74 74
 	/**
@@ -78,21 +78,21 @@  discard block
 block discarded – undo
78 78
 	 * @param string $id Class name (fully namespaced.)
79 79
 	 * @return boolean
80 80
 	 */
81
-	public function has( string $id ): bool {
82
-		$from_dice = $this->dice->getRule( $id );
81
+	public function has(string $id): bool {
82
+		$from_dice = $this->dice->getRule($id);
83 83
 		// If set in global rules.
84
-		if ( array_key_exists( 'substitutions', $from_dice )
85
-		&& array_key_exists( $id, $from_dice['substitutions'] ) ) {
84
+		if (array_key_exists('substitutions', $from_dice)
85
+		&& array_key_exists($id, $from_dice['substitutions'])) {
86 86
 			return true;
87 87
 		}
88 88
 
89 89
 		// If set with a replacement instance.
90
-		if ( array_key_exists( 'instanceOf', $from_dice ) ) {
90
+		if (array_key_exists('instanceOf', $from_dice)) {
91 91
 			return true;
92 92
 		}
93 93
 
94 94
 		// Checks if the class exists
95
-		return class_exists( $id );
95
+		return class_exists($id);
96 96
 	}
97 97
 
98 98
 	/**
@@ -102,8 +102,8 @@  discard block
 block discarded – undo
102 102
 	 * @param array<string, string|object|mixed[]> $rule
103 103
 	 * @return PinkCrab_Dice
104 104
 	 */
105
-	public function addRule( string $name, array $rule ): DI_Container { // phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
106
-		$this->dice = $this->dice->addRule( $name, $rule );
105
+	public function addRule(string $name, array $rule): DI_Container { // phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
106
+		$this->dice = $this->dice->addRule($name, $rule);
107 107
 		return $this;
108 108
 	}
109 109
 
@@ -113,8 +113,8 @@  discard block
 block discarded – undo
113 113
 	 * @param array<string, mixed[]> $rules
114 114
 	 * @return PinkCrab_Dice
115 115
 	 */
116
-	public function addRules( array $rules ): DI_Container { // phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
117
-		$this->dice = $this->dice->addRules( apply_filters( Hooks::APP_INIT_SET_DI_RULES, $rules ) );
116
+	public function addRules(array $rules): DI_Container { // phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
117
+		$this->dice = $this->dice->addRules(apply_filters(Hooks::APP_INIT_SET_DI_RULES, $rules));
118 118
 		return $this;
119 119
 	}
120 120
 
@@ -125,8 +125,8 @@  discard block
 block discarded – undo
125 125
 	 * @param array<mixed> $args
126 126
 	 * @return object|null
127 127
 	 */
128
-	public function create( string $name, array $args = array() ): ?object {
129
-		return $this->dice->create( $name, $args );
128
+	public function create(string $name, array $args = array()): ?object {
129
+		return $this->dice->create($name, $args);
130 130
 	}
131 131
 
132 132
 	/**
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 	 * @param string $name
136 136
 	 * @return array<mixed>
137 137
 	 */
138
-	public function getRule( string $name ): ?array {
139
-		return $this->dice->getRule( $name );
138
+	public function getRule(string $name): ?array {
139
+		return $this->dice->getRule($name);
140 140
 	}
141 141
 }
Please login to merge, or discard this patch.
src/Services/View/PHP_Engine.php 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -53,8 +53,8 @@  discard block
 block discarded – undo
53 53
 	 *
54 54
 	 * @param string $base_view_path
55 55
 	 */
56
-	public function __construct( string $base_view_path ) {
57
-		$this->base_view_path = $this->verify_view_path( $base_view_path );
56
+	public function __construct(string $base_view_path) {
57
+		$this->base_view_path = $this->verify_view_path($base_view_path);
58 58
 	}
59 59
 
60 60
 	/**
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	 * @param Component_Compiler $compiler
64 64
 	 * @return void
65 65
 	 */
66
-	public function set_component_compiler( Component_Compiler $compiler ): void {
66
+	public function set_component_compiler(Component_Compiler $compiler): void {
67 67
 		$this->component_compiler = $compiler;
68 68
 	}
69 69
 
@@ -75,13 +75,13 @@  discard block
 block discarded – undo
75 75
 	 * @param boolean                 $print
76 76
 	 * @return string|null
77 77
 	 */
78
-	public function render( string $view, iterable $data, bool $print = true ): ?string {
79
-		$view = $this->resolve_file_path( $view );
80
-		if ( $print ) {
81
-			print( $this->render_buffer( $view, $data ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
78
+	public function render(string $view, iterable $data, bool $print = true): ?string {
79
+		$view = $this->resolve_file_path($view);
80
+		if ($print) {
81
+			print($this->render_buffer($view, $data)); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
82 82
 			return null;
83 83
 		} else {
84
-			return $this->render_buffer( $view, $data );
84
+			return $this->render_buffer($view, $data);
85 85
 		}
86 86
 	}
87 87
 
@@ -91,26 +91,26 @@  discard block
 block discarded – undo
91 91
 	 * @param Component $component
92 92
 	 * @return string
93 93
 	 */
94
-	public function component( Component $component, bool $print = true ): ?string {
94
+	public function component(Component $component, bool $print = true): ?string {
95 95
 
96 96
 		// Throw exception of no compiler passed.
97
-		if ( ! Object_Helper::is_a( $this->component_compiler, Component_Compiler::class ) ) {
98
-			throw new Exception( 'No component compiler passed to PHP_Engine' );
97
+		if ( ! Object_Helper::is_a($this->component_compiler, Component_Compiler::class)) {
98
+			throw new Exception('No component compiler passed to PHP_Engine');
99 99
 		}
100 100
 
101 101
 		// Compile the component.
102
-		$compiled = $this->component_compiler->compile( $component ); // @phpstan-ignore-line, checked above.
102
+		$compiled = $this->component_compiler->compile($component); // @phpstan-ignore-line, checked above.
103 103
 		$template = $compiled->template();
104 104
 
105
-		$view = file_exists( $template )
105
+		$view = file_exists($template)
106 106
 			? $template
107
-			: sprintf( '%s%s%s.php', $this->base_view_path, \DIRECTORY_SEPARATOR, trim( $this->maybe_resolve_dot_notation( $template ) ) );
107
+			: sprintf('%s%s%s.php', $this->base_view_path, \DIRECTORY_SEPARATOR, trim($this->maybe_resolve_dot_notation($template)));
108 108
 
109
-		if ( $print ) {
110
-			print( $this->render_buffer( $view, $compiled->data() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
109
+		if ($print) {
110
+			print($this->render_buffer($view, $compiled->data())); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
111 111
 			return null;
112 112
 		} else {
113
-			return $this->render_buffer( $view, $compiled->data() );
113
+			return $this->render_buffer($view, $compiled->data());
114 114
 		}
115 115
 	}
116 116
 
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
 	 * @param View_Model $view_model
121 121
 	 * @return string|null
122 122
 	 */
123
-	public function view_model( View_Model $view_model, bool $print = true ): ?string {
124
-		return $this->render( $view_model->template(), $view_model->data(), $print );
123
+	public function view_model(View_Model $view_model, bool $print = true): ?string {
124
+		return $this->render($view_model->template(), $view_model->data(), $print);
125 125
 	}
126 126
 
127 127
 	/**
@@ -132,12 +132,12 @@  discard block
 block discarded – undo
132 132
 	 * @param boolean                 $print
133 133
 	 * @return string|null
134 134
 	 */
135
-	public function partial( string $view, iterable $data = array(), bool $print = true ): ?string {
136
-		if ( $print ) {
137
-			$this->render( $view, $data, $print );
135
+	public function partial(string $view, iterable $data = array(), bool $print = true): ?string {
136
+		if ($print) {
137
+			$this->render($view, $data, $print);
138 138
 			return null;
139 139
 		} else {
140
-			return $this->render( $view, $data, $print );
140
+			return $this->render($view, $data, $print);
141 141
 		}
142 142
 	}
143 143
 
@@ -149,27 +149,27 @@  discard block
 block discarded – undo
149 149
 	 * @return string
150 150
 	 * @throws Exception
151 151
 	 */
152
-	private function render_buffer( string $view, iterable $__data ): string {
152
+	private function render_buffer(string $view, iterable $__data): string {
153 153
 
154
-		if ( ! file_exists( $view ) ) {
155
-			throw new Exception( esc_html( "{$view} doesn't exist" ) );
154
+		if ( ! file_exists($view)) {
155
+			throw new Exception(esc_html("{$view} doesn't exist"));
156 156
 		}
157 157
 
158 158
 		$output = '';
159 159
 		ob_start();
160 160
 
161 161
 		// Set all the data values a parameters.
162
-		foreach ( $__data as $__key => $__value ) {
163
-			if ( is_string( $__key ) ) {
164
-				${\wp_strip_all_tags( $__key )} = $__value;
162
+		foreach ($__data as $__key => $__value) {
163
+			if (is_string($__key)) {
164
+				${\wp_strip_all_tags($__key)} = $__value;
165 165
 			}
166 166
 
167 167
 			// Unset the key and value.
168
-			unset( $__key, $__value );
168
+			unset($__key, $__value);
169 169
 		}
170 170
 
171 171
 		// Unset the data.
172
-		unset( $__data );
172
+		unset($__data);
173 173
 
174 174
 		include $view;
175 175
 		$output = ob_get_contents();
@@ -183,12 +183,12 @@  discard block
 block discarded – undo
183 183
 	 * @param string $filename
184 184
 	 * @return string
185 185
 	 */
186
-	private function resolve_file_path( string $filename ): string {
187
-		$filename = $this->maybe_resolve_dot_notation( $filename );
186
+	private function resolve_file_path(string $filename): string {
187
+		$filename = $this->maybe_resolve_dot_notation($filename);
188 188
 		return sprintf(
189 189
 			'%s%s.php',
190 190
 			$this->base_view_path,
191
-			trim( $filename )
191
+			trim($filename)
192 192
 		);
193 193
 	}
194 194
 
@@ -198,13 +198,13 @@  discard block
 block discarded – undo
198 198
 	 * @param string $filename
199 199
 	 * @return string
200 200
 	 */
201
-	private function maybe_resolve_dot_notation( string $filename ): string {
202
-		if ( endsWith( '.php' )( $filename ) ) {
203
-			$filename = substr( $filename, 0, -4 );
201
+	private function maybe_resolve_dot_notation(string $filename): string {
202
+		if (endsWith('.php')($filename)) {
203
+			$filename = substr($filename, 0, -4);
204 204
 		}
205 205
 
206
-		$parts    = explode( '.', $filename );
207
-		$filename = implode( DIRECTORY_SEPARATOR, $parts );
206
+		$parts    = explode('.', $filename);
207
+		$filename = implode(DIRECTORY_SEPARATOR, $parts);
208 208
 
209 209
 		return $filename;
210 210
 	}
@@ -216,12 +216,12 @@  discard block
 block discarded – undo
216 216
 	 * @return string
217 217
 	 * @throws Exception
218 218
 	 */
219
-	private function verify_view_path( string $path ): string {
220
-		$path = $this->maybe_resolve_dot_notation( $path );
221
-		$path = rtrim( $path, '/' ) . '/';
219
+	private function verify_view_path(string $path): string {
220
+		$path = $this->maybe_resolve_dot_notation($path);
221
+		$path = rtrim($path, '/') . '/';
222 222
 
223
-		if ( ! \is_dir( $path ) ) {
224
-			throw new Exception( esc_html( "{$path} doesn't exist and cant be used as the base view path." ) );
223
+		if ( ! \is_dir($path)) {
224
+			throw new Exception(esc_html("{$path} doesn't exist and cant be used as the base view path."));
225 225
 		}
226 226
 
227 227
 		return $path;
Please login to merge, or discard this patch.
src/Services/Registration/Module_Manager.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	 *
68 68
 	 * @param DI_Container $di_container
69 69
 	 */
70
-	public function __construct( DI_Container $di_container, Registration_Service $registration_service ) {
70
+	public function __construct(DI_Container $di_container, Registration_Service $registration_service) {
71 71
 		$this->di_container = $di_container;
72 72
 
73 73
 		// Create the registration service.
@@ -82,8 +82,8 @@  discard block
 block discarded – undo
82 82
 	 * @param callable(Module, ?Registration_Middleware):Module $config
83 83
 	 * @return void
84 84
 	 */
85
-	public function push_module( string $module_name, ?callable $config = null ): void {
86
-		$this->modules[] = array( $module_name, $config );
85
+	public function push_module(string $module_name, ?callable $config = null): void {
86
+		$this->modules[] = array($module_name, $config);
87 87
 	}
88 88
 
89 89
 	/**
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
 	 *
92 92
 	 * @param class-string $class_string The class to register.
93 93
 	 */
94
-	public function register_class( string $class_string ): void {
95
-		$this->registration_service->push_class( $class_string );
94
+	public function register_class(string $class_string): void {
95
+		$this->registration_service->push_class($class_string);
96 96
 	}
97 97
 
98 98
 	/**
@@ -104,26 +104,26 @@  discard block
 block discarded – undo
104 104
 	 */
105 105
 	public function register_modules(): void {
106 106
 		// Allow for additional apps to hook into the Module Manager.
107
-		do_action( Hooks::MODULE_MANAGER, $this );
107
+		do_action(Hooks::MODULE_MANAGER, $this);
108 108
 
109
-		foreach ( $this->modules as list($module_name, $config) ) {
109
+		foreach ($this->modules as list($module_name, $config)) {
110 110
 			// Create the instance.
111
-			$module = $this->create_module( $module_name );
111
+			$module = $this->create_module($module_name);
112 112
 
113 113
 			// Create the middleware.
114
-			$middleware = $this->create_middleware( $module );
114
+			$middleware = $this->create_middleware($module);
115 115
 
116 116
 			// If a config is provided, call it.
117
-			if ( ! is_null( $config ) ) {
118
-				$module = $config( $module, $middleware );
117
+			if ( ! is_null($config)) {
118
+				$module = $config($module, $middleware);
119 119
 			}
120 120
 
121 121
 			// Add to the modules and register all hooks.
122
-			$this->register_hooks( $module );
122
+			$this->register_hooks($module);
123 123
 
124 124
 			// Add to the middleware, if provided.
125
-			if ( ! is_null( $middleware ) ) {
126
-				$this->registration_service->push_middleware( $middleware );
125
+			if ( ! is_null($middleware)) {
126
+				$this->registration_service->push_middleware($middleware);
127 127
 			}
128 128
 		}
129 129
 	}
@@ -134,14 +134,14 @@  discard block
 block discarded – undo
134 134
 	 * @param class-string<Module> $module
135 135
 	 * @return Module
136 136
 	 */
137
-	private function create_module( string $module ): Module {
138
-		$instance = $this->di_container->create( $module );
137
+	private function create_module(string $module): Module {
138
+		$instance = $this->di_container->create($module);
139 139
 
140 140
 		// If not an object or not an instance of the module interface, throw.
141
-		if ( ! is_object( $instance )
142
-		|| ! is_a( $instance, Module::class, true )
141
+		if ( ! is_object($instance)
142
+		|| ! is_a($instance, Module::class, true)
143 143
 		) {
144
-			throw Module_Manager_Exception::invalid_module_class_name( esc_html( $module ) );
144
+			throw Module_Manager_Exception::invalid_module_class_name(esc_html($module));
145 145
 		}
146 146
 
147 147
 		return $instance;
@@ -153,27 +153,27 @@  discard block
 block discarded – undo
153 153
 	 * @param Module $module
154 154
 	 * @return Registration_Middleware|null
155 155
 	 */
156
-	private function create_middleware( Module $module ): ?Registration_Middleware {
156
+	private function create_middleware(Module $module): ?Registration_Middleware {
157 157
 		$middleware = $module->get_middleware();
158 158
 
159 159
 		// If no middleware is provided, return null.
160
-		if ( is_null( $middleware ) ) {
160
+		if (is_null($middleware)) {
161 161
 			return null;
162 162
 		}
163 163
 
164 164
 		// If not an object or not an instance of the module interface, throw.
165
-		if ( ! is_a( $middleware, Registration_Middleware::class, true ) ) {
166
-			throw Module_Manager_Exception::invalid_registration_middleware( $middleware ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped, escaped in exception.
165
+		if ( ! is_a($middleware, Registration_Middleware::class, true)) {
166
+			throw Module_Manager_Exception::invalid_registration_middleware($middleware); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped, escaped in exception.
167 167
 		}
168 168
 
169 169
 		// Create the middleware.
170
-		$middleware = $this->di_container->create( $middleware );
170
+		$middleware = $this->di_container->create($middleware);
171 171
 
172 172
 		// If the middleware is not an object, throw.
173
-		if ( ! is_object( $middleware )
174
-		|| ! is_a( $middleware, Registration_Middleware::class, true )
173
+		if ( ! is_object($middleware)
174
+		|| ! is_a($middleware, Registration_Middleware::class, true)
175 175
 		) {
176
-			throw Module_Manager_Exception::failed_to_create_registration_middleware( $middleware ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped, escaped in exception.
176
+			throw Module_Manager_Exception::failed_to_create_registration_middleware($middleware); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped, escaped in exception.
177 177
 		}
178 178
 
179 179
 		return $middleware;
@@ -185,10 +185,10 @@  discard block
 block discarded – undo
185 185
 	 * @param Module $module
186 186
 	 * @return void
187 187
 	 */
188
-	private function register_hooks( Module $module ): void {
189
-		add_action( Hooks::APP_INIT_PRE_BOOT, array( $module, 'pre_boot' ), 10, 3 );
190
-		add_action( Hooks::APP_INIT_PRE_REGISTRATION, array( $module, 'pre_register' ), 10, 3 );
191
-		add_action( Hooks::APP_INIT_POST_REGISTRATION, array( $module, 'post_register' ), 10, 3 );
188
+	private function register_hooks(Module $module): void {
189
+		add_action(Hooks::APP_INIT_PRE_BOOT, array($module, 'pre_boot'), 10, 3);
190
+		add_action(Hooks::APP_INIT_PRE_REGISTRATION, array($module, 'pre_register'), 10, 3);
191
+		add_action(Hooks::APP_INIT_POST_REGISTRATION, array($module, 'post_register'), 10, 3);
192 192
 	}
193 193
 
194 194
 	/**
Please login to merge, or discard this patch.
src/Services/Registration/Modules/Hookable_Middleware.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -41,10 +41,10 @@
 block discarded – undo
41 41
 	 * @param object $class
42 42
 	 * @return object
43 43
 	 */
44
-	public function process( object $class ): object {  // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.classFound
45
-		if ( in_array( Hookable::class, class_implements( $class ) ?: array(), true ) ) { // phpcs:ignore Universal.Operators.DisallowShortTernary.Found
44
+	public function process(object $class): object {  // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.classFound
45
+		if (in_array(Hookable::class, class_implements($class) ?: array(), true)) { // phpcs:ignore Universal.Operators.DisallowShortTernary.Found
46 46
 			/** @phpstan-ignore-next-line class must implement register for interface*/
47
-			$class->register( $this->loader );
47
+			$class->register($this->loader);
48 48
 		}
49 49
 		return $class;
50 50
 	}
Please login to merge, or discard this patch.
src/Services/Registration/Registration_Service.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 	 */
54 54
 	protected DI_Container $di_container;
55 55
 
56
-	public function __construct( DI_Container $di_container ) {
56
+	public function __construct(DI_Container $di_container) {
57 57
 		$this->di_container = $di_container;
58 58
 	}
59 59
 
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
 	 * @param Registration_Middleware $middleware
64 64
 	 * @return self
65 65
 	 */
66
-	public function push_middleware( Registration_Middleware $middleware ): self {
67
-		$this->middleware[ \get_class( $middleware ) ] = $middleware;
66
+	public function push_middleware(Registration_Middleware $middleware): self {
67
+		$this->middleware[\get_class($middleware)] = $middleware;
68 68
 		return $this;
69 69
 	}
70 70
 
@@ -74,15 +74,15 @@  discard block
 block discarded – undo
74 74
 	 * @template Class_Name of object
75 75
 	 * @param class-string<Class_Name> $class_string
76 76
 	 */
77
-	public function push_class( string $class_string ): self {
77
+	public function push_class(string $class_string): self {
78 78
 		// If the class is already in the list, skip.
79
-		if ( \in_array( $class_string, $this->class_list, true ) ) {
79
+		if (\in_array($class_string, $this->class_list, true)) {
80 80
 			return $this;
81 81
 		}
82 82
 
83 83
 		// If $class_string is not a class, throw exception.
84
-		if ( ! \class_exists( $class_string ) ) {
85
-			throw Module_Manager_Exception::none_class_string_passed_to_registration( esc_html( $class_string ) );
84
+		if ( ! \class_exists($class_string)) {
85
+			throw Module_Manager_Exception::none_class_string_passed_to_registration(esc_html($class_string));
86 86
 		}
87 87
 
88 88
 		$this->class_list[] = $class_string;
@@ -96,25 +96,25 @@  discard block
 block discarded – undo
96 96
 	 */
97 97
 	public function process(): void {
98 98
 		// Filter all classes, before processing.
99
-		$class_list = apply_filters( Hooks::APP_INIT_REGISTRATION_CLASS_LIST, $this->class_list );
99
+		$class_list = apply_filters(Hooks::APP_INIT_REGISTRATION_CLASS_LIST, $this->class_list);
100 100
 
101 101
 		// If class list is empty, skip.
102
-		if ( empty( $class_list ) ) {
102
+		if (empty($class_list)) {
103 103
 			return;
104 104
 		}
105 105
 
106
-		foreach ( $this->middleware as $middleware ) {
106
+		foreach ($this->middleware as $middleware) {
107 107
 			// Run middleware setup
108 108
 			$middleware->setup();
109 109
 
110 110
 			// Pass each class to the middleware.
111
-			foreach ( $class_list as $class ) {
111
+			foreach ($class_list as $class) {
112 112
 				// Construct class using container,
113
-				$class_instance = $this->di_container->create( $class );
113
+				$class_instance = $this->di_container->create($class);
114 114
 
115 115
 				// if valid object process via current middleware
116
-				if ( is_object( $class_instance ) ) {
117
-					$middleware->process( $class_instance );
116
+				if (is_object($class_instance)) {
117
+					$middleware->process($class_instance);
118 118
 				}
119 119
 			}
120 120
 
Please login to merge, or discard this patch.
src/Exceptions/Module_Manager_Exception.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -35,20 +35,20 @@  discard block
 block discarded – undo
35 35
 	 * @param mixed $value
36 36
 	 * @return string
37 37
 	 */
38
-	private static function cast_to_string( $value ): string {
39
-		if ( is_object( $value ) ) {
40
-			return get_class( $value );
38
+	private static function cast_to_string($value): string {
39
+		if (is_object($value)) {
40
+			return get_class($value);
41 41
 		}
42 42
 
43
-		if ( is_array( $value ) ) {
44
-			return \wp_json_encode( $value ) ?: 'FAILED_TO_CAST ARRAY'; // phpcs:ignore Universal.Operators.DisallowShortTernary.Found
43
+		if (is_array($value)) {
44
+			return \wp_json_encode($value) ?: 'FAILED_TO_CAST ARRAY'; // phpcs:ignore Universal.Operators.DisallowShortTernary.Found
45 45
 		}
46 46
 
47
-		if ( is_null( $value ) ) {
47
+		if (is_null($value)) {
48 48
 			return 'NULL';
49 49
 		}
50 50
 
51
-		if ( is_bool( $value ) ) {
51
+		if (is_bool($value)) {
52 52
 			return $value ? 'BOOL::true' : 'BOOL::false';
53 53
 		}
54 54
 
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
 	 * @param string $module
62 62
 	 * @return Module_Manager_Exception
63 63
 	 */
64
-	public static function invalid_module_class_name( string $module ): Module_Manager_Exception {
64
+	public static function invalid_module_class_name(string $module): Module_Manager_Exception {
65 65
 		$message = "{$module} must be an instance of the Module interface";
66
-		return new Module_Manager_Exception( $message, 20 );
66
+		return new Module_Manager_Exception($message, 20);
67 67
 	}
68 68
 
69 69
 	/**
@@ -73,12 +73,12 @@  discard block
 block discarded – undo
73 73
 	 * @param mixed $created
74 74
 	 * @return Module_Manager_Exception
75 75
 	 */
76
-	public static function failed_to_create_registration_middleware( $created ): Module_Manager_Exception {
76
+	public static function failed_to_create_registration_middleware($created): Module_Manager_Exception {
77 77
 
78
-		$created = self::cast_to_string( $created );
78
+		$created = self::cast_to_string($created);
79 79
 
80 80
 		$message = "Failed to create Registration_Middleware, invalid instance created. Created: {$created}";
81
-		return new Module_Manager_Exception( $message, 21 );
81
+		return new Module_Manager_Exception($message, 21);
82 82
 	}
83 83
 
84 84
 	/**
@@ -88,11 +88,11 @@  discard block
 block discarded – undo
88 88
 	 * @param mixed $created
89 89
 	 * @return Module_Manager_Exception
90 90
 	 */
91
-	public static function invalid_registration_middleware( $created ): Module_Manager_Exception {
92
-		$created = self::cast_to_string( $created );
91
+	public static function invalid_registration_middleware($created): Module_Manager_Exception {
92
+		$created = self::cast_to_string($created);
93 93
 
94 94
 		$message = "{$created} was returned as the modules Middleware, but this does not implement Registration_Middleware interface";
95
-		return new Module_Manager_Exception( $message, 22 );
95
+		return new Module_Manager_Exception($message, 22);
96 96
 	}
97 97
 
98 98
 	/**
@@ -102,10 +102,10 @@  discard block
 block discarded – undo
102 102
 	 * @param mixed $passed
103 103
 	 * @return Module_Manager_Exception
104 104
 	 */
105
-	public static function none_class_string_passed_to_registration( $passed ): Module_Manager_Exception {
106
-		$passed = self::cast_to_string( $passed );
105
+	public static function none_class_string_passed_to_registration($passed): Module_Manager_Exception {
106
+		$passed = self::cast_to_string($passed);
107 107
 
108 108
 		$message = "None class-string \"{$passed}\" passed to the registration class list";
109
-		return new Module_Manager_Exception( $message, 23 );
109
+		return new Module_Manager_Exception($message, 23);
110 110
 	}
111 111
 }
Please login to merge, or discard this patch.