@@ -136,7 +136,7 @@ |
||
136 | 136 | */ |
137 | 137 | protected function get_primary_page( Abstract_Group $group ): Page { |
138 | 138 | /** |
139 | - * @var Page |
|
139 | + * @var Page |
|
140 | 140 | */ |
141 | 141 | $page = $this->di_container->create( $group->get_primary_page() ); |
142 | 142 |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | protected View $view; |
41 | 41 | protected Registrar $registrar; |
42 | 42 | |
43 | - public function __construct( DI_Container $di_container, View $view, Registrar $registrar ) { |
|
43 | + public function __construct(DI_Container $di_container, View $view, Registrar $registrar) { |
|
44 | 44 | $this->di_container = $di_container; |
45 | 45 | $this->view = $view; |
46 | 46 | $this->registrar = $registrar; |
@@ -52,10 +52,10 @@ discard block |
||
52 | 52 | * @param \PinkCrab\Perique_Admin_Menu\Group\Abstract_Group $group |
53 | 53 | * @return void |
54 | 54 | */ |
55 | - public function register_group( Abstract_Group $group ): void { |
|
55 | + public function register_group(Abstract_Group $group): void { |
|
56 | 56 | |
57 | 57 | // If current user can not access the group, bail without attempting to register. |
58 | - if ( ! current_user_can( $group->get_capability() ) ) { |
|
58 | + if ( ! current_user_can($group->get_capability())) { |
|
59 | 59 | return; |
60 | 60 | } |
61 | 61 | |
@@ -63,19 +63,19 @@ discard block |
||
63 | 63 | |
64 | 64 | // Validate the group. |
65 | 65 | $validator = new Group_Validator(); |
66 | - if ( ! $validator->validate( $group ) ) { |
|
67 | - throw Group_Exception::failed_validation( $validator, $group ); |
|
66 | + if ( ! $validator->validate($group)) { |
|
67 | + throw Group_Exception::failed_validation($validator, $group); |
|
68 | 68 | } |
69 | 69 | |
70 | - $this->register_primary_page( $group ); |
|
70 | + $this->register_primary_page($group); |
|
71 | 71 | |
72 | 72 | // Register all pages and attempt to set primary page name in menu. |
73 | - foreach ( $this->get_pages( $group ) as $page ) { |
|
74 | - $this->register_subpage( $page, $this->get_primary_page( $group )->slug(), $group ); |
|
73 | + foreach ($this->get_pages($group) as $page) { |
|
74 | + $this->register_subpage($page, $this->get_primary_page($group)->slug(), $group); |
|
75 | 75 | } |
76 | - $this->set_primary_page_details( $group ); |
|
77 | - } catch ( \Throwable $th ) { |
|
78 | - $this->admin_exception_notice( $group, $th ); |
|
76 | + $this->set_primary_page_details($group); |
|
77 | + } catch (\Throwable $th) { |
|
78 | + $this->admin_exception_notice($group, $th); |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
@@ -86,22 +86,22 @@ discard block |
||
86 | 86 | * @param \Throwable $exception |
87 | 87 | * @return void |
88 | 88 | */ |
89 | - public function admin_exception_notice( $object_instance, Throwable $exception ): void { |
|
89 | + public function admin_exception_notice($object_instance, Throwable $exception): void { |
|
90 | 90 | add_action( |
91 | 91 | 'admin_notices', |
92 | - function () use ( $object_instance, $exception ) { |
|
92 | + function() use ($object_instance, $exception) { |
|
93 | 93 | $class = 'notice notice-error'; |
94 | 94 | $message = sprintf( |
95 | 95 | '%s <i>%s</i> generated errors while being registered. This might result in admin pages being missing or broken. <br><b>%s(%s: %s)</b>', |
96 | - get_class( $object_instance ) === Page::class ? 'Page' : 'Menu Group', |
|
97 | - get_class( $object_instance ), |
|
96 | + get_class($object_instance) === Page::class ? 'Page' : 'Menu Group', |
|
97 | + get_class($object_instance), |
|
98 | 98 | $exception->getMessage(), |
99 | 99 | $exception->getFile(), |
100 | 100 | $exception->getLine() |
101 | 101 | ); |
102 | 102 | printf( |
103 | 103 | '<div class="%1$s"><p>%2$s</p></div>', |
104 | - esc_attr( $class ), |
|
104 | + esc_attr($class), |
|
105 | 105 | wp_kses( |
106 | 106 | $message, |
107 | 107 | array( |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | * @param \PinkCrab\Perique_Admin_Menu\Group\Abstract_Group $group |
122 | 122 | * @return void |
123 | 123 | */ |
124 | - protected function register_primary_page( Abstract_Group $group ): void { |
|
124 | + protected function register_primary_page(Abstract_Group $group): void { |
|
125 | 125 | $this->registrar->register_primary( |
126 | - $this->get_primary_page( $group ), |
|
126 | + $this->get_primary_page($group), |
|
127 | 127 | $group |
128 | 128 | ); |
129 | 129 | } |
@@ -134,19 +134,19 @@ discard block |
||
134 | 134 | * @param \PinkCrab\Perique_Admin_Menu\Group\Abstract_Group $group |
135 | 135 | * @return \PinkCrab\Perique_Admin_Menu\Page\Page |
136 | 136 | */ |
137 | - protected function get_primary_page( Abstract_Group $group ): Page { |
|
137 | + protected function get_primary_page(Abstract_Group $group): Page { |
|
138 | 138 | /** |
139 | 139 | * @var Page |
140 | 140 | */ |
141 | - $page = $this->di_container->create( $group->get_primary_page() ); |
|
141 | + $page = $this->di_container->create($group->get_primary_page()); |
|
142 | 142 | |
143 | - if ( ! is_object( $page ) || ! is_a( $page, Page::class ) ) { |
|
144 | - throw Page_Exception::invalid_page_type( $page ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped, escaped in exception. |
|
143 | + if ( ! is_object($page) || ! is_a($page, Page::class)) { |
|
144 | + throw Page_Exception::invalid_page_type($page); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped, escaped in exception. |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | // Register view if requied. |
148 | - if ( \method_exists( $page, 'set_view' ) ) { |
|
149 | - $page->set_view( $this->view ); |
|
148 | + if (\method_exists($page, 'set_view')) { |
|
149 | + $page->set_view($this->view); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | return $page; |
@@ -160,18 +160,18 @@ discard block |
||
160 | 160 | * @return array<Page> |
161 | 161 | * @throws Page_Exception (Code 202) |
162 | 162 | */ |
163 | - protected function get_pages( Abstract_Group $group ): array { |
|
163 | + protected function get_pages(Abstract_Group $group): array { |
|
164 | 164 | return array_map( |
165 | - function ( string $page ): Page { |
|
166 | - $constructed_page = $this->di_container->create( $page ); |
|
167 | - if ( ! is_object( $constructed_page ) || ! is_a( $constructed_page, Page::class ) ) { |
|
168 | - throw Page_Exception::invalid_page_type( $constructed_page ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped, escaped in exception. |
|
165 | + function(string $page): Page { |
|
166 | + $constructed_page = $this->di_container->create($page); |
|
167 | + if ( ! is_object($constructed_page) || ! is_a($constructed_page, Page::class)) { |
|
168 | + throw Page_Exception::invalid_page_type($constructed_page); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped, escaped in exception. |
|
169 | 169 | } |
170 | 170 | return $constructed_page; |
171 | 171 | }, |
172 | 172 | array_filter( |
173 | 173 | $group->get_pages(), |
174 | - function ( string $page ) use ( $group ) { |
|
174 | + function(string $page) use ($group) { |
|
175 | 175 | return $page !== $group->get_primary_page(); |
176 | 176 | } |
177 | 177 | ) |
@@ -187,22 +187,22 @@ discard block |
||
187 | 187 | * @phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited |
188 | 188 | * @throws Group_Exception (code 253) |
189 | 189 | */ |
190 | - protected function set_primary_page_details( Abstract_Group $group ) { |
|
190 | + protected function set_primary_page_details(Abstract_Group $group) { |
|
191 | 191 | global $submenu; |
192 | 192 | |
193 | - $primary = $this->get_primary_page( $group ); |
|
193 | + $primary = $this->get_primary_page($group); |
|
194 | 194 | |
195 | - if ( ! array_key_exists( $primary->slug(), $submenu ) ) { |
|
195 | + if ( ! array_key_exists($primary->slug(), $submenu)) { |
|
196 | 196 | return; |
197 | 197 | } |
198 | 198 | |
199 | 199 | $primary_page_key = array_search( |
200 | 200 | $primary->slug(), |
201 | - \array_column( $submenu[ $primary->slug() ], 2 ), |
|
201 | + \array_column($submenu[$primary->slug()], 2), |
|
202 | 202 | true |
203 | 203 | ) ?: 0; // phpcs:ignore Universal.Operators.DisallowShortTernary.Found |
204 | 204 | |
205 | - $submenu[ $primary->slug() ][ $primary_page_key ][0] = $primary->menu_title(); |
|
205 | + $submenu[$primary->slug()][$primary_page_key][0] = $primary->menu_title(); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | |
@@ -214,21 +214,21 @@ discard block |
||
214 | 214 | * @param \PinkCrab\Perique_Admin_Menu\Group\Abstract_Group|null $group |
215 | 215 | * @return void |
216 | 216 | */ |
217 | - public function register_subpage( Page $page, string $parent_slug, ?Abstract_Group $group = null ): void { |
|
217 | + public function register_subpage(Page $page, string $parent_slug, ?Abstract_Group $group = null): void { |
|
218 | 218 | // If user cant access the page, bail before attempting to register. |
219 | - if ( ! current_user_can( $page->capability() ) ) { |
|
219 | + if ( ! current_user_can($page->capability())) { |
|
220 | 220 | return; |
221 | 221 | } |
222 | 222 | |
223 | 223 | // Register view if required. |
224 | - if ( \method_exists( $page, 'set_view' ) ) { |
|
225 | - $page->set_view( $this->view ); |
|
224 | + if (\method_exists($page, 'set_view')) { |
|
225 | + $page->set_view($this->view); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | try { |
229 | - $this->registrar->register_subpage( $page, $parent_slug, $group ); |
|
230 | - } catch ( \Throwable $th ) { |
|
231 | - $this->admin_exception_notice( $page, $th ); |
|
229 | + $this->registrar->register_subpage($page, $parent_slug, $group); |
|
230 | + } catch (\Throwable $th) { |
|
231 | + $this->admin_exception_notice($page, $th); |
|
232 | 232 | } |
233 | 233 | } |
234 | 234 | |
@@ -238,16 +238,16 @@ discard block |
||
238 | 238 | * @param \PinkCrab\Perique_Admin_Menu\Page\Page $page |
239 | 239 | * @return void |
240 | 240 | */ |
241 | - public function register_single_page( Page $page ): void { |
|
241 | + public function register_single_page(Page $page): void { |
|
242 | 242 | // Register view if required. |
243 | - if ( \method_exists( $page, 'set_view' ) ) { |
|
244 | - $page->set_view( $this->view ); |
|
243 | + if (\method_exists($page, 'set_view')) { |
|
244 | + $page->set_view($this->view); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | try { |
248 | - $this->registrar->register_primary( $page, null ); |
|
249 | - } catch ( \Throwable $th ) { |
|
250 | - $this->admin_exception_notice( $page, $th ); |
|
248 | + $this->registrar->register_primary($page, null); |
|
249 | + } catch (\Throwable $th) { |
|
250 | + $this->admin_exception_notice($page, $th); |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 | } |
@@ -53,41 +53,41 @@ discard block |
||
53 | 53 | * @param object $class_instance |
54 | 54 | * @return object |
55 | 55 | */ |
56 | - public function process( object $class_instance ): object { |
|
56 | + public function process(object $class_instance): object { |
|
57 | 57 | // If we have a valid SUB page. |
58 | 58 | if ( |
59 | - is_a( $class_instance, Page::class ) |
|
59 | + is_a($class_instance, Page::class) |
|
60 | 60 | && is_admin() |
61 | - && ! is_null( $class_instance->parent_slug() ) |
|
61 | + && ! is_null($class_instance->parent_slug()) |
|
62 | 62 | ) { |
63 | 63 | $this->add_to_loader( |
64 | - function () use ( $class_instance ): void { |
|
65 | - $this->dispatcher->register_subpage( $class_instance, $class_instance->parent_slug() ); |
|
64 | + function() use ($class_instance): void { |
|
65 | + $this->dispatcher->register_subpage($class_instance, $class_instance->parent_slug()); |
|
66 | 66 | } |
67 | 67 | ); |
68 | 68 | } |
69 | 69 | |
70 | 70 | // If we have a valid SINGLE/PARENT page. |
71 | 71 | if ( |
72 | - is_a( $class_instance, Page::class ) |
|
72 | + is_a($class_instance, Page::class) |
|
73 | 73 | && is_admin() |
74 | - && is_null( $class_instance->parent_slug() ) |
|
74 | + && is_null($class_instance->parent_slug()) |
|
75 | 75 | ) { |
76 | 76 | $this->add_to_loader( |
77 | - function () use ( $class_instance ): void { |
|
78 | - $this->dispatcher->register_single_page( $class_instance ); |
|
77 | + function() use ($class_instance): void { |
|
78 | + $this->dispatcher->register_single_page($class_instance); |
|
79 | 79 | } |
80 | 80 | ); |
81 | 81 | } |
82 | 82 | |
83 | 83 | // If we have a valid group. |
84 | 84 | if ( |
85 | - is_a( $class_instance, Abstract_Group::class ) |
|
85 | + is_a($class_instance, Abstract_Group::class) |
|
86 | 86 | && is_admin() |
87 | 87 | ) { |
88 | 88 | $this->add_to_loader( |
89 | - function () use ( $class_instance ): void { |
|
90 | - $this->dispatcher->register_group( $class_instance ); |
|
89 | + function() use ($class_instance): void { |
|
90 | + $this->dispatcher->register_group($class_instance); |
|
91 | 91 | } |
92 | 92 | ); |
93 | 93 | } |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | * @param callable $callback |
101 | 101 | * @return void |
102 | 102 | */ |
103 | - protected function add_to_loader( callable $callback ): void { |
|
104 | - $this->hook_loader->action( 'admin_menu', $callback ); |
|
103 | + protected function add_to_loader(callable $callback): void { |
|
104 | + $this->hook_loader->action('admin_menu', $callback); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * @param View $view View |
107 | 107 | * @return self |
108 | 108 | */ |
109 | - public function set_view( View $view ): self { |
|
109 | + public function set_view(View $view): self { |
|
110 | 110 | $this->view = $view; |
111 | 111 | return $this; |
112 | 112 | } |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | * @return string |
123 | 123 | */ |
124 | 124 | public function slug(): string { |
125 | - if ( $this->page_slug === '' ) { |
|
126 | - throw Page_Exception::undefined_property( 'page_slug', $this ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped, escaped in exception. |
|
125 | + if ($this->page_slug === '') { |
|
126 | + throw Page_Exception::undefined_property('page_slug', $this); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped, escaped in exception. |
|
127 | 127 | } |
128 | 128 | return $this->page_slug; |
129 | 129 | } |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | * @return string |
133 | 133 | */ |
134 | 134 | public function menu_title(): string { |
135 | - if ( $this->menu_title === '' ) { |
|
136 | - throw Page_Exception::undefined_property( 'menu_title', $this ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped, escaped in exception. |
|
135 | + if ($this->menu_title === '') { |
|
136 | + throw Page_Exception::undefined_property('menu_title', $this); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped, escaped in exception. |
|
137 | 137 | } |
138 | 138 | return $this->menu_title; |
139 | 139 | } |
@@ -167,17 +167,17 @@ discard block |
||
167 | 167 | * @throws Page_Exception code 201 if template not defined. |
168 | 168 | */ |
169 | 169 | public function render_view(): callable { |
170 | - if ( null === $this->view ) { |
|
171 | - throw Page_Exception::view_not_set( $this ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped, escaped in exception. |
|
170 | + if (null === $this->view) { |
|
171 | + throw Page_Exception::view_not_set($this); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped, escaped in exception. |
|
172 | 172 | } |
173 | 173 | |
174 | - if ( '' === $this->view_template ) { |
|
175 | - throw Page_Exception::undefined_property( 'view_template', $this ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped, escaped in exception. |
|
174 | + if ('' === $this->view_template) { |
|
175 | + throw Page_Exception::undefined_property('view_template', $this); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped, escaped in exception. |
|
176 | 176 | } |
177 | 177 | |
178 | - return function () { |
|
178 | + return function() { |
|
179 | 179 | // @phpstan-ignore-next-line, as we have already checked for null. |
180 | - $this->view->render( $this->view_template, $this->view_data ); |
|
180 | + $this->view->render($this->view_template, $this->view_data); |
|
181 | 181 | }; |
182 | 182 | } |
183 | 183 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @return void |
189 | 189 | * @codeCoverageIgnore This can be tested as it does nothing and is extended only |
190 | 190 | */ |
191 | - public function enqueue( Page $page ): void { |
|
191 | + public function enqueue(Page $page): void { |
|
192 | 192 | // Do nothing. |
193 | 193 | // Can be extended in any child class that extends. |
194 | 194 | } |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | * @return void |
201 | 201 | * @codeCoverageIgnore This can be tested as it does nothing and is extended only |
202 | 202 | */ |
203 | - public function load( Page $page ): void { |
|
203 | + public function load(Page $page): void { |
|
204 | 204 | // Do nothing. |
205 | 205 | // Can be extended in any child class that extends. |
206 | 206 | } |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | * @param string $page_hook |
212 | 212 | * @return void |
213 | 213 | */ |
214 | - final public function set_page_hook( string $page_hook ): void { |
|
214 | + final public function set_page_hook(string $page_hook): void { |
|
215 | 215 | $this->page_hook = $page_hook; |
216 | 216 | } |
217 | 217 |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @return bool |
49 | 49 | */ |
50 | 50 | public function has_errors(): bool { |
51 | - return count( $this->errors ) > 0; |
|
51 | + return count($this->errors) > 0; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @param string $error |
67 | 67 | * @return void |
68 | 68 | */ |
69 | - public function push_error( string $error ): void { |
|
69 | + public function push_error(string $error): void { |
|
70 | 70 | $this->errors[] = $error; |
71 | 71 | } |
72 | 72 | |
@@ -76,5 +76,5 @@ discard block |
||
76 | 76 | * @param mixed $subject |
77 | 77 | * @return bool |
78 | 78 | */ |
79 | - abstract public function validate( $subject ): bool; |
|
79 | + abstract public function validate($subject): bool; |
|
80 | 80 | } |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | * @return string |
85 | 85 | */ |
86 | 86 | public function get_group_title(): string { |
87 | - if ( $this->group_title === null ) { |
|
88 | - throw Group_Exception::group_title_undefined( $this ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped, escaped in exception. |
|
87 | + if ($this->group_title === null) { |
|
88 | + throw Group_Exception::group_title_undefined($this); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped, escaped in exception. |
|
89 | 89 | } |
90 | 90 | return $this->group_title; |
91 | 91 | } |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | * @return string |
115 | 115 | */ |
116 | 116 | public function get_primary_page(): string { |
117 | - if ( $this->primary_page === null ) { |
|
118 | - throw Group_Exception::primary_page_undefined( $this ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped, escaped in exception. |
|
117 | + if ($this->primary_page === null) { |
|
118 | + throw Group_Exception::primary_page_undefined($this); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped, escaped in exception. |
|
119 | 119 | } |
120 | 120 | return $this->primary_page; |
121 | 121 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | * @return void |
147 | 147 | * @codeCoverageIgnore This can't be tested as it does nothing and is extended only |
148 | 148 | */ |
149 | - public function enqueue( Abstract_Group $group, Page $page ): void { |
|
149 | + public function enqueue(Abstract_Group $group, Page $page): void { |
|
150 | 150 | // Do nothing by default. |
151 | 151 | } |
152 | 152 | |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return void |
159 | 159 | * @codeCoverageIgnore This can't be tested as it does nothing and is extended only |
160 | 160 | */ |
161 | - public function load( Abstract_Group $group, Page $page ): void { |
|
161 | + public function load(Abstract_Group $group, Page $page): void { |
|
162 | 162 | // Do nothing by default. |
163 | 163 | } |
164 | 164 | } |