Completed
Push — master ( a4ba22...5297ca )
by Glynn
09:37 queued 09:34
created
src/Application/App.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 		$this->module_manager->register_modules(); // @phpstan-ignore-line, already verified if not null
363 363
 
364 364
 		/**
365
- * @hook{string, App_Config, Loader, DI_Container}
365
+		 * @hook{string, App_Config, Loader, DI_Container}
366 366
 */
367 367
 		do_action( Hooks::APP_INIT_PRE_BOOT, self::$app_config, $this->loader, self::$container ); // phpcs:disable WordPress.NamingConventions.ValidHookName.*
368 368
 
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
 			throw App_Initialization_Exception::app_not_initialized( View::class );
425 425
 		}
426 426
 		/**
427
- * @var ?View
427
+		 * @var ?View
428 428
 */
429 429
 		return self::$container->create( View::class ); // @phpstan-ignore-line, already verified if not null
430 430
 	}
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
 	 *  base_path:string,
441 441
 	 *  view_path:?string
442 442
 	 * }
443
-	*/
443
+	 */
444 444
 	public function __debugInfo(): array {
445 445
 		return array(
446 446
 			'container'      => self::$container,
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 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,8 +280,8 @@  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 ) {
283
+		$validate = new App_Validation($this);
284
+		if ($validate->validate() === false) {
285 285
 			throw App_Initialization_Exception::failed_boot_validation(
286 286
 				$validate->errors
287 287
 			);
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 			Inject_Hook_Loader::class,
334 334
 			array(
335 335
 				'call' => array(
336
-					array( 'set_hook_loader', array( $this->loader ) ),
336
+					array('set_hook_loader', array($this->loader)),
337 337
 				),
338 338
 			)
339 339
 		);
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
 			Inject_App_Config::class,
344 344
 			array(
345 345
 				'call' => array(
346
-					array( 'set_app_config', array( self::$app_config ) ),
346
+					array('set_app_config', array(self::$app_config)),
347 347
 				),
348 348
 			)
349 349
 		);
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 			Inject_DI_Container::class,
354 354
 			array(
355 355
 				'call' => array(
356
-					array( 'set_di_container', array( self::$container ) ),
356
+					array('set_di_container', array(self::$container)),
357 357
 				),
358 358
 			)
359 359
 		);
@@ -364,15 +364,15 @@  discard block
 block discarded – undo
364 364
 		/**
365 365
  * @hook{string, App_Config, Loader, DI_Container}
366 366
 */
367
-		do_action( Hooks::APP_INIT_PRE_BOOT, self::$app_config, $this->loader, self::$container ); // phpcs:disable WordPress.NamingConventions.ValidHookName.*
367
+		do_action(Hooks::APP_INIT_PRE_BOOT, self::$app_config, $this->loader, self::$container); // phpcs:disable WordPress.NamingConventions.ValidHookName.*
368 368
 
369 369
 		// Initialise on init
370 370
 		add_action(
371 371
 			'init',
372
-			function () {
373
-				do_action( Hooks::APP_INIT_PRE_REGISTRATION, self::$app_config, $this->loader, self::$container );
372
+			function() {
373
+				do_action(Hooks::APP_INIT_PRE_REGISTRATION, self::$app_config, $this->loader, self::$container);
374 374
 				$this->module_manager->process_middleware(); // @phpstan-ignore-line, already verified if not null
375
-				do_action( Hooks::APP_INIT_POST_REGISTRATION, self::$app_config, $this->loader, self::$container );
375
+				do_action(Hooks::APP_INIT_POST_REGISTRATION, self::$app_config, $this->loader, self::$container);
376 376
 				$this->loader->register_hooks(); // @phpstan-ignore-line, if loader is not defined, exception will be thrown above
377 377
 			},
378 378
 			1
@@ -391,11 +391,11 @@  discard block
 block discarded – undo
391 391
 	 * @return object|null
392 392
 	 * @throws App_Initialization_Exception Code 4
393 393
 	 */
394
-	public static function make( string $class, array $args = array() ): ?object {
395
-		if ( self::$booted === false ) {
396
-			throw App_Initialization_Exception::app_not_initialized( DI_Container::class );
394
+	public static function make(string $class, array $args = array()): ?object {
395
+		if (self::$booted === false) {
396
+			throw App_Initialization_Exception::app_not_initialized(DI_Container::class);
397 397
 		}
398
-		return self::$container->create( $class, $args ); // @phpstan-ignore-line, already verified if not null
398
+		return self::$container->create($class, $args); // @phpstan-ignore-line, already verified if not null
399 399
 	}
400 400
 
401 401
 	/**
@@ -406,11 +406,11 @@  discard block
 block discarded – undo
406 406
 	 * @return mixed
407 407
 	 * @throws App_Initialization_Exception Code 4
408 408
 	 */
409
-	public static function config( string $key, string ...$child ) {
410
-		if ( self::$booted === false ) {
411
-			throw App_Initialization_Exception::app_not_initialized( App_Config::class );
409
+	public static function config(string $key, string ...$child) {
410
+		if (self::$booted === false) {
411
+			throw App_Initialization_Exception::app_not_initialized(App_Config::class);
412 412
 		}
413
-		return self::$app_config->{$key}( ...$child );
413
+		return self::$app_config->{$key}(...$child);
414 414
 	}
415 415
 
416 416
 	/**
@@ -420,13 +420,13 @@  discard block
 block discarded – undo
420 420
 	 * @throws App_Initialization_Exception Code 4
421 421
 	 */
422 422
 	public static function view(): ?View {
423
-		if ( self::$booted === false ) {
424
-			throw App_Initialization_Exception::app_not_initialized( View::class );
423
+		if (self::$booted === false) {
424
+			throw App_Initialization_Exception::app_not_initialized(View::class);
425 425
 		}
426 426
 		/**
427 427
  * @var ?View
428 428
 */
429
-		return self::$container->create( View::class ); // @phpstan-ignore-line, already verified if not null
429
+		return self::$container->create(View::class); // @phpstan-ignore-line, already verified if not null
430 430
 	}
431 431
 
432 432
 	/**
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
 	 * @return boolean
459 459
 	 */
460 460
 	public function has_app_config(): bool {
461
-		return Object_Helper::is_a( self::$app_config, App_Config::class );
461
+		return Object_Helper::is_a(self::$app_config, App_Config::class);
462 462
 	}
463 463
 
464 464
 	/**
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
 	 * @throws App_Initialization_Exception (Code 1)
469 469
 	 */
470 470
 	public function get_container(): DI_Container {
471
-		if ( self::$container === null ) {
471
+		if (self::$container === null) {
472 472
 			// Throw container not set.
473 473
 			throw App_Initialization_Exception::requires_di_container();
474 474
 		}
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,22 +91,22 @@  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.
103
-		$template = $this->maybe_resolve_dot_notation( $compiled->template() );
104
-		$view     = sprintf( '%s%s%s.php', $this->base_view_path, \DIRECTORY_SEPARATOR, trim( $template ) );
105
-		if ( $print ) {
106
-			print( $this->render_buffer( $view, $compiled->data() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
102
+		$compiled = $this->component_compiler->compile($component); // @phpstan-ignore-line, checked above.
103
+		$template = $this->maybe_resolve_dot_notation($compiled->template());
104
+		$view     = sprintf('%s%s%s.php', $this->base_view_path, \DIRECTORY_SEPARATOR, trim($template));
105
+		if ($print) {
106
+			print($this->render_buffer($view, $compiled->data())); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
107 107
 			return null;
108 108
 		} else {
109
-			return $this->render_buffer( $view, $compiled->data() );
109
+			return $this->render_buffer($view, $compiled->data());
110 110
 		}
111 111
 	}
112 112
 
@@ -117,8 +117,8 @@  discard block
 block discarded – undo
117 117
 	 * @param View_Model $view_model
118 118
 	 * @return string|null
119 119
 	 */
120
-	public function view_model( View_Model $view_model, bool $print = true ): ?string {
121
-		return $this->render( $view_model->template(), $view_model->data(), $print );
120
+	public function view_model(View_Model $view_model, bool $print = true): ?string {
121
+		return $this->render($view_model->template(), $view_model->data(), $print);
122 122
 	}
123 123
 
124 124
 	/**
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
 	 * @param boolean                 $print
130 130
 	 * @return string|null
131 131
 	 */
132
-	public function partial( string $view, iterable $data = array(), bool $print = true ): ?string {
133
-		if ( $print ) {
134
-			$this->render( $view, $data, $print );
132
+	public function partial(string $view, iterable $data = array(), bool $print = true): ?string {
133
+		if ($print) {
134
+			$this->render($view, $data, $print);
135 135
 			return null;
136 136
 		} else {
137
-			return $this->render( $view, $data, $print );
137
+			return $this->render($view, $data, $print);
138 138
 		}
139 139
 	}
140 140
 
@@ -146,27 +146,27 @@  discard block
 block discarded – undo
146 146
 	 * @return string
147 147
 	 * @throws Exception
148 148
 	 */
149
-	private function render_buffer( string $view, iterable $__data ): string {
149
+	private function render_buffer(string $view, iterable $__data): string {
150 150
 
151
-		if ( ! file_exists( $view ) ) {
152
-			throw new Exception( "{$view} doesn't exist" );
151
+		if ( ! file_exists($view)) {
152
+			throw new Exception("{$view} doesn't exist");
153 153
 		}
154 154
 
155 155
 		$output = '';
156 156
 		ob_start();
157 157
 
158 158
 		// Set all the data values a parameters.
159
-		foreach ( $__data as $__key => $__value ) {
160
-			if ( is_string( $__key ) ) {
161
-				${\wp_strip_all_tags( $__key )} = $__value;
159
+		foreach ($__data as $__key => $__value) {
160
+			if (is_string($__key)) {
161
+				${\wp_strip_all_tags($__key)} = $__value;
162 162
 			}
163 163
 
164 164
 			// Unset the key and value.
165
-			unset( $__key, $__value );
165
+			unset($__key, $__value);
166 166
 		}
167 167
 
168 168
 		// Unset the data.
169
-		unset( $__data );
169
+		unset($__data);
170 170
 
171 171
 		include $view;
172 172
 		$output = ob_get_contents();
@@ -180,12 +180,12 @@  discard block
 block discarded – undo
180 180
 	 * @param string $filename
181 181
 	 * @return string
182 182
 	 */
183
-	private function resolve_file_path( string $filename ): string {
184
-		$filename = $this->maybe_resolve_dot_notation( $filename );
183
+	private function resolve_file_path(string $filename): string {
184
+		$filename = $this->maybe_resolve_dot_notation($filename);
185 185
 		return sprintf(
186 186
 			'%s%s.php',
187 187
 			$this->base_view_path,
188
-			trim( $filename )
188
+			trim($filename)
189 189
 		);
190 190
 	}
191 191
 
@@ -195,13 +195,13 @@  discard block
 block discarded – undo
195 195
 	 * @param string $filename
196 196
 	 * @return string
197 197
 	 */
198
-	private function maybe_resolve_dot_notation( string $filename ): string {
199
-		if ( endsWith( '.php' )( $filename ) ) {
200
-			$filename = substr( $filename, 0, -4 );
198
+	private function maybe_resolve_dot_notation(string $filename): string {
199
+		if (endsWith('.php')($filename)) {
200
+			$filename = substr($filename, 0, -4);
201 201
 		}
202 202
 
203
-		$parts    = explode( '.', $filename );
204
-		$filename = implode( DIRECTORY_SEPARATOR, $parts );
203
+		$parts    = explode('.', $filename);
204
+		$filename = implode(DIRECTORY_SEPARATOR, $parts);
205 205
 
206 206
 		return $filename;
207 207
 	}
@@ -213,12 +213,12 @@  discard block
 block discarded – undo
213 213
 	 * @return string
214 214
 	 * @throws Exception
215 215
 	 */
216
-	private function verify_view_path( string $path ): string {
217
-		$path = $this->maybe_resolve_dot_notation( $path );
218
-		$path = rtrim( $path, '/' ) . '/';
216
+	private function verify_view_path(string $path): string {
217
+		$path = $this->maybe_resolve_dot_notation($path);
218
+		$path = rtrim($path, '/') . '/';
219 219
 
220
-		if ( ! \is_dir( $path ) ) {
221
-			throw new Exception( "{$path} doesn't exist and cant be used as the base view path." );
220
+		if ( ! \is_dir($path)) {
221
+			throw new Exception("{$path} doesn't exist and cant be used as the base view path.");
222 222
 		}
223 223
 
224 224
 		return $path;
Please login to merge, or discard this patch.