@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | /** @var App */ |
44 | 44 | private $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 | private 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 | private 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 | } |
@@ -61,11 +61,11 @@ |
||
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
64 | - * Gets the defined base path. |
|
65 | - * |
|
66 | - * @return string |
|
67 | - * @since 1.4.0 |
|
68 | - */ |
|
64 | + * Gets the defined base path. |
|
65 | + * |
|
66 | + * @return string |
|
67 | + * @since 1.4.0 |
|
68 | + */ |
|
69 | 69 | public function get_base_path(): string { |
70 | 70 | return $this->base_path; |
71 | 71 | } |
@@ -48,15 +48,15 @@ discard block |
||
48 | 48 | */ |
49 | 49 | protected $base_view_path; |
50 | 50 | |
51 | - public function __construct( ?string $base_path = null ) { |
|
51 | + public function __construct(?string $base_path = null) { |
|
52 | 52 | $this->app = new App(); |
53 | 53 | |
54 | - if ( null === $base_path ) { |
|
54 | + if (null === $base_path) { |
|
55 | 55 | $file_index = 0; |
56 | 56 | $trace = debug_backtrace(); //phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace |
57 | - $this->base_path = isset( $trace[ $file_index ]['file'] ) ? \trailingslashit( dirname( $trace[ $file_index ]['file'] ) ) : __DIR__; |
|
57 | + $this->base_path = isset($trace[$file_index]['file']) ? \trailingslashit(dirname($trace[$file_index]['file'])) : __DIR__; |
|
58 | 58 | } else { |
59 | - $this->base_path = \trailingslashit( $base_path ); |
|
59 | + $this->base_path = \trailingslashit($base_path); |
|
60 | 60 | } |
61 | 61 | } |
62 | 62 | |
@@ -77,8 +77,8 @@ discard block |
||
77 | 77 | * @param string $base_view_path |
78 | 78 | * @return self |
79 | 79 | */ |
80 | - public function set_base_view_path( string $base_view_path ): self { |
|
81 | - $this->base_view_path = \trailingslashit( $base_view_path ); |
|
80 | + public function set_base_view_path(string $base_view_path): self { |
|
81 | + $this->base_view_path = \trailingslashit($base_view_path); |
|
82 | 82 | return $this; |
83 | 83 | } |
84 | 84 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | public function get_base_view_path(): string { |
92 | 92 | return null !== $this->base_view_path |
93 | 93 | ? $this->base_view_path |
94 | - : \trailingslashit( $this->default_config_paths()['path']['view'] ); |
|
94 | + : \trailingslashit($this->default_config_paths()['path']['view']); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -103,12 +103,12 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @return self |
105 | 105 | */ |
106 | - public function with_wp_dice( bool $include_default_rules = false ): self { |
|
106 | + public function with_wp_dice(bool $include_default_rules = false): self { |
|
107 | 107 | // If the view path is not set, set it to the same as base path. |
108 | - if ( null === $this->base_view_path ) { |
|
108 | + if (null === $this->base_view_path) { |
|
109 | 109 | $this->base_view_path = $this->base_path; |
110 | 110 | } |
111 | - return $this->default_setup( $include_default_rules ); |
|
111 | + return $this->default_setup($include_default_rules); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -123,25 +123,25 @@ discard block |
||
123 | 123 | * @param bool $include_default_rules |
124 | 124 | * @return self |
125 | 125 | */ |
126 | - public function default_setup( bool $include_default_rules = true ): self { |
|
126 | + public function default_setup(bool $include_default_rules = true): self { |
|
127 | 127 | $loader = new Hook_Loader(); |
128 | 128 | |
129 | 129 | // Setup DI Container |
130 | - $container = PinkCrab_Dice::withDice( new Dice() ); |
|
130 | + $container = PinkCrab_Dice::withDice(new Dice()); |
|
131 | 131 | |
132 | - if ( $include_default_rules === true ) { |
|
133 | - $container->addRules( $this->default_di_rules() ); |
|
132 | + if ($include_default_rules === true) { |
|
133 | + $container->addRules($this->default_di_rules()); |
|
134 | 134 | } |
135 | 135 | |
136 | - $this->app->set_container( $container ); |
|
136 | + $this->app->set_container($container); |
|
137 | 137 | |
138 | 138 | // Set registration middleware |
139 | - $this->app->set_registration_services( new Registration_Service() ); |
|
139 | + $this->app->set_registration_services(new Registration_Service()); |
|
140 | 140 | |
141 | - $this->app->set_loader( $loader ); |
|
141 | + $this->app->set_loader($loader); |
|
142 | 142 | |
143 | 143 | // Include Hookable. |
144 | - $this->app->registration_middleware( new Hookable_Middleware() ); |
|
144 | + $this->app->registration_middleware(new Hookable_Middleware()); |
|
145 | 145 | |
146 | 146 | return $this; |
147 | 147 | } |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | return array( |
157 | 157 | '*' => array( |
158 | 158 | 'substitutions' => array( |
159 | - Renderable::class => new PHP_Engine( $this->get_base_view_path() ), |
|
159 | + Renderable::class => new PHP_Engine($this->get_base_view_path()), |
|
160 | 160 | ), |
161 | 161 | ), |
162 | 162 | ); |
@@ -168,10 +168,10 @@ discard block |
||
168 | 168 | * @param array<string,array<string,string|object|callable|null|false|\Closure>> $rules |
169 | 169 | * @return self |
170 | 170 | */ |
171 | - public function di_rules( array $rules ): self { |
|
171 | + public function di_rules(array $rules): self { |
|
172 | 172 | $this->app->container_config( |
173 | - function( DI_Container $container ) use ( $rules ): void { |
|
174 | - $container->addRules( $rules ); |
|
173 | + function(DI_Container $container) use ($rules): void { |
|
174 | + $container->addRules($rules); |
|
175 | 175 | } |
176 | 176 | ); |
177 | 177 | return $this; |
@@ -183,8 +183,8 @@ discard block |
||
183 | 183 | * @param array<int, string> $class_list Array of fully namespaced class names. |
184 | 184 | * @return self |
185 | 185 | */ |
186 | - public function registration_classes( array $class_list ): self { |
|
187 | - $this->app->registration_classes( $class_list ); |
|
186 | + public function registration_classes(array $class_list): self { |
|
187 | + $this->app->registration_classes($class_list); |
|
188 | 188 | return $this; |
189 | 189 | } |
190 | 190 | |
@@ -194,8 +194,8 @@ discard block |
||
194 | 194 | * @param array<string, mixed> $app_config |
195 | 195 | * @return self |
196 | 196 | */ |
197 | - public function app_config( array $app_config ): self { |
|
198 | - $this->app->set_app_config( \array_replace_recursive( $this->default_config_paths(), $app_config ) ); |
|
197 | + public function app_config(array $app_config): self { |
|
198 | + $this->app->set_app_config(\array_replace_recursive($this->default_config_paths(), $app_config)); |
|
199 | 199 | return $this; |
200 | 200 | } |
201 | 201 | |
@@ -215,8 +215,8 @@ discard block |
||
215 | 215 | */ |
216 | 216 | public function boot(): App { |
217 | 217 | // Sets default settings if not already set. |
218 | - if ( ! $this->app->has_app_config() ) { |
|
219 | - $this->app_config( $this->default_config_paths() ); |
|
218 | + if ( ! $this->app->has_app_config()) { |
|
219 | + $this->app_config($this->default_config_paths()); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | return $this->app->boot(); |
@@ -246,16 +246,16 @@ discard block |
||
246 | 246 | $wp_uploads = \wp_upload_dir(); |
247 | 247 | return array( |
248 | 248 | 'path' => array( |
249 | - 'plugin' => rtrim( $this->base_path, \DIRECTORY_SEPARATOR ), |
|
250 | - 'view' => rtrim( $this->base_path, \DIRECTORY_SEPARATOR ) . '/views', |
|
251 | - 'assets' => rtrim( $this->base_path, \DIRECTORY_SEPARATOR ) . '/assets', |
|
249 | + 'plugin' => rtrim($this->base_path, \DIRECTORY_SEPARATOR), |
|
250 | + 'view' => rtrim($this->base_path, \DIRECTORY_SEPARATOR) . '/views', |
|
251 | + 'assets' => rtrim($this->base_path, \DIRECTORY_SEPARATOR) . '/assets', |
|
252 | 252 | 'upload_root' => $wp_uploads['basedir'], |
253 | 253 | 'upload_current' => $wp_uploads['path'], |
254 | 254 | ), |
255 | 255 | 'url' => array( |
256 | - 'plugin' => plugins_url( basename( $this->base_path ) ), |
|
257 | - 'view' => plugins_url( basename( $this->base_path ) ) . '/views', |
|
258 | - 'assets' => plugins_url( basename( $this->base_path ) ) . '/assets', |
|
256 | + 'plugin' => plugins_url(basename($this->base_path)), |
|
257 | + 'view' => plugins_url(basename($this->base_path)) . '/views', |
|
258 | + 'assets' => plugins_url(basename($this->base_path)) . '/assets', |
|
259 | 259 | 'upload_root' => $wp_uploads['baseurl'], |
260 | 260 | 'upload_current' => $wp_uploads['url'], |
261 | 261 | ), |
@@ -269,8 +269,8 @@ discard block |
||
269 | 269 | * @return self |
270 | 270 | * @throws App_Initialization_Exception Code 3 |
271 | 271 | */ |
272 | - public function registration_middleware( Registration_Middleware $middleware ): self { |
|
273 | - $this->app->registration_middleware( $middleware ); |
|
272 | + public function registration_middleware(Registration_Middleware $middleware): self { |
|
273 | + $this->app->registration_middleware($middleware); |
|
274 | 274 | return $this; |
275 | 275 | } |
276 | 276 | |
@@ -283,8 +283,8 @@ discard block |
||
283 | 283 | * @throws App_Initialization_Exception Code 1 If DI container not registered |
284 | 284 | * @throws App_Initialization_Exception Code 9 If class doesn't create as middleware. |
285 | 285 | */ |
286 | - public function construct_registration_middleware( string $class_name ): self { |
|
287 | - $this->app->construct_registration_middleware( $class_name ); |
|
286 | + public function construct_registration_middleware(string $class_name): self { |
|
287 | + $this->app->construct_registration_middleware($class_name); |
|
288 | 288 | return $this; |
289 | 289 | } |
290 | 290 | } |
@@ -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( "App Config :: \"{$key}\" is not a defined post type" ); |
|
219 | + public function post_types(string $key) { |
|
220 | + if ( ! array_key_exists($key, $this->post_types)) { |
|
221 | + throw new OutOfBoundsException("App Config :: \"{$key}\" is not a defined post type"); |
|
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( "App Config :: \"{$type}\" is not a valid meta type and cant be fetched" ); |
|
237 | + if ( ! array_key_exists($type, $this->meta)) { |
|
238 | + throw new OutOfBoundsException("App Config :: \"{$type}\" is not a valid meta type and cant be fetched"); |
|
239 | 239 | } |
240 | 240 | // Check key. |
241 | - if ( ! array_key_exists( $key, $this->meta[ $type ] ) ) { |
|
242 | - throw new OutOfBoundsException( "App Config :: \"{$key}\" is not a defined {$type} meta key" ); |
|
241 | + if ( ! array_key_exists($key, $this->meta[$type])) { |
|
242 | + throw new OutOfBoundsException("App Config :: \"{$key}\" is not a defined {$type} meta key"); |
|
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( "App Config :: \"{$meta_type}\" is not a valid meta type and cant be defined" ); |
|
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("App Config :: \"{$meta_type}\" is not a valid meta type and cant be defined"); |
|
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( "App Config :: \"{$key}\" is not a defined taxonomy" ); |
|
306 | + public function taxonomies(string $key): string { |
|
307 | + if ( ! array_key_exists($key, $this->taxonomies)) { |
|
308 | + throw new OutOfBoundsException("App Config :: \"{$key}\" is not a defined taxonomy"); |
|
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( "App Config :: \"{$name}\" is not a defined DB table" ); |
|
322 | + public function db_tables(string $name): string { |
|
323 | + if ( ! array_key_exists($name, $this->db_tables)) { |
|
324 | + throw new OutOfBoundsException("App Config :: \"{$name}\" is not a defined DB table"); |
|
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 | ), |
@@ -382,15 +382,15 @@ discard block |
||
382 | 382 | * @param array<int|string, mixed> $pairs |
383 | 383 | * @return array<string, string> |
384 | 384 | */ |
385 | - private function filter_key_value_pair( array $pairs ): array { |
|
385 | + private function filter_key_value_pair(array $pairs): array { |
|
386 | 386 | /** @var array<string, string> (as per filter function)*/ |
387 | 387 | return array_filter( |
388 | 388 | $pairs, |
389 | - function ( $value, $key ): bool { |
|
390 | - return is_string( $value ) |
|
391 | - && \strlen( $value ) > 0 |
|
392 | - && is_string( $key ) |
|
393 | - && \strlen( $key ) > 0; |
|
389 | + function($value, $key): bool { |
|
390 | + return is_string($value) |
|
391 | + && \strlen($value) > 0 |
|
392 | + && is_string($key) |
|
393 | + && \strlen($key) > 0; |
|
394 | 394 | }, |
395 | 395 | ARRAY_FILTER_USE_BOTH |
396 | 396 | ); |
@@ -43,7 +43,7 @@ discard block |
||
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 |
||
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 |
||
64 | 64 | * @param string $id Class name (fully namespaced.) |
65 | 65 | * @return object|null |
66 | 66 | */ |
67 | - public function get( string $id ) { |
|
68 | - if ( ! $this->has( $id ) ) { |
|
69 | - throw new DI_Container_Exception( "{$id} not defined in container", 1 ); |
|
67 | + public function get(string $id) { |
|
68 | + if ( ! $this->has($id)) { |
|
69 | + throw new DI_Container_Exception("{$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 |
||
78 | 78 | * @param string $id Class name (fully namespaced.) |
79 | 79 | * @return bool |
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 |
||
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 |
||
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,7 +125,7 @@ discard block |
||
125 | 125 | * @param array<mixed> $args |
126 | 126 | * @return object|null |
127 | 127 | */ |
128 | - public function create( string $name, array $args = array() ) { |
|
129 | - return $this->dice->create( $name, $args ); |
|
128 | + public function create(string $name, array $args = array()) { |
|
129 | + return $this->dice->create($name, $args); |
|
130 | 130 | } |
131 | 131 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * @param DI_Container $di_container |
66 | 66 | * @return self |
67 | 67 | */ |
68 | - public function set_container( DI_Container $di_container ): self { |
|
68 | + public function set_container(DI_Container $di_container): self { |
|
69 | 69 | $this->di_container = $di_container; |
70 | 70 | return $this; |
71 | 71 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @param Hook_Loader $loader |
77 | 77 | * @return self |
78 | 78 | */ |
79 | - public function set_loader( Hook_Loader $loader ): self { |
|
79 | + public function set_loader(Hook_Loader $loader): self { |
|
80 | 80 | $this->loader = $loader; |
81 | 81 | return $this; |
82 | 82 | } |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | * @param Registration_Middleware $middleware |
88 | 88 | * @return self |
89 | 89 | */ |
90 | - public function push_middleware( Registration_Middleware $middleware ): self { |
|
91 | - $this->middleware[ \get_class( $middleware ) ] = $middleware; |
|
90 | + public function push_middleware(Registration_Middleware $middleware): self { |
|
91 | + $this->middleware[\get_class($middleware)] = $middleware; |
|
92 | 92 | return $this; |
93 | 93 | } |
94 | 94 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * @param array<string> $class_list |
99 | 99 | * @return self |
100 | 100 | */ |
101 | - public function set_classes( array $class_list ): self { |
|
101 | + public function set_classes(array $class_list): self { |
|
102 | 102 | $this->class_list = $class_list; |
103 | 103 | return $this; |
104 | 104 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @param string $class |
110 | 110 | * @return self |
111 | 111 | */ |
112 | - public function push_class( string $class ): self { |
|
112 | + public function push_class(string $class): self { |
|
113 | 113 | $this->class_list[] = $class; |
114 | 114 | return $this; |
115 | 115 | } |
@@ -121,30 +121,30 @@ discard block |
||
121 | 121 | */ |
122 | 122 | public function process(): void { |
123 | 123 | // Filter all classes, before processing. |
124 | - $class_list = apply_filters( Hooks::APP_INIT_REGISTRATION_CLASS_LIST, $this->class_list ); |
|
125 | - foreach ( $this->middleware as $middleware ) { |
|
124 | + $class_list = apply_filters(Hooks::APP_INIT_REGISTRATION_CLASS_LIST, $this->class_list); |
|
125 | + foreach ($this->middleware as $middleware) { |
|
126 | 126 | |
127 | 127 | // Set the container if requested. |
128 | - if ( \method_exists( $middleware, 'set_di_container' ) && ! is_null( $this->di_container ) ) { |
|
129 | - $middleware->set_di_container( $this->di_container ); |
|
128 | + if (\method_exists($middleware, 'set_di_container') && ! is_null($this->di_container)) { |
|
129 | + $middleware->set_di_container($this->di_container); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | // Set the hook loader if requested. |
133 | - if ( \method_exists( $middleware, 'set_hook_loader' ) && ! is_null( $this->loader ) ) { |
|
134 | - $middleware->set_hook_loader( $this->loader ); |
|
133 | + if (\method_exists($middleware, 'set_hook_loader') && ! is_null($this->loader)) { |
|
134 | + $middleware->set_hook_loader($this->loader); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | // Run middleware setup |
138 | 138 | $middleware->setup(); |
139 | 139 | |
140 | 140 | // Pass each class to the middleware. |
141 | - foreach ( $class_list as $class ) { |
|
141 | + foreach ($class_list as $class) { |
|
142 | 142 | // Construct class using container, |
143 | - $class_instance = $this->di_container->create( $class ); |
|
143 | + $class_instance = $this->di_container->create($class); |
|
144 | 144 | |
145 | 145 | // if valid object process via current middleware |
146 | - if ( is_object( $class_instance ) ) { |
|
147 | - $middleware->process( $class_instance ); |
|
146 | + if (is_object($class_instance)) { |
|
147 | + $middleware->process($class_instance); |
|
148 | 148 | } |
149 | 149 | } |
150 | 150 |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @param string $base_view_path |
54 | 54 | */ |
55 | - public function __construct( string $base_view_path ) { |
|
56 | - $this->base_view_path = $this->verify_view_path( $base_view_path ); |
|
55 | + public function __construct(string $base_view_path) { |
|
56 | + $this->base_view_path = $this->verify_view_path($base_view_path); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @param Component_Compiler $compiler |
63 | 63 | * @return void |
64 | 64 | */ |
65 | - public function set_component_compiler( Component_Compiler $compiler ): void { |
|
65 | + public function set_component_compiler(Component_Compiler $compiler): void { |
|
66 | 66 | $this->component_compiler = $compiler; |
67 | 67 | } |
68 | 68 | |
@@ -74,12 +74,12 @@ discard block |
||
74 | 74 | * @param bool $print |
75 | 75 | * @return string|void |
76 | 76 | */ |
77 | - public function render( string $view, iterable $data, bool $print = true ) { |
|
78 | - $view = $this->resolve_file_path( $view ); |
|
79 | - if ( $print ) { |
|
80 | - print( $this->render_buffer( $view, $data ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
77 | + public function render(string $view, iterable $data, bool $print = true) { |
|
78 | + $view = $this->resolve_file_path($view); |
|
79 | + if ($print) { |
|
80 | + print($this->render_buffer($view, $data)); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
81 | 81 | } else { |
82 | - return $this->render_buffer( $view, $data ); |
|
82 | + return $this->render_buffer($view, $data); |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
@@ -89,21 +89,21 @@ discard block |
||
89 | 89 | * @param Component $component |
90 | 90 | * @return string|void |
91 | 91 | */ |
92 | - public function component( Component $component, bool $print = true ) { |
|
92 | + public function component(Component $component, bool $print = true) { |
|
93 | 93 | |
94 | 94 | // Throw exception of no compiler passed. |
95 | - if ( ! is_a( $this->component_compiler, Component_Compiler::class ) ) { |
|
96 | - throw new Exception( 'No component compiler passed to PHP_Engine' ); |
|
95 | + if ( ! is_a($this->component_compiler, Component_Compiler::class)) { |
|
96 | + throw new Exception('No component compiler passed to PHP_Engine'); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | // Compile the component. |
100 | - $compiled = $this->component_compiler->compile( $component ); |
|
101 | - $template = $this->maybe_resolve_dot_notation( $compiled->template() ); |
|
102 | - $view = sprintf( '%s%s.php', \DIRECTORY_SEPARATOR, trim( $template ) ); |
|
103 | - if ( $print ) { |
|
104 | - print( $this->render_buffer( $view, $compiled->data() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
100 | + $compiled = $this->component_compiler->compile($component); |
|
101 | + $template = $this->maybe_resolve_dot_notation($compiled->template()); |
|
102 | + $view = sprintf('%s%s.php', \DIRECTORY_SEPARATOR, trim($template)); |
|
103 | + if ($print) { |
|
104 | + print($this->render_buffer($view, $compiled->data())); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
105 | 105 | } else { |
106 | - return $this->render_buffer( $view, $compiled->data() ); |
|
106 | + return $this->render_buffer($view, $compiled->data()); |
|
107 | 107 | } |
108 | 108 | } |
109 | 109 | |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | * @param View_Model $view_model |
115 | 115 | * @return string|void |
116 | 116 | */ |
117 | - public function view_model( View_Model $view_model, bool $print = true ) { |
|
118 | - return $this->render( $view_model->template(), $view_model->data(), $print ); |
|
117 | + public function view_model(View_Model $view_model, bool $print = true) { |
|
118 | + return $this->render($view_model->template(), $view_model->data(), $print); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -126,11 +126,11 @@ discard block |
||
126 | 126 | * @param bool $print |
127 | 127 | * @return string|void |
128 | 128 | */ |
129 | - public function partial( string $view, iterable $data = array(), bool $print = true ) { |
|
130 | - if ( $print ) { |
|
131 | - $this->render( $view, $data, $print ); |
|
129 | + public function partial(string $view, iterable $data = array(), bool $print = true) { |
|
130 | + if ($print) { |
|
131 | + $this->render($view, $data, $print); |
|
132 | 132 | } else { |
133 | - return $this->render( $view, $data, $print ); |
|
133 | + return $this->render($view, $data, $print); |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | |
@@ -142,27 +142,27 @@ discard block |
||
142 | 142 | * @return string |
143 | 143 | * @throws Exception |
144 | 144 | */ |
145 | - private function render_buffer( string $view, iterable $__data ): string { |
|
145 | + private function render_buffer(string $view, iterable $__data): string { |
|
146 | 146 | |
147 | - if ( ! file_exists( $view ) ) { |
|
148 | - throw new Exception( "{$view} doesn't exist" ); |
|
147 | + if ( ! file_exists($view)) { |
|
148 | + throw new Exception("{$view} doesn't exist"); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | $output = ''; |
152 | 152 | ob_start(); |
153 | 153 | |
154 | 154 | // Set all the data values a parameters. |
155 | - foreach ( $__data as $__key => $__value ) { |
|
156 | - if ( is_string( $__key ) ) { |
|
157 | - ${\wp_strip_all_tags( $__key )} = $__value; |
|
155 | + foreach ($__data as $__key => $__value) { |
|
156 | + if (is_string($__key)) { |
|
157 | + ${\wp_strip_all_tags($__key)} = $__value; |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | // Unset the key and value. |
161 | - unset( $__key, $__value ); |
|
161 | + unset($__key, $__value); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | // Unset the data. |
165 | - unset( $__data ); |
|
165 | + unset($__data); |
|
166 | 166 | |
167 | 167 | include $view; |
168 | 168 | $output = ob_get_contents(); |
@@ -176,12 +176,12 @@ discard block |
||
176 | 176 | * @param string $filename |
177 | 177 | * @return string |
178 | 178 | */ |
179 | - private function resolve_file_path( string $filename ): string { |
|
180 | - $filename = $this->maybe_resolve_dot_notation( $filename ); |
|
179 | + private function resolve_file_path(string $filename): string { |
|
180 | + $filename = $this->maybe_resolve_dot_notation($filename); |
|
181 | 181 | return sprintf( |
182 | 182 | '%s%s.php', |
183 | 183 | $this->base_view_path, |
184 | - trim( $filename ) |
|
184 | + trim($filename) |
|
185 | 185 | ); |
186 | 186 | } |
187 | 187 | |
@@ -191,13 +191,13 @@ discard block |
||
191 | 191 | * @param string $filename |
192 | 192 | * @return string |
193 | 193 | */ |
194 | - private function maybe_resolve_dot_notation( string $filename ): string { |
|
195 | - if ( endsWith( '.php' )( $filename ) ) { |
|
196 | - $filename = substr( $filename, 0, -4 ); |
|
194 | + private function maybe_resolve_dot_notation(string $filename): string { |
|
195 | + if (endsWith('.php')($filename)) { |
|
196 | + $filename = substr($filename, 0, -4); |
|
197 | 197 | } |
198 | 198 | |
199 | - $parts = explode( '.', $filename ); |
|
200 | - $filename = implode( DIRECTORY_SEPARATOR, $parts ); |
|
199 | + $parts = explode('.', $filename); |
|
200 | + $filename = implode(DIRECTORY_SEPARATOR, $parts); |
|
201 | 201 | |
202 | 202 | return $filename; |
203 | 203 | } |
@@ -209,12 +209,12 @@ discard block |
||
209 | 209 | * @return string |
210 | 210 | * @throws Exception |
211 | 211 | */ |
212 | - private function verify_view_path( string $path ): string { |
|
213 | - $path = $this->maybe_resolve_dot_notation( $path ); |
|
214 | - $path = rtrim( $path, '/' ) . '/'; |
|
212 | + private function verify_view_path(string $path): string { |
|
213 | + $path = $this->maybe_resolve_dot_notation($path); |
|
214 | + $path = rtrim($path, '/') . '/'; |
|
215 | 215 | |
216 | - if ( ! \is_dir( $path ) ) { |
|
217 | - throw new Exception( "{$path} doesn't exist and cant be used as the base view path." ); |
|
216 | + if ( ! \is_dir($path)) { |
|
217 | + throw new Exception("{$path} doesn't exist and cant be used as the base view path."); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | return $path; |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | private $component_aliases = array(); |
51 | 51 | |
52 | 52 | /** @param array<string, string> $component_aliases */ |
53 | - public function __construct( string $component_base_path = '', array $component_aliases = array() ) { |
|
53 | + public function __construct(string $component_base_path = '', array $component_aliases = array()) { |
|
54 | 54 | $this->component_base_path = $component_base_path; |
55 | - $this->component_aliases = \apply_filters( Hooks::COMPONENT_ALIASES, $component_aliases ); |
|
55 | + $this->component_aliases = \apply_filters(Hooks::COMPONENT_ALIASES, $component_aliases); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | * @param Component $component |
62 | 62 | * @return View_Model |
63 | 63 | */ |
64 | - public function compile( Component $component ): View_Model { |
|
65 | - return new View_Model( $this->get_component_path( $component ), $component->get_variables() ); |
|
64 | + public function compile(Component $component): View_Model { |
|
65 | + return new View_Model($this->get_component_path($component), $component->get_variables()); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -71,34 +71,34 @@ discard block |
||
71 | 71 | * @param Component $component |
72 | 72 | * @return string |
73 | 73 | */ |
74 | - private function get_component_path( Component $component ): string { |
|
74 | + private function get_component_path(Component $component): string { |
|
75 | 75 | |
76 | 76 | // Check aliases. |
77 | - $aliases = \apply_filters( Hooks::COMPONENT_ALIASES, $this->component_aliases ); |
|
77 | + $aliases = \apply_filters(Hooks::COMPONENT_ALIASES, $this->component_aliases); |
|
78 | 78 | |
79 | - if ( isset( $aliases[ get_class( $component ) ] ) ) { |
|
80 | - return esc_attr( $aliases[ get_class( $component ) ] ); |
|
79 | + if (isset($aliases[get_class($component)])) { |
|
80 | + return esc_attr($aliases[get_class($component)]); |
|
81 | 81 | } |
82 | 82 | |
83 | - $from_annotation = $this->get_annotation( 'view', $component ); |
|
83 | + $from_annotation = $this->get_annotation('view', $component); |
|
84 | 84 | |
85 | 85 | // If it does have a path defined, use that. |
86 | - if ( ! empty( $from_annotation ) ) { |
|
87 | - return \trailingslashit( $this->component_base_path ) . $from_annotation; |
|
86 | + if ( ! empty($from_annotation)) { |
|
87 | + return \trailingslashit($this->component_base_path) . $from_annotation; |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | // If the component has a defined path |
91 | - if ( $component->template() ) { |
|
92 | - return \trailingslashit( $this->component_base_path ) . $component->template(); |
|
91 | + if ($component->template()) { |
|
92 | + return \trailingslashit($this->component_base_path) . $component->template(); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | // Get path based on class name. |
96 | - $reflect = new \ReflectionClass( $component ); |
|
96 | + $reflect = new \ReflectionClass($component); |
|
97 | 97 | $short_name = $reflect->getShortName(); |
98 | 98 | // Add space between capitals, make lowercase and replace underscores with dashes. |
99 | - $short_name = strtolower( preg_replace( '/(?<!^)[A-Z]/', '$0', $short_name ) ?? '' ); |
|
100 | - $short_name = str_replace( '_', '-', $short_name ); |
|
101 | - return \trailingslashit( $this->component_base_path ) . $short_name; |
|
99 | + $short_name = strtolower(preg_replace('/(?<!^)[A-Z]/', '$0', $short_name) ?? ''); |
|
100 | + $short_name = str_replace('_', '-', $short_name); |
|
101 | + return \trailingslashit($this->component_base_path) . $short_name; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -108,18 +108,18 @@ discard block |
||
108 | 108 | * @param Component $component |
109 | 109 | * @return string|null |
110 | 110 | */ |
111 | - private function get_annotation( string $annotation, Component $component ): ?string { |
|
112 | - $reflect = new \ReflectionClass( $component ); |
|
111 | + private function get_annotation(string $annotation, Component $component): ?string { |
|
112 | + $reflect = new \ReflectionClass($component); |
|
113 | 113 | $comment = $reflect->getDocComment(); |
114 | 114 | |
115 | 115 | // if no comment, return null. |
116 | - if ( empty( $comment ) ) { |
|
116 | + if (empty($comment)) { |
|
117 | 117 | return null; |
118 | 118 | } |
119 | 119 | |
120 | 120 | // Check if the comment contains the annotation "@{$annotation}" using regex. |
121 | 121 | $pattern = "/@{$annotation}\s+(.*)/"; |
122 | - preg_match( $pattern, $comment, $matches ); |
|
122 | + preg_match($pattern, $comment, $matches); |
|
123 | 123 | |
124 | 124 | return $matches[1] ?? null; |
125 | 125 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * @param bool $print |
36 | 36 | * @return void|string |
37 | 37 | */ |
38 | - public function render( string $view, iterable $data, bool $print = true ); |
|
38 | + public function render(string $view, iterable $data, bool $print = true); |
|
39 | 39 | |
40 | 40 | /** |
41 | 41 | * Renders a component. |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @param Component $component |
44 | 44 | * @return string|void |
45 | 45 | */ |
46 | - public function component( Component $component, bool $print = true ); |
|
46 | + public function component(Component $component, bool $print = true); |
|
47 | 47 | |
48 | 48 | /** |
49 | 49 | * Renders a view Model |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * @param View_Model $view_model |
52 | 52 | * @return string|void |
53 | 53 | */ |
54 | - public function view_model( View_Model $view_model, bool $print = true ); |
|
54 | + public function view_model(View_Model $view_model, bool $print = true); |
|
55 | 55 | |
56 | 56 | /** |
57 | 57 | * Sets the component compiler. |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * @param Component_Compiler $compiler |
60 | 60 | * @return void |
61 | 61 | */ |
62 | - public function set_component_compiler( Component_Compiler $compiler ): void; |
|
62 | + public function set_component_compiler(Component_Compiler $compiler): void; |
|
63 | 63 | |
64 | 64 | /** |
65 | 65 | * Returns the base view path. |