Skip to content

Commit 77a2687

Browse files
authored
Merge pull request #366 from lloc/version-2-9-2
Addressed some of the errors that were reported by PHPStan
2 parents 0cbf649 + c833643 commit 77a2687

File tree

2 files changed

+27
-36
lines changed

2 files changed

+27
-36
lines changed

includes/MslsPlugin.php

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static function init() {
4040

4141
add_action( 'plugins_loaded', array( $obj, 'init_i18n_support' ) );
4242

43-
register_activation_hook( self::file(), array( $obj, 'activate' ) );
43+
register_activation_hook( self::file(), array( __CLASS__, 'activate' ) );
4444

4545
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
4646
add_action( 'admin_enqueue_scripts', array( $obj, 'custom_enqueue' ) );
@@ -69,14 +69,16 @@ public static function init() {
6969
add_action( 'load-term.php', array( MslsPostTag::class, 'init' ) );
7070

7171
if ( MslsRequest::has_var( MslsFields::FIELD_ACTION ) ) {
72-
$action = MslsRequest::get_var( MslsFields::FIELD_ACTION );
73-
74-
if ( 'add-tag' === $action ) {
75-
add_action( 'admin_init', array( MslsPostTag::class, 'init' ) );
76-
} elseif ( 'inline-save' === $action ) {
77-
add_action( 'admin_init', array( MslsCustomColumn::class, 'init' ) );
78-
} elseif ( 'inline-save-tax' === $action ) {
79-
add_action( 'admin_init', array( MslsCustomColumnTaxonomy::class, 'init' ) );
72+
switch ( MslsRequest::get_var( MslsFields::FIELD_ACTION ) ) {
73+
case 'add-tag':
74+
add_action( 'admin_init', array( MslsPostTag::class, 'init' ) );
75+
break;
76+
case 'inline-save':
77+
add_action( 'admin_init', array( MslsCustomColumn::class, 'init' ) );
78+
break;
79+
case 'inline-save-tax':
80+
add_action( 'admin_init', array( MslsCustomColumnTaxonomy::class, 'init' ) );
81+
break;
8082
}
8183
}
8284

@@ -120,23 +122,16 @@ public static function get_output() {
120122
return $obj;
121123
}
122124

123-
/**
124-
* Callback for action wp_head
125-
*/
126-
public static function print_alternate_links() {
125+
public static function print_alternate_links(): void {
127126
echo self::get_output()->get_alternate_links(), PHP_EOL;
128127
}
129128

130129
/**
131130
* Loads styles and some js if needed
132-
*
133-
* The method returns true if the autocomplete-option is activated, false otherwise.
134-
*
135-
* @return boolean
136131
*/
137-
public function custom_enqueue() {
132+
public function custom_enqueue(): void {
138133
if ( ! is_admin_bar_showing() ) {
139-
return false;
134+
return;
140135
}
141136

142137
$ver = defined( 'MSLS_PLUGIN_VERSION' ) ? constant( 'MSLS_PLUGIN_VERSION' ) : false;
@@ -147,11 +142,7 @@ public function custom_enqueue() {
147142

148143
if ( $this->options->activate_autocomplete ) {
149144
wp_enqueue_script( 'msls-autocomplete', self::plugins_url( "$folder/msls.js" ), array( 'jquery-ui-autocomplete' ), $ver, array( 'in_footer' => true ) );
150-
151-
return true;
152145
}
153-
154-
return false;
155146
}
156147

157148
/**
@@ -202,13 +193,10 @@ public static function path(): string {
202193
/**
203194
* Load textdomain
204195
*
205-
* The method should be executed always on init because we have some
206-
* translatable string in the frontend too.
207-
*
208-
* @return boolean
196+
* The method should be executed always on init because we have some translatable string in the frontend too.
209197
*/
210-
public function init_i18n_support() {
211-
return load_plugin_textdomain( 'multisite-language-switcher', false, self::dirname( '/languages/' ) );
198+
public function init_i18n_support(): void {
199+
load_plugin_textdomain( 'multisite-language-switcher', false, self::dirname( '/languages/' ) );
212200
}
213201

214202
/**
@@ -234,7 +222,7 @@ public static function message_handler( $message, $css_class = 'error' ) {
234222
/**
235223
* Activate plugin
236224
*/
237-
public static function activate() {
225+
public static function activate(): void {
238226
register_uninstall_hook( self::file(), array( __CLASS__, 'uninstall' ) );
239227
}
240228

tests/phpunit/TestMslsPlugin.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ function test_admin_menu_without_autocomplete(): void {
1818

1919
$test = new MslsPlugin( $options );
2020

21-
$this->assertFalse( $test->custom_enqueue() );
21+
$this->expectNotToPerformAssertions();
22+
$test->custom_enqueue();
2223
}
2324

2425
function test_admin_menu_with_autocomplete(): void {
@@ -33,7 +34,8 @@ function test_admin_menu_with_autocomplete(): void {
3334

3435
$test = new MslsPlugin( $options );
3536

36-
$this->assertTrue( $test->custom_enqueue() );
37+
$this->expectNotToPerformAssertions();
38+
$test->custom_enqueue();
3739
}
3840

3941
function test_admin_menu_admin_bar_not_showing(): void {
@@ -45,21 +47,22 @@ function test_admin_menu_admin_bar_not_showing(): void {
4547

4648
$test = new MslsPlugin( $options );
4749

48-
$this->assertFalse( $test->custom_enqueue() );
50+
$this->expectNotToPerformAssertions();
51+
$test->custom_enqueue();
4952
}
5053

5154
/**
5255
* Verify the static init_i18n_support-method
5356
*/
5457
function test_init_i18n_support(): void {
55-
Functions\when( 'load_plugin_textdomain' )->justReturn( true );
58+
Functions\expect( 'load_plugin_textdomain' )->once()->andReturn( true );
5659

5760
$options = \Mockery::mock( MslsOptions::class );
58-
$options->shouldReceive( 'is_excluded' )->andReturn( false );
5961

6062
$test = new MslsPlugin( $options );
6163

62-
$this->assertIsBool( $test->init_i18n_support() );
64+
$this->expectNotToPerformAssertions();
65+
$test->init_i18n_support();
6366
}
6467

6568
/**

0 commit comments

Comments
 (0)