Skip to content

Commit a588a67

Browse files
authored
Raise coverage (#301)
* Raise coverage * Added Types * Cleanup & tests added * get_args reviewed
1 parent 285b095 commit a588a67

8 files changed

+213
-157
lines changed

includes/MslsAdmin.php

+75-55
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,16 @@ public static function init() {
4949
* @param string $capability
5050
*
5151
* @since 2.0
52-
*
5352
*/
5453
$caps = apply_filters( 'msls_admin_caps', 'manage_options' );
5554
if ( current_user_can( $caps ) ) {
5655
$title = __( 'Multisite Language Switcher', 'multisite-language-switcher' );
57-
add_options_page( $title, $title, 'manage_options', $obj->get_menu_slug(), [ $obj, 'render' ] );
56+
add_options_page( $title, $title, 'manage_options', $obj->get_menu_slug(), array( $obj, 'render' ) );
5857

59-
add_action( 'admin_init', [ $obj, 'register' ] );
60-
add_action( 'admin_notices', [ $obj, 'has_problems' ] );
58+
add_action( 'admin_init', array( $obj, 'register' ) );
59+
add_action( 'admin_notices', array( $obj, 'has_problems' ) );
6160

62-
add_filter( 'msls_admin_validate', [ $obj, 'set_blog_language' ] );
61+
add_filter( 'msls_admin_validate', array( $obj, 'set_blog_language' ) );
6362
}
6463
}
6564

@@ -88,32 +87,41 @@ public function get_options_page_link() {
8887
* You can use every method of the decorated object
8988
*
9089
* @param string $method
91-
* @param mixed $args
90+
* @param mixed $args
9291
*
9392
* @return mixed
9493
*/
9594
public function __call( $method, $args ) {
9695
$parts = explode( '_', $method, 2 );
9796

9897
if ( is_array( $parts ) && 'rewrite' === $parts[0] ) {
99-
return $this->render_rewrite( $parts[1] );
98+
$this->render_rewrite( $parts[1] );
99+
return;
100100
}
101101

102-
$checkboxes = [
103-
'activate_autocomplete' => __( 'Activate experimental autocomplete inputs',
104-
'multisite-language-switcher' ),
105-
'activate_content_import' => __( 'Activate the content import functionality',
106-
'multisite-language-switcher' ),
102+
$checkboxes = array(
103+
'activate_autocomplete' => __(
104+
'Activate experimental autocomplete inputs',
105+
'multisite-language-switcher'
106+
),
107+
'activate_content_import' => __(
108+
'Activate the content import functionality',
109+
'multisite-language-switcher'
110+
),
107111
'sort_by_description' => __( 'Sort languages by description', 'multisite-language-switcher' ),
108112
'exclude_current_blog' => __( 'Exclude this blog from output', 'multisite-language-switcher' ),
109113
'only_with_translation' => __( 'Show only links with a translation', 'multisite-language-switcher' ),
110114
'output_current_blog' => __( 'Display link to the current language', 'multisite-language-switcher' ),
111115
'content_filter' => __( 'Add hint for available translations', 'multisite-language-switcher' ),
112-
];
116+
);
113117

114-
if ( isset ( $checkboxes[ $method ] ) ) {
115-
echo ( new Group() )->add( new Checkbox( $method, $this->options->$method ) )->add( new Label( $method,
116-
$checkboxes[ $method ] ) )->render();
118+
if ( isset( $checkboxes[ $method ] ) ) {
119+
echo ( new Group() )->add( new Checkbox( $method, $this->options->$method ) )->add(
120+
new Label(
121+
$method,
122+
$checkboxes[ $method ]
123+
)
124+
)->render();
117125
} else {
118126
$value = ! empty( $this->options->$method ) ? $this->options->$method : '';
119127
echo ( new Text( $method, $value ) )->render();
@@ -122,21 +130,26 @@ public function __call( $method, $args ) {
122130

123131
/**
124132
* There is something wrong? Here comes the message...
133+
*
125134
* @return bool
126135
*/
127-
public function has_problems() {
136+
public function has_problems(): bool {
128137
$message = '';
129138

130139
if ( $this->options->is_empty() ) {
131140
$message = sprintf(
132-
__( 'Multisite Language Switcher is almost ready. You must <a href="%s">complete the configuration process</a>.',
133-
'multisite-language-switcher' ),
141+
__(
142+
'Multisite Language Switcher is almost ready. You must <a href="%s">complete the configuration process</a>.',
143+
'multisite-language-switcher'
144+
),
134145
esc_url( admin_url( $this->get_options_page_link() ) )
135146
);
136147
} elseif ( 1 == count( $this->options->get_available_languages() ) ) {
137148
$message = sprintf(
138-
__( 'There are no language files installed. You can <a href="%s">manually install some language files</a> or you could use a <a href="%s">plugin</a> to download these files automatically.',
139-
'multisite-language-switcher' ),
149+
__(
150+
'There are no language files installed. You can <a href="%1$s">manually install some language files</a> or you could use a <a href="%2$s">plugin</a> to download these files automatically.',
151+
'multisite-language-switcher'
152+
),
140153
esc_url( 'http://codex.wordpress.org/Installing_WordPress_in_Your_Language#Manually_Installing_Language_Files' ),
141154
esc_url( 'http://wordpress.org/plugins/wp-native-dashboard/' )
142155
);
@@ -148,43 +161,50 @@ public function has_problems() {
148161
/**
149162
* Render the options-page
150163
*/
151-
public function render() {
164+
public function render(): void {
152165
printf(
153166
'<div class="wrap"><div class="icon32" id="icon-options-general"><br/></div><h1>%s</h1>%s<br class="clear"/><form action="options.php" method="post"><p>%s</p>',
154167
__( 'Multisite Language Switcher Options', 'multisite-language-switcher' ),
155168
$this->subsubsub(),
156-
__( 'To achieve maximum flexibility, you have to configure each blog separately.',
157-
'multisite-language-switcher' )
169+
__(
170+
'To achieve maximum flexibility, you have to configure each blog separately.',
171+
'multisite-language-switcher'
172+
)
158173
);
159174

160175
settings_fields( 'msls' );
161176
do_settings_sections( __CLASS__ );
162177

163178
printf(
164179
'<p class="submit"><input name="Submit" type="submit" class="button button-primary" value="%s" /></p></form></div>',
165-
( $this->options->is_empty() ? __( 'Configure', 'multisite-language-switcher' ) : __( 'Update',
166-
'multisite-language-switcher' ) )
180+
( $this->options->is_empty() ? __( 'Configure', 'multisite-language-switcher' ) : __(
181+
'Update',
182+
'multisite-language-switcher'
183+
) )
167184
);
168185
}
169186

170187

171188
/**
172189
* Create a submenu which contains links to all blogs of the current user
190+
*
173191
* @return string
174192
*/
175193
public function subsubsub() {
176194
$icon_type = $this->options->get_icon_type();
177195

178-
$arr = [];
196+
$arr = array();
179197
foreach ( $this->collection->get_plugin_active_blogs() as $blog ) {
180198
$admin_url = get_admin_url( $blog->userblog_id, $this->get_options_page_link() );
181199
$current = $blog->userblog_id == $this->collection->get_current_blog_id() ? ' class="current"' : '';
182200

183201
$arr[] = sprintf( '<a href="%1$s"%2$s>%3$s</a>', $admin_url, $current, $blog->get_title( $icon_type ) );
184202
}
185203

186-
return empty( $arr ) ? '' : sprintf( '<ul class="subsubsub"><li>%s</li></ul>',
187-
implode( ' | </li><li>', $arr ) );
204+
return empty( $arr ) ? '' : sprintf(
205+
'<ul class="subsubsub"><li>%s</li></ul>',
206+
implode( ' | </li><li>', $arr )
207+
);
188208
}
189209

190210
/**
@@ -193,21 +213,21 @@ public function subsubsub() {
193213
* @codeCoverageIgnore
194214
*/
195215
public function register() {
196-
register_setting( 'msls', 'msls', [ $this, 'validate' ] );
216+
register_setting( 'msls', 'msls', array( $this, 'validate' ) );
197217

198-
$sections = [
218+
$sections = array(
199219
'language_section' => __( 'Language Settings', 'multisite-language-switcher' ),
200220
'main_section' => __( 'Main Settings', 'multisite-language-switcher' ),
201221
'advanced_section' => __( 'Advanced Settings', 'multisite-language-switcher' ),
202-
];
222+
);
203223

204224
global $wp_rewrite;
205225
if ( $wp_rewrite->using_permalinks() ) {
206226
$sections['rewrites_section'] = __( 'Rewrites Settings', 'multisite-language-switcher' );
207227
}
208228

209229
foreach ( $sections as $id => $title ) {
210-
add_settings_section( $id, $title, [ $this, $id ], __CLASS__ );
230+
add_settings_section( $id, $title, array( $this, $id ), __CLASS__ );
211231
}
212232

213233
/**
@@ -216,7 +236,6 @@ public function register() {
216236
* @param string $page
217237
*
218238
* @since 1.0
219-
*
220239
*/
221240
do_action( 'msls_admin_register', __CLASS__ );
222241
}
@@ -229,7 +248,7 @@ public function register() {
229248
* @return int
230249
*/
231250
public function language_section(): int {
232-
$map = [ 'blog_language' => __( 'Blog Language', 'multisite-language-switcher' ) ];
251+
$map = array( 'blog_language' => __( 'Blog Language', 'multisite-language-switcher' ) );
233252

234253
return $this->add_settings_fields( $map, 'language_section' );
235254
}
@@ -242,7 +261,7 @@ public function language_section(): int {
242261
* @return int
243262
*/
244263
public function main_section(): int {
245-
$map = [
264+
$map = array(
246265
'display' => __( 'Display', 'multisite-language-switcher' ),
247266
'admin_display' => __( 'Admin Display', 'multisite-language-switcher' ),
248267
'sort_by_description' => __( 'Sort languages', 'multisite-language-switcher' ),
@@ -255,7 +274,7 @@ public function main_section(): int {
255274
'after_item' => __( 'Text/HTML after each item', 'multisite-language-switcher' ),
256275
'content_filter' => __( 'Available translations hint', 'multisite-language-switcher' ),
257276
'content_priority' => __( 'Hint priority', 'multisite-language-switcher' ),
258-
];
277+
);
259278

260279
return $this->add_settings_fields( $map, 'main_section' );
261280
}
@@ -268,13 +287,13 @@ public function main_section(): int {
268287
* @return int
269288
*/
270289
public function advanced_section(): int {
271-
$map = [
290+
$map = array(
272291
'activate_autocomplete' => __( 'Autocomplete', 'multisite-language-switcher' ),
273292
'image_url' => __( 'Custom URL for flag-images', 'multisite-language-switcher' ),
274293
'reference_user' => __( 'Reference user', 'multisite-language-switcher' ),
275294
'exclude_current_blog' => __( 'Exclude blog', 'multisite-language-switcher' ),
276295
'activate_content_import' => __( 'Content import', 'multisite-language-switcher' ),
277-
];
296+
);
278297

279298
return $this->add_settings_fields( $map, 'advanced_section' );
280299
}
@@ -287,23 +306,23 @@ public function advanced_section(): int {
287306
* @return int
288307
*/
289308
public function rewrites_section(): int {
290-
$map = [];
291-
foreach ( get_post_types( [ 'public' => true ], 'objects' ) as $key => $object ) {
292-
$map["rewrite_{$key}"] = sprintf( __( '%s Slug', 'multisite-language-switcher' ), $object->label );
309+
$map = array();
310+
foreach ( get_post_types( array( 'public' => true ), 'objects' ) as $key => $object ) {
311+
$map[ "rewrite_{$key}" ] = sprintf( __( '%s Slug', 'multisite-language-switcher' ), $object->label );
293312
}
294313

295314
return $this->add_settings_fields( $map, 'rewrites_section' );
296315
}
297316

298317
/**
299-
* @param array $map
318+
* @param array $map
300319
* @param string $section
301320
*
302321
* @return int
303322
*/
304323
protected function add_settings_fields( array $map, string $section ): int {
305324
foreach ( $map as $id => $title ) {
306-
add_settings_field( $id, $title, [ $this, $id ], __CLASS__, $section, [ 'label_for' => $id ] );
325+
add_settings_field( $id, $title, array( $this, $id ), __CLASS__, $section, array( 'label_for' => $id ) );
307326
}
308327

309328
/**
@@ -313,7 +332,6 @@ protected function add_settings_fields( array $map, string $section ): int {
313332
* @param string $section
314333
*
315334
* @since 2.4.4
316-
*
317335
*/
318336
do_action( "msls_admin_{$section}", __CLASS__, $section );
319337

@@ -341,30 +359,34 @@ public function display() {
341359
* Shows the select-form-field 'admin_display'
342360
*/
343361
public function admin_display() {
344-
echo ( new Select( 'admin_display',
362+
echo ( new Select(
363+
'admin_display',
345364
array(
346365
'flag' => __( 'Flag', 'multisite-language-switcher' ),
347-
'label' => __( 'Label', 'multisite-language-switcher' )
366+
'label' => __( 'Label', 'multisite-language-switcher' ),
348367
),
349-
$this->options->admin_display ) )->render();
368+
$this->options->admin_display
369+
) )->render();
350370
}
351371

352372
/**
353373
* Shows the select-form-field 'reference_user'
354374
*/
355375
public function reference_user() {
356-
$users = [];
376+
$users = array();
357377

358-
foreach ( ( array ) apply_filters( 'msls_reference_users', $this->collection->get_users() ) as $user ) {
378+
foreach ( (array) apply_filters( 'msls_reference_users', $this->collection->get_users() ) as $user ) {
359379
$users[ $user->ID ] = $user->user_nicename;
360380
}
361381

362382
if ( count( $users ) > self::MAX_REFERENCE_USERS ) {
363383
$users = array_slice( $users, 0, self::MAX_REFERENCE_USERS, true );
364384

365385
$message = sprintf(
366-
__( 'Multisite Language Switcher: Collection for reference user has been truncated because it exceeded the maximum of %s users. Please, use the hook "msls_reference_users" to filter the result before!',
367-
'multisite-language-switcher' ),
386+
__(
387+
'Multisite Language Switcher: Collection for reference user has been truncated because it exceeded the maximum of %s users. Please, use the hook "msls_reference_users" to filter the result before!',
388+
'multisite-language-switcher'
389+
),
368390
self::MAX_REFERENCE_USERS
369391
);
370392
trigger_error( $message );
@@ -390,7 +412,7 @@ public function description() {
390412
* for the output
391413
*/
392414
public function content_priority() {
393-
$temp = array_merge( range( 1, 10 ), [ 20, 50, 100 ] );
415+
$temp = array_merge( range( 1, 10 ), array( 20, 50, 100 ) );
394416
$arr = array_combine( $temp, $temp );
395417
$selected = empty( $this->options->content_priority ) ? 10 : $this->options->content_priority;
396418

@@ -429,7 +451,6 @@ public function validate( array $arr ) {
429451
* @param array $arr
430452
*
431453
* @since 1.0
432-
*
433454
*/
434455
$arr = (array) apply_filters( 'msls_admin_validate', $arr );
435456

@@ -457,5 +478,4 @@ public function set_blog_language( array $arr ) {
457478

458479
return $arr;
459480
}
460-
461481
}

0 commit comments

Comments
 (0)