@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | * @return self |
102 | 102 | * @throws App_Initialization_Exception Code 2 |
103 | 103 | */ |
104 | - public function set_container( DI_Container $container ): self { |
|
105 | - if ( self::$container !== null ) { |
|
104 | + public function set_container(DI_Container $container): self { |
|
105 | + if (self::$container !== null) { |
|
106 | 106 | throw App_Initialization_Exception::di_container_exists(); |
107 | 107 | } |
108 | 108 | |
@@ -117,12 +117,12 @@ discard block |
||
117 | 117 | * @return self |
118 | 118 | * @throws App_Initialization_Exception Code 5 |
119 | 119 | */ |
120 | - public function set_app_config( array $settings ): self { |
|
121 | - if ( self::$app_config !== null ) { |
|
120 | + public function set_app_config(array $settings): self { |
|
121 | + if (self::$app_config !== null) { |
|
122 | 122 | throw App_Initialization_Exception::app_config_exists(); |
123 | 123 | } |
124 | 124 | |
125 | - self::$app_config = new App_Config( apply_filters( Hooks::APP_INIT_CONFIG_VALUES, $settings ) ); |
|
125 | + self::$app_config = new App_Config(apply_filters(Hooks::APP_INIT_CONFIG_VALUES, $settings)); |
|
126 | 126 | return $this; |
127 | 127 | } |
128 | 128 | |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | * @param \PinkCrab\Perique\Services\Registration\Registration_Service $registration |
133 | 133 | * @return self |
134 | 134 | */ |
135 | - public function set_registration_services( Registration_Service $registration ): self { |
|
136 | - if ( $this->registration !== null ) { |
|
135 | + public function set_registration_services(Registration_Service $registration): self { |
|
136 | + if ($this->registration !== null) { |
|
137 | 137 | throw App_Initialization_Exception::registration_exists(); |
138 | 138 | } |
139 | 139 | $this->registration = $registration; |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | * @param \PinkCrab\Loader\Hook_Loader $loader |
147 | 147 | * @return self |
148 | 148 | */ |
149 | - public function set_loader( Hook_Loader $loader ): self { |
|
150 | - if ( $this->loader !== null ) { |
|
149 | + public function set_loader(Hook_Loader $loader): self { |
|
150 | + if ($this->loader !== null) { |
|
151 | 151 | throw App_Initialization_Exception::loader_exists(); |
152 | 152 | } |
153 | 153 | $this->loader = $loader; |
@@ -162,11 +162,11 @@ discard block |
||
162 | 162 | * @return self |
163 | 163 | * @throws App_Initialization_Exception Code 1 |
164 | 164 | */ |
165 | - public function container_config( callable $callback ): self { |
|
166 | - if ( self::$container === null ) { |
|
165 | + public function container_config(callable $callback): self { |
|
166 | + if (self::$container === null) { |
|
167 | 167 | throw App_Initialization_Exception::requires_di_container(); |
168 | 168 | } |
169 | - $callback( self::$container ); |
|
169 | + $callback(self::$container); |
|
170 | 170 | return $this; |
171 | 171 | } |
172 | 172 | |
@@ -177,17 +177,17 @@ discard block |
||
177 | 177 | * @return self |
178 | 178 | * @throws App_Initialization_Exception Code 3 |
179 | 179 | */ |
180 | - public function registration_middleware( Registration_Middleware $middleware ): self { |
|
181 | - if ( $this->registration === null ) { |
|
180 | + public function registration_middleware(Registration_Middleware $middleware): self { |
|
181 | + if ($this->registration === null) { |
|
182 | 182 | throw App_Initialization_Exception::requires_registration_service(); |
183 | 183 | } |
184 | 184 | |
185 | 185 | // Set the loader to the registration service, if defined. |
186 | - if ( ! is_null( $this->loader ) ) { |
|
187 | - $this->registration->set_loader( $this->loader ); |
|
186 | + if ( ! is_null($this->loader)) { |
|
187 | + $this->registration->set_loader($this->loader); |
|
188 | 188 | } |
189 | 189 | |
190 | - $this->registration->push_middleware( $middleware ); |
|
190 | + $this->registration->push_middleware($middleware); |
|
191 | 191 | |
192 | 192 | return $this; |
193 | 193 | } |
@@ -200,23 +200,23 @@ discard block |
||
200 | 200 | * @throws App_Initialization_Exception Code 1 If DI container not registered |
201 | 201 | * @throws App_Initialization_Exception Code 9 If class doesn't create as middleware. |
202 | 202 | */ |
203 | - public function construct_registration_middleware( string $class_name ): self { |
|
204 | - if ( self::$container === null ) { |
|
203 | + public function construct_registration_middleware(string $class_name): self { |
|
204 | + if (self::$container === null) { |
|
205 | 205 | throw App_Initialization_Exception::requires_di_container(); |
206 | 206 | } |
207 | 207 | |
208 | 208 | // Add to stack if finalise has not been run. |
209 | - if ( false === self::$booted ) { |
|
209 | + if (false === self::$booted) { |
|
210 | 210 | $this->middleware_class_names[] = $class_name; |
211 | 211 | return $this; |
212 | 212 | } |
213 | 213 | |
214 | - $middleware = self::$container->create( $class_name ); |
|
215 | - if ( ! is_object( $middleware ) || ! is_a( $middleware, Registration_Middleware::class ) ) { |
|
216 | - throw App_Initialization_Exception::invalid_registration_middleware_instance( $class_name ); |
|
214 | + $middleware = self::$container->create($class_name); |
|
215 | + if ( ! is_object($middleware) || ! is_a($middleware, Registration_Middleware::class)) { |
|
216 | + throw App_Initialization_Exception::invalid_registration_middleware_instance($class_name); |
|
217 | 217 | } |
218 | 218 | |
219 | - return $this->registration_middleware( $middleware ); |
|
219 | + return $this->registration_middleware($middleware); |
|
220 | 220 | |
221 | 221 | } |
222 | 222 | |
@@ -227,11 +227,11 @@ discard block |
||
227 | 227 | * @return self |
228 | 228 | * @throws App_Initialization_Exception Code 3 |
229 | 229 | */ |
230 | - public function registration_classes( array $class_list ): self { |
|
231 | - if ( $this->registration === null ) { |
|
230 | + public function registration_classes(array $class_list): self { |
|
231 | + if ($this->registration === null) { |
|
232 | 232 | throw App_Initialization_Exception::requires_registration_service(); |
233 | 233 | } |
234 | - $this->registration->set_classes( $class_list ); |
|
234 | + $this->registration->set_classes($class_list); |
|
235 | 235 | return $this; |
236 | 236 | } |
237 | 237 | |
@@ -243,15 +243,15 @@ discard block |
||
243 | 243 | public function boot(): self { |
244 | 244 | |
245 | 245 | // Validate. |
246 | - $validate = new App_Validation( $this ); |
|
247 | - if ( $validate->validate() === false || $this->registration === null ) { |
|
246 | + $validate = new App_Validation($this); |
|
247 | + if ($validate->validate() === false || $this->registration === null) { |
|
248 | 248 | throw App_Initialization_Exception::failed_boot_validation( |
249 | 249 | $validate->errors |
250 | 250 | ); |
251 | 251 | } |
252 | 252 | |
253 | 253 | // Process registration |
254 | - $this->registration->set_container( self::$container ); |
|
254 | + $this->registration->set_container(self::$container); |
|
255 | 255 | |
256 | 256 | // Run the final process, where all are loaded in via |
257 | 257 | $this->finalise(); |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | Inject_DI_Container::class, |
294 | 294 | array( |
295 | 295 | 'call' => array( |
296 | - array( 'set_di_container', array( self::$container ) ), |
|
296 | + array('set_di_container', array(self::$container)), |
|
297 | 297 | ), |
298 | 298 | ) |
299 | 299 | ); |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | Inject_Hook_Loader::class, |
304 | 304 | array( |
305 | 305 | 'call' => array( |
306 | - array( 'set_hook_loader', array( $this->loader ) ), |
|
306 | + array('set_hook_loader', array($this->loader)), |
|
307 | 307 | ), |
308 | 308 | ) |
309 | 309 | ); |
@@ -313,31 +313,31 @@ discard block |
||
313 | 313 | Inject_App_Config::class, |
314 | 314 | array( |
315 | 315 | 'call' => array( |
316 | - array( 'set_app_config', array( self::$app_config ) ), |
|
316 | + array('set_app_config', array(self::$app_config)), |
|
317 | 317 | ), |
318 | 318 | ) |
319 | 319 | ); |
320 | 320 | |
321 | 321 | // Process middleware classnames. |
322 | - foreach ( $this->middleware_class_names as $class_name ) { |
|
323 | - $middleware = self::$container->create( $class_name ); |
|
324 | - if ( ! is_object( $middleware ) || ! is_a( $middleware, Registration_Middleware::class ) ) { |
|
325 | - throw App_Initialization_Exception::invalid_registration_middleware_instance( $class_name ); |
|
322 | + foreach ($this->middleware_class_names as $class_name) { |
|
323 | + $middleware = self::$container->create($class_name); |
|
324 | + if ( ! is_object($middleware) || ! is_a($middleware, Registration_Middleware::class)) { |
|
325 | + throw App_Initialization_Exception::invalid_registration_middleware_instance($class_name); |
|
326 | 326 | } |
327 | 327 | |
328 | - $this->registration_middleware( $middleware ); |
|
328 | + $this->registration_middleware($middleware); |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | /** @hook{string, App_Config, Loader, DI_Container} */ |
332 | - do_action( Hooks::APP_INIT_PRE_BOOT, self::$app_config, $this->loader, self::$container ); // phpcs:disable WordPress.NamingConventions.ValidHookName.* |
|
332 | + do_action(Hooks::APP_INIT_PRE_BOOT, self::$app_config, $this->loader, self::$container); // phpcs:disable WordPress.NamingConventions.ValidHookName.* |
|
333 | 333 | |
334 | 334 | // Initialise on init |
335 | 335 | add_action( |
336 | 336 | 'init', |
337 | - function () { |
|
338 | - do_action( Hooks::APP_INIT_PRE_REGISTRATION, self::$app_config, $this->loader, self::$container ); |
|
337 | + function() { |
|
338 | + do_action(Hooks::APP_INIT_PRE_REGISTRATION, self::$app_config, $this->loader, self::$container); |
|
339 | 339 | $this->registration->process(); |
340 | - do_action( Hooks::APP_INIT_POST_REGISTRATION, self::$app_config, $this->loader, self::$container ); |
|
340 | + do_action(Hooks::APP_INIT_POST_REGISTRATION, self::$app_config, $this->loader, self::$container); |
|
341 | 341 | $this->loader->register_hooks(); // @phpstan-ignore-line, if loader is not defined, exception will be thrown above |
342 | 342 | }, |
343 | 343 | 1 |
@@ -356,11 +356,11 @@ discard block |
||
356 | 356 | * @return object|null |
357 | 357 | * @throws App_Initialization_Exception Code 4 |
358 | 358 | */ |
359 | - public static function make( string $class, array $args = array() ) { |
|
360 | - if ( self::$booted === false ) { |
|
361 | - throw App_Initialization_Exception::app_not_initialized( DI_Container::class ); |
|
359 | + public static function make(string $class, array $args = array()) { |
|
360 | + if (self::$booted === false) { |
|
361 | + throw App_Initialization_Exception::app_not_initialized(DI_Container::class); |
|
362 | 362 | } |
363 | - return self::$container->create( $class, $args ); |
|
363 | + return self::$container->create($class, $args); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | /** |
@@ -371,11 +371,11 @@ discard block |
||
371 | 371 | * @return mixed |
372 | 372 | * @throws App_Initialization_Exception Code 4 |
373 | 373 | */ |
374 | - public static function config( string $key, string ...$child ) { |
|
375 | - if ( self::$booted === false ) { |
|
376 | - throw App_Initialization_Exception::app_not_initialized( App_Config::class ); |
|
374 | + public static function config(string $key, string ...$child) { |
|
375 | + if (self::$booted === false) { |
|
376 | + throw App_Initialization_Exception::app_not_initialized(App_Config::class); |
|
377 | 377 | } |
378 | - return self::$app_config->{$key}( ...$child ); |
|
378 | + return self::$app_config->{$key}(...$child); |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | /** |
@@ -385,11 +385,11 @@ discard block |
||
385 | 385 | * @throws App_Initialization_Exception Code 4 |
386 | 386 | */ |
387 | 387 | public static function view(): ?View { |
388 | - if ( self::$booted === false ) { |
|
389 | - throw App_Initialization_Exception::app_not_initialized( View::class ); |
|
388 | + if (self::$booted === false) { |
|
389 | + throw App_Initialization_Exception::app_not_initialized(View::class); |
|
390 | 390 | } |
391 | 391 | /** @var ?View */ |
392 | - return self::$container->create( View::class ); |
|
392 | + return self::$container->create(View::class); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | /** @return array{container:DI_Container,app_config:App_Config,booted:bool} */ |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | * @return bool |
408 | 408 | */ |
409 | 409 | public function has_app_config(): bool { |
410 | - return is_a( self::$app_config, App_Config::class ); |
|
410 | + return is_a(self::$app_config, App_Config::class); |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | /** |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | * @throws App_Initialization_Exception (Code 1) |
418 | 418 | */ |
419 | 419 | public function get_container(): DI_Container { |
420 | - if ( self::$container === null ) { |
|
420 | + if (self::$container === null) { |
|
421 | 421 | // Throw container not set. |
422 | 422 | throw App_Initialization_Exception::requires_di_container(); |
423 | 423 | } |
@@ -34,12 +34,12 @@ |
||
34 | 34 | * @param array<int, mixed> $params |
35 | 35 | * @return mixed |
36 | 36 | */ |
37 | - public static function __callStatic( $method, $params ) { |
|
38 | - if ( ! self::$config_cache ) { |
|
37 | + public static function __callStatic($method, $params) { |
|
38 | + if ( ! self::$config_cache) { |
|
39 | 39 | /** @phpstan-ignore-next-line */ |
40 | - self::$config_cache = App::make( App_Config::class ); |
|
40 | + self::$config_cache = App::make(App_Config::class); |
|
41 | 41 | } |
42 | 42 | |
43 | - return self::$config_cache->{$method}( ...$params ); |
|
43 | + return self::$config_cache->{$method}(...$params); |
|
44 | 44 | } |
45 | 45 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | /** @var App */ |
44 | 44 | protected $app; |
45 | 45 | |
46 | - public function __construct( App $app ) { |
|
46 | + public function __construct(App $app) { |
|
47 | 47 | $this->app = $app; |
48 | 48 | } |
49 | 49 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | public function validate(): bool { |
56 | 56 | $this->already_booted(); |
57 | 57 | $this->validate_properties_set(); |
58 | - return count( $this->errors ) === 0; |
|
58 | + return count($this->errors) === 0; |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -65,11 +65,11 @@ discard block |
||
65 | 65 | * @return void |
66 | 66 | */ |
67 | 67 | protected function validate_properties_set(): void { |
68 | - foreach ( $this->required_properties as $property => $is_static ) { |
|
69 | - $property_reflection = new ReflectionProperty( $this->app, $property ); |
|
70 | - $property_reflection->setAccessible( true ); |
|
71 | - if ( empty( $property_reflection->getValue( $this->app ) ) ) { |
|
72 | - $this->errors[] = \sprintf( self::ERROR_MESSAGE_TEMPLATE, $property ); |
|
68 | + foreach ($this->required_properties as $property => $is_static) { |
|
69 | + $property_reflection = new ReflectionProperty($this->app, $property); |
|
70 | + $property_reflection->setAccessible(true); |
|
71 | + if (empty($property_reflection->getValue($this->app))) { |
|
72 | + $this->errors[] = \sprintf(self::ERROR_MESSAGE_TEMPLATE, $property); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * @return void |
81 | 81 | */ |
82 | 82 | protected function already_booted(): void { |
83 | - if ( $this->app->is_booted() === true ) { |
|
83 | + if ($this->app->is_booted() === true) { |
|
84 | 84 | $this->errors[] = self::ERROR_MESSAGE_APP_BOOTED; |
85 | 85 | } |
86 | 86 | } |
@@ -88,9 +88,9 @@ discard block |
||
88 | 88 | /** |
89 | 89 | * @param array<string, mixed> $settings |
90 | 90 | */ |
91 | - public function __construct( array $settings = array() ) { |
|
92 | - $settings = $this->set_defaults( $settings ); |
|
93 | - $this->set_props( $settings ); |
|
91 | + public function __construct(array $settings = array()) { |
|
92 | + $settings = $this->set_defaults($settings); |
|
93 | + $this->set_props($settings); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -99,8 +99,8 @@ discard block |
||
99 | 99 | * @param array<string, mixed> $settings |
100 | 100 | * @return array<string, mixed> |
101 | 101 | */ |
102 | - private function set_defaults( array $settings ): array { |
|
103 | - return array_replace_recursive( $this->settings_defaults(), $settings ); |
|
102 | + private function set_defaults(array $settings): array { |
|
103 | + return array_replace_recursive($this->settings_defaults(), $settings); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -109,17 +109,17 @@ discard block |
||
109 | 109 | * @param array<string, mixed> $settings |
110 | 110 | * @return void |
111 | 111 | */ |
112 | - private function set_props( array $settings ): void { |
|
112 | + private function set_props(array $settings): void { |
|
113 | 113 | $this->paths['url'] = $settings['url']; |
114 | 114 | $this->paths['path'] = $settings['path']; |
115 | - $this->namespaces = $this->filter_key_value_pair( $settings['namespaces'] ); |
|
115 | + $this->namespaces = $this->filter_key_value_pair($settings['namespaces']); |
|
116 | 116 | $this->plugin = $settings['plugin']; |
117 | 117 | $this->additional = $settings['additional']; |
118 | - $this->db_tables = $this->filter_key_value_pair( $settings['db_tables'] ); |
|
119 | - $this->post_types = $this->filter_key_value_pair( $settings['post_types'] ); |
|
120 | - $this->taxonomies = $this->filter_key_value_pair( $settings['taxonomies'] ); |
|
118 | + $this->db_tables = $this->filter_key_value_pair($settings['db_tables']); |
|
119 | + $this->post_types = $this->filter_key_value_pair($settings['post_types']); |
|
120 | + $this->taxonomies = $this->filter_key_value_pair($settings['taxonomies']); |
|
121 | 121 | |
122 | - $this->set_meta( $settings['meta'] ); |
|
122 | + $this->set_meta($settings['meta']); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -129,14 +129,14 @@ discard block |
||
129 | 129 | * @param string|null $default The default value to return if not set. |
130 | 130 | * @return array<string, mixed>|string|null |
131 | 131 | */ |
132 | - public function path( ?string $path = null, ?string $default = null ) { |
|
132 | + public function path(?string $path = null, ?string $default = null) { |
|
133 | 133 | |
134 | - if ( is_null( $path ) ) { |
|
134 | + if (is_null($path)) { |
|
135 | 135 | return $this->paths['path']; |
136 | 136 | } |
137 | 137 | |
138 | - return \array_key_exists( $path, $this->paths['path'] ) |
|
139 | - ? trailingslashit( $this->paths['path'][ $path ] ) |
|
138 | + return \array_key_exists($path, $this->paths['path']) |
|
139 | + ? trailingslashit($this->paths['path'][$path]) |
|
140 | 140 | : $default; |
141 | 141 | } |
142 | 142 | |
@@ -147,14 +147,14 @@ discard block |
||
147 | 147 | * @param string|null $default The default value to return if not set. |
148 | 148 | * @return array<string, mixed>|string|null |
149 | 149 | */ |
150 | - public function url( ?string $url = null, ?string $default = null ) { |
|
150 | + public function url(?string $url = null, ?string $default = null) { |
|
151 | 151 | |
152 | - if ( is_null( $url ) ) { |
|
152 | + if (is_null($url)) { |
|
153 | 153 | return $this->paths['url']; |
154 | 154 | } |
155 | 155 | |
156 | - return \array_key_exists( $url, $this->paths['url'] ) |
|
157 | - ? trailingslashit( $this->paths['url'][ $url ] ) |
|
156 | + return \array_key_exists($url, $this->paths['url']) |
|
157 | + ? trailingslashit($this->paths['url'][$url]) |
|
158 | 158 | : $default; |
159 | 159 | } |
160 | 160 | |
@@ -183,9 +183,9 @@ discard block |
||
183 | 183 | * @param string|null $default The default value to return if not set. |
184 | 184 | * @return string|null |
185 | 185 | */ |
186 | - public function namespace( string $key, ?string $default = null ): ?string { |
|
187 | - return array_key_exists( $key, $this->namespaces ) |
|
188 | - ? $this->namespaces[ $key ] : $default; |
|
186 | + public function namespace(string $key, ?string $default = null) : ?string { |
|
187 | + return array_key_exists($key, $this->namespaces) |
|
188 | + ? $this->namespaces[$key] : $default; |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
@@ -195,9 +195,9 @@ discard block |
||
195 | 195 | * @param string|null $default The default value to return if not set. |
196 | 196 | * @return mixed |
197 | 197 | */ |
198 | - public function additional( string $key, ?string $default = null ) { |
|
199 | - return array_key_exists( $key, $this->additional ) |
|
200 | - ? $this->additional[ $key ] : $default; |
|
198 | + public function additional(string $key, ?string $default = null) { |
|
199 | + return array_key_exists($key, $this->additional) |
|
200 | + ? $this->additional[$key] : $default; |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -216,12 +216,12 @@ discard block |
||
216 | 216 | * @return string |
217 | 217 | * @throws OutOfBoundsException |
218 | 218 | */ |
219 | - public function post_types( string $key ) { |
|
220 | - if ( ! array_key_exists( $key, $this->post_types ) ) { |
|
221 | - throw new OutOfBoundsException( 'Post Type not defined.' ); |
|
219 | + public function post_types(string $key) { |
|
220 | + if ( ! array_key_exists($key, $this->post_types)) { |
|
221 | + throw new OutOfBoundsException('Post Type not defined.'); |
|
222 | 222 | } |
223 | 223 | |
224 | - return $this->post_types[ $key ]; |
|
224 | + return $this->post_types[$key]; |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -232,17 +232,17 @@ discard block |
||
232 | 232 | * @return string |
233 | 233 | * @throws OutOfBoundsException |
234 | 234 | */ |
235 | - public function meta( string $key, string $type = self::POST_META ): string { |
|
235 | + public function meta(string $key, string $type = self::POST_META): string { |
|
236 | 236 | // Check meta type. |
237 | - if ( ! array_key_exists( $type, $this->meta ) ) { |
|
238 | - throw new OutOfBoundsException( 'Meta Type doesnt exists' ); |
|
237 | + if ( ! array_key_exists($type, $this->meta)) { |
|
238 | + throw new OutOfBoundsException('Meta Type doesnt exists'); |
|
239 | 239 | } |
240 | 240 | // Check key. |
241 | - if ( ! array_key_exists( $key, $this->meta[ $type ] ) ) { |
|
242 | - throw new OutOfBoundsException( $type . ' meta key doesnt exists' ); |
|
241 | + if ( ! array_key_exists($key, $this->meta[$type])) { |
|
242 | + throw new OutOfBoundsException($type . ' meta key doesnt exists'); |
|
243 | 243 | } |
244 | 244 | |
245 | - return $this->meta[ $type ][ $key ]; |
|
245 | + return $this->meta[$type][$key]; |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
@@ -252,8 +252,8 @@ discard block |
||
252 | 252 | * @param string $key |
253 | 253 | * @return string |
254 | 254 | */ |
255 | - public function post_meta( string $key ): string { |
|
256 | - return $this->meta( $key, self::POST_META ); |
|
255 | + public function post_meta(string $key): string { |
|
256 | + return $this->meta($key, self::POST_META); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
@@ -263,8 +263,8 @@ discard block |
||
263 | 263 | * @param string $key |
264 | 264 | * @return string |
265 | 265 | */ |
266 | - public function user_meta( string $key ): string { |
|
267 | - return $this->meta( $key, self::USER_META ); |
|
266 | + public function user_meta(string $key): string { |
|
267 | + return $this->meta($key, self::USER_META); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
@@ -274,8 +274,8 @@ discard block |
||
274 | 274 | * @param string $key |
275 | 275 | * @return string |
276 | 276 | */ |
277 | - public function term_meta( string $key ): string { |
|
278 | - return $this->meta( $key, self::TERM_META ); |
|
277 | + public function term_meta(string $key): string { |
|
278 | + return $this->meta($key, self::TERM_META); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
@@ -284,15 +284,15 @@ discard block |
||
284 | 284 | * @param array<string, array<string,string>> $meta |
285 | 285 | * @return void |
286 | 286 | */ |
287 | - public function set_meta( array $meta ): void { |
|
288 | - $valid_meta_types = array( self::POST_META, self::USER_META, self::TERM_META ); |
|
289 | - foreach ( $meta as $meta_type => $pairs ) { |
|
290 | - if ( ! in_array( $meta_type, $valid_meta_types, true ) ) { |
|
291 | - throw new OutOfBoundsException( 'Valid meta type must be used as key.' ); |
|
287 | + public function set_meta(array $meta): void { |
|
288 | + $valid_meta_types = array(self::POST_META, self::USER_META, self::TERM_META); |
|
289 | + foreach ($meta as $meta_type => $pairs) { |
|
290 | + if ( ! in_array($meta_type, $valid_meta_types, true)) { |
|
291 | + throw new OutOfBoundsException('Valid meta type must be used as key.'); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | // Set all pairs which have both valid key and values. |
295 | - $this->meta[ $meta_type ] = $this->filter_key_value_pair( $pairs ); |
|
295 | + $this->meta[$meta_type] = $this->filter_key_value_pair($pairs); |
|
296 | 296 | } |
297 | 297 | } |
298 | 298 | |
@@ -303,12 +303,12 @@ discard block |
||
303 | 303 | * @return string |
304 | 304 | * @throws OutOfBoundsException |
305 | 305 | */ |
306 | - public function taxonomies( string $key ): string { |
|
307 | - if ( ! array_key_exists( $key, $this->taxonomies ) ) { |
|
308 | - throw new OutOfBoundsException( 'Taxonomy not defined.' ); |
|
306 | + public function taxonomies(string $key): string { |
|
307 | + if ( ! array_key_exists($key, $this->taxonomies)) { |
|
308 | + throw new OutOfBoundsException('Taxonomy not defined.'); |
|
309 | 309 | } |
310 | 310 | |
311 | - return $this->taxonomies[ $key ]; |
|
311 | + return $this->taxonomies[$key]; |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | |
@@ -319,11 +319,11 @@ discard block |
||
319 | 319 | * @return string |
320 | 320 | * @throws OutOfBoundsException |
321 | 321 | */ |
322 | - public function db_tables( string $name ): string { |
|
323 | - if ( ! array_key_exists( $name, $this->db_tables ) ) { |
|
324 | - throw new OutOfBoundsException( 'Table doesnt exist' ); |
|
322 | + public function db_tables(string $name): string { |
|
323 | + if ( ! array_key_exists($name, $this->db_tables)) { |
|
324 | + throw new OutOfBoundsException('Table doesnt exist'); |
|
325 | 325 | } |
326 | - return $this->db_tables[ $name ]; |
|
326 | + return $this->db_tables[$name]; |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
@@ -332,8 +332,8 @@ discard block |
||
332 | 332 | * @param string $name |
333 | 333 | * @return mixed |
334 | 334 | */ |
335 | - public function __get( $name ) { |
|
336 | - return $this->additional( $name ); |
|
335 | + public function __get($name) { |
|
336 | + return $this->additional($name); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | /** |
@@ -342,8 +342,8 @@ discard block |
||
342 | 342 | * @return array<string, mixed> |
343 | 343 | */ |
344 | 344 | private function settings_defaults(): array { |
345 | - $base_path = \dirname( __DIR__, 2 ); |
|
346 | - $plugin_dir = \basename( $base_path ); |
|
345 | + $base_path = \dirname(__DIR__, 2); |
|
346 | + $plugin_dir = \basename($base_path); |
|
347 | 347 | $wp_uploads = \wp_upload_dir(); |
348 | 348 | |
349 | 349 | return array( |
@@ -358,9 +358,9 @@ discard block |
||
358 | 358 | 'upload_current' => $wp_uploads['path'], |
359 | 359 | ), |
360 | 360 | 'url' => array( |
361 | - 'plugin' => plugins_url( $plugin_dir ), |
|
362 | - 'view' => plugins_url( $plugin_dir ) . '/views', |
|
363 | - 'assets' => plugins_url( $plugin_dir ) . '/assets', |
|
361 | + 'plugin' => plugins_url($plugin_dir), |
|
362 | + 'view' => plugins_url($plugin_dir) . '/views', |
|
363 | + 'assets' => plugins_url($plugin_dir) . '/assets', |
|
364 | 364 | 'upload_root' => $wp_uploads['baseurl'], |
365 | 365 | 'upload_current' => $wp_uploads['url'], |
366 | 366 | ), |
@@ -386,14 +386,14 @@ discard block |
||
386 | 386 | * @param array<int|string, mixed> $pairs |
387 | 387 | * @return array<string, string> |
388 | 388 | */ |
389 | - private function filter_key_value_pair( array $pairs ): array { |
|
389 | + private function filter_key_value_pair(array $pairs): array { |
|
390 | 390 | /** @var array<string, string> (as per filter function)*/ |
391 | 391 | return array_filter( |
392 | 392 | $pairs, |
393 | - function ( $value, $key ): bool { |
|
394 | - return is_string( $value ) |
|
395 | - && \mb_strlen( $value ) > 0 |
|
396 | - && is_string( $key ); |
|
393 | + function($value, $key): bool { |
|
394 | + return is_string($value) |
|
395 | + && \mb_strlen($value) > 0 |
|
396 | + && is_string($key); |
|
397 | 397 | }, |
398 | 398 | ARRAY_FILTER_USE_BOTH |
399 | 399 | ); |
@@ -40,14 +40,14 @@ discard block |
||
40 | 40 | */ |
41 | 41 | protected $base_path; |
42 | 42 | |
43 | - public function __construct( ?string $base_path = null ) { |
|
43 | + public function __construct(?string $base_path = null) { |
|
44 | 44 | $this->app = new App(); |
45 | 45 | |
46 | - if ( null === $base_path ) { |
|
46 | + if (null === $base_path) { |
|
47 | 47 | $trace = debug_backtrace(); //phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace |
48 | - $this->base_path = isset( $trace[0]['file'] ) ? \trailingslashit( dirname( $trace[0]['file'] ) ) : __DIR__; |
|
48 | + $this->base_path = isset($trace[0]['file']) ? \trailingslashit(dirname($trace[0]['file'])) : __DIR__; |
|
49 | 49 | } else { |
50 | - $this->base_path = \trailingslashit( $base_path ); |
|
50 | + $this->base_path = \trailingslashit($base_path); |
|
51 | 51 | } |
52 | 52 | } |
53 | 53 | |
@@ -61,25 +61,25 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @return self |
63 | 63 | */ |
64 | - public function with_wp_dice( bool $include_default_rules = false ): self { |
|
64 | + public function with_wp_dice(bool $include_default_rules = false): self { |
|
65 | 65 | $loader = new Hook_Loader(); |
66 | 66 | |
67 | 67 | // Setup DI Container |
68 | - $container = PinkCrab_Dice::withDice( new Dice() ); |
|
68 | + $container = PinkCrab_Dice::withDice(new Dice()); |
|
69 | 69 | |
70 | - if ( $include_default_rules === true ) { |
|
71 | - $container->addRules( $this->default_di_rules() ); |
|
70 | + if ($include_default_rules === true) { |
|
71 | + $container->addRules($this->default_di_rules()); |
|
72 | 72 | } |
73 | 73 | |
74 | - $this->app->set_container( $container ); |
|
74 | + $this->app->set_container($container); |
|
75 | 75 | |
76 | 76 | // Set registration middleware |
77 | - $this->app->set_registration_services( new Registration_Service() ); |
|
77 | + $this->app->set_registration_services(new Registration_Service()); |
|
78 | 78 | |
79 | - $this->app->set_loader( $loader ); |
|
79 | + $this->app->set_loader($loader); |
|
80 | 80 | |
81 | 81 | // Include Hookable. |
82 | - $this->app->registration_middleware( new Hookable_Middleware() ); |
|
82 | + $this->app->registration_middleware(new Hookable_Middleware()); |
|
83 | 83 | |
84 | 84 | return $this; |
85 | 85 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | return array( |
95 | 95 | '*' => array( |
96 | 96 | 'substitutions' => array( |
97 | - Renderable::class => new PHP_Engine( $this->base_path ), |
|
97 | + Renderable::class => new PHP_Engine($this->base_path), |
|
98 | 98 | ), |
99 | 99 | ), |
100 | 100 | ); |
@@ -106,10 +106,10 @@ discard block |
||
106 | 106 | * @param array<string,array<string,string|object|callable|null|false|\Closure>> $rules |
107 | 107 | * @return self |
108 | 108 | */ |
109 | - public function di_rules( array $rules ): self { |
|
109 | + public function di_rules(array $rules): self { |
|
110 | 110 | $this->app->container_config( |
111 | - function( DI_Container $container ) use ( $rules ): void { |
|
112 | - $container->addRules( $rules ); |
|
111 | + function(DI_Container $container) use ($rules): void { |
|
112 | + $container->addRules($rules); |
|
113 | 113 | } |
114 | 114 | ); |
115 | 115 | return $this; |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | * @param array<int, string> $class_list Array of fully namespaced class names. |
122 | 122 | * @return self |
123 | 123 | */ |
124 | - public function registration_classes( array $class_list ): self { |
|
125 | - $this->app->registration_classes( $class_list ); |
|
124 | + public function registration_classes(array $class_list): self { |
|
125 | + $this->app->registration_classes($class_list); |
|
126 | 126 | return $this; |
127 | 127 | } |
128 | 128 | |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | * @param array<string, mixed> $app_config |
133 | 133 | * @return self |
134 | 134 | */ |
135 | - public function app_config( array $app_config ): self { |
|
136 | - $this->app->set_app_config( $app_config ); |
|
135 | + public function app_config(array $app_config): self { |
|
136 | + $this->app->set_app_config($app_config); |
|
137 | 137 | return $this; |
138 | 138 | } |
139 | 139 | |
@@ -153,8 +153,8 @@ discard block |
||
153 | 153 | */ |
154 | 154 | public function boot(): App { |
155 | 155 | // Sets default settings if not already set. |
156 | - if ( ! $this->app->has_app_config() ) { |
|
157 | - $this->app_config( $this->default_config_paths() ); |
|
156 | + if ( ! $this->app->has_app_config()) { |
|
157 | + $this->app_config($this->default_config_paths()); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | return $this->app->boot(); |
@@ -185,16 +185,16 @@ discard block |
||
185 | 185 | |
186 | 186 | return array( |
187 | 187 | 'path' => array( |
188 | - 'plugin' => rtrim( $this->base_path, \DIRECTORY_SEPARATOR ), |
|
189 | - 'view' => rtrim( $this->base_path, \DIRECTORY_SEPARATOR ) . '/views', |
|
190 | - 'assets' => rtrim( $this->base_path, \DIRECTORY_SEPARATOR ) . '/assets', |
|
188 | + 'plugin' => rtrim($this->base_path, \DIRECTORY_SEPARATOR), |
|
189 | + 'view' => rtrim($this->base_path, \DIRECTORY_SEPARATOR) . '/views', |
|
190 | + 'assets' => rtrim($this->base_path, \DIRECTORY_SEPARATOR) . '/assets', |
|
191 | 191 | 'upload_root' => $wp_uploads['basedir'], |
192 | 192 | 'upload_current' => $wp_uploads['path'], |
193 | 193 | ), |
194 | 194 | 'url' => array( |
195 | - 'plugin' => rtrim( plugins_url( basename( $this->base_path ) ), \DIRECTORY_SEPARATOR ), |
|
196 | - 'view' => rtrim( plugins_url( basename( $this->base_path ) ), \DIRECTORY_SEPARATOR ) . '/views', |
|
197 | - 'assets' => rtrim( plugins_url( basename( $this->base_path ) ), \DIRECTORY_SEPARATOR ) . '/assets', |
|
195 | + 'plugin' => rtrim(plugins_url(basename($this->base_path)), \DIRECTORY_SEPARATOR), |
|
196 | + 'view' => rtrim(plugins_url(basename($this->base_path)), \DIRECTORY_SEPARATOR) . '/views', |
|
197 | + 'assets' => rtrim(plugins_url(basename($this->base_path)), \DIRECTORY_SEPARATOR) . '/assets', |
|
198 | 198 | 'upload_root' => $wp_uploads['baseurl'], |
199 | 199 | 'upload_current' => $wp_uploads['url'], |
200 | 200 | ), |
@@ -208,8 +208,8 @@ discard block |
||
208 | 208 | * @return self |
209 | 209 | * @throws App_Initialization_Exception Code 3 |
210 | 210 | */ |
211 | - public function registration_middleware( Registration_Middleware $middleware ): self { |
|
212 | - $this->app->registration_middleware( $middleware ); |
|
211 | + public function registration_middleware(Registration_Middleware $middleware): self { |
|
212 | + $this->app->registration_middleware($middleware); |
|
213 | 213 | return $this; |
214 | 214 | } |
215 | 215 | |
@@ -222,8 +222,8 @@ discard block |
||
222 | 222 | * @throws App_Initialization_Exception Code 1 If DI container not registered |
223 | 223 | * @throws App_Initialization_Exception Code 9 If class doesn't create as middleware. |
224 | 224 | */ |
225 | - public function construct_registration_middleware( string $class_name ): self { |
|
226 | - $this->app->construct_registration_middleware( $class_name ); |
|
225 | + public function construct_registration_middleware(string $class_name): self { |
|
226 | + $this->app->construct_registration_middleware($class_name); |
|
227 | 227 | return $this; |
228 | 228 | } |
229 | 229 | } |
@@ -28,4 +28,4 @@ |
||
28 | 28 | use Exception; |
29 | 29 | use Psr\Container\NotFoundExceptionInterface; |
30 | 30 | |
31 | -class DI_Container_Exception extends Exception implements NotFoundExceptionInterface{} |
|
31 | +class DI_Container_Exception extends Exception implements NotFoundExceptionInterface {} |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public static function requires_di_container(): App_Initialization_Exception { |
38 | 38 | $message = 'The Application must be populated with a DI_Container before booting.'; |
39 | - return new App_Initialization_Exception( $message, 1 ); |
|
39 | + return new App_Initialization_Exception($message, 1); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public static function di_container_exists(): App_Initialization_Exception { |
48 | 48 | $message = 'App already contains a DI Container, can not redeclare.'; |
49 | - return new App_Initialization_Exception( $message, 2 ); |
|
49 | + return new App_Initialization_Exception($message, 2); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public static function requires_registration_service(): App_Initialization_Exception { |
58 | 58 | $message = 'App has not defined Registration Service, this must be set before use.'; |
59 | - return new App_Initialization_Exception( $message, 3 ); |
|
59 | + return new App_Initialization_Exception($message, 3); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -65,9 +65,9 @@ discard block |
||
65 | 65 | * @param string $service The service which has been called without initialising the app. |
66 | 66 | * @return App_Initialization_Exception |
67 | 67 | */ |
68 | - public static function app_not_initialized( string $service ): App_Initialization_Exception { |
|
68 | + public static function app_not_initialized(string $service): App_Initialization_Exception { |
|
69 | 69 | $message = "App must be initialised before calling {$service}"; |
70 | - return new App_Initialization_Exception( $message, 4 ); |
|
70 | + return new App_Initialization_Exception($message, 4); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | */ |
78 | 78 | public static function app_config_exists(): App_Initialization_Exception { |
79 | 79 | $message = 'Can not redeclare App_Config as its already set to the application'; |
80 | - return new App_Initialization_Exception( $message, 5 ); |
|
80 | + return new App_Initialization_Exception($message, 5); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | */ |
88 | 88 | public static function registration_exists(): App_Initialization_Exception { |
89 | 89 | $message = 'Can not redeclare Registration_Service as its already set to the application'; |
90 | - return new App_Initialization_Exception( $message, 7 ); |
|
90 | + return new App_Initialization_Exception($message, 7); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -96,12 +96,12 @@ discard block |
||
96 | 96 | * @param array<int,string> $errors |
97 | 97 | * @return App_Initialization_Exception |
98 | 98 | */ |
99 | - public static function failed_boot_validation( array $errors ): App_Initialization_Exception { |
|
99 | + public static function failed_boot_validation(array $errors): App_Initialization_Exception { |
|
100 | 100 | $message = sprintf( |
101 | 101 | 'App failed boot validation : %s', |
102 | - join( ',', $errors ) |
|
102 | + join(',', $errors) |
|
103 | 103 | ); |
104 | - return new App_Initialization_Exception( $message, 6 ); |
|
104 | + return new App_Initialization_Exception($message, 6); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | */ |
112 | 112 | public static function loader_exists(): App_Initialization_Exception { |
113 | 113 | $message = 'Can not redeclare Loader as its already set to the application'; |
114 | - return new App_Initialization_Exception( $message, 8 ); |
|
114 | + return new App_Initialization_Exception($message, 8); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -120,12 +120,12 @@ discard block |
||
120 | 120 | * @param string $class |
121 | 121 | * @return App_Initialization_Exception |
122 | 122 | */ |
123 | - public static function invalid_registration_middleware_instance( string $class ): App_Initialization_Exception { |
|
123 | + public static function invalid_registration_middleware_instance(string $class): App_Initialization_Exception { |
|
124 | 124 | $message = sprintf( |
125 | 125 | '%s is not a valid instance of Registration_Middleware', |
126 | 126 | $class |
127 | 127 | ); |
128 | - return new App_Initialization_Exception( $message, 9 ); |
|
128 | + return new App_Initialization_Exception($message, 9); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | } |
@@ -33,5 +33,5 @@ |
||
33 | 33 | * @param App_Config $app_config |
34 | 34 | * @return void |
35 | 35 | */ |
36 | - public function set_app_config( App_Config $app_config ): void; |
|
36 | + public function set_app_config(App_Config $app_config): void; |
|
37 | 37 | } |
@@ -34,5 +34,5 @@ |
||
34 | 34 | * @param Hook_Loader $hook_loader |
35 | 35 | * @return void |
36 | 36 | */ |
37 | - public function set_hook_loader( Hook_Loader $hook_loader ): void; |
|
37 | + public function set_hook_loader(Hook_Loader $hook_loader): void; |
|
38 | 38 | } |