Skip to content

Commit feae831

Browse files
committed
add type hints to method signatures
1 parent b1e3206 commit feae831

8 files changed

+65
-65
lines changed

inc/class-statifyblacklist-admin.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class StatifyBlacklist_Admin extends StatifyBlacklist {
2626
*
2727
* @since 1.5.0
2828
*/
29-
public static function init() {
29+
public static function init(): void {
3030
// Add actions.
3131
add_action( 'wpmu_new_blog', array( 'StatifyBlacklist_System', 'install_site' ) );
3232
add_action( 'delete_blog', array( 'StatifyBlacklist_System', 'uninstall_site' ) );
@@ -55,7 +55,7 @@ public static function init() {
5555
*
5656
* @since 1.0.0
5757
*/
58-
public static function add_menu_page() {
58+
public static function add_menu_page(): void {
5959
$title = __( 'Statify Filter', 'statify-blacklist' );
6060
if ( self::$multisite ) {
6161
add_options_page(
@@ -86,7 +86,7 @@ public static function add_menu_page() {
8686
*
8787
* @since 1.0.0
8888
*/
89-
public static function plugin_meta_link( $links, $file ) {
89+
public static function plugin_meta_link( array $links, string $file ): array {
9090
if ( STATIFYBLACKLIST_BASE === $file ) {
9191
$links[] = '<a href="https://github.com/stklcode/statify-blacklist">GitHub</a>';
9292
}
@@ -104,7 +104,7 @@ public static function plugin_meta_link( $links, $file ) {
104104
*
105105
* @since 1.0.0
106106
*/
107-
public static function plugin_actions_links( $links, $file ) {
107+
public static function plugin_actions_links( array $links, string $file ): array {
108108
$base = self::$multisite ? network_admin_url( 'settings.php' ) : admin_url( 'options-general.php' );
109109

110110
if ( STATIFYBLACKLIST_BASE === $file && current_user_can( 'manage_options' ) ) {
@@ -124,7 +124,7 @@ public static function plugin_actions_links( $links, $file ) {
124124
*
125125
* @global wpdb $wpdb WordPress database.
126126
*/
127-
public static function cleanup_database() {
127+
public static function cleanup_database(): void {
128128
// Check user permissions.
129129
if ( ! current_user_can( 'manage_options' ) && ! ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
130130
die( esc_html__( 'Are you sure you want to do this?', 'statify-blacklist' ) );
@@ -206,7 +206,7 @@ public static function cleanup_database() {
206206
*
207207
* @since 1.1.1
208208
*/
209-
private static function sanitize_urls( $urls ) {
209+
private static function sanitize_urls( array $urls ): array {
210210
return array_flip(
211211
array_filter(
212212
array_map(

inc/class-statifyblacklist-settings.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class StatifyBlacklist_Settings extends StatifyBlacklist {
2020
*
2121
* @return void
2222
*/
23-
public static function register_settings() {
23+
public static function register_settings(): void {
2424
register_setting(
2525
'statify-blacklist',
2626
'statify-blacklist',
@@ -166,7 +166,7 @@ public static function register_settings() {
166166
*
167167
* @return void
168168
*/
169-
public static function create_settings_page() {
169+
public static function create_settings_page(): void {
170170
?>
171171
<div class="wrap">
172172
<h1><?php esc_html_e( 'Statify Filter', 'statify-blacklist' ); ?></h1>
@@ -225,7 +225,7 @@ public static function create_settings_page() {
225225
*
226226
* @return void
227227
*/
228-
public static function option_referer_active() {
228+
public static function option_referer_active(): void {
229229
?>
230230
<fieldset>
231231
<legend class="screen-reader-text"><?php esc_html_e( 'Activate live filter', 'statify-blacklist' ); ?></legend>
@@ -245,7 +245,7 @@ public static function option_referer_active() {
245245
*
246246
* @return void
247247
*/
248-
public static function option_referer_cron() {
248+
public static function option_referer_cron(): void {
249249
?>
250250
<fieldset>
251251
<legend class="screen-reader-text"><?php esc_html_e( 'CronJob execution', 'statify-blacklist' ); ?></legend>
@@ -265,7 +265,7 @@ public static function option_referer_cron() {
265265
*
266266
* @return void
267267
*/
268-
public static function option_referer_regexp() {
268+
public static function option_referer_regexp(): void {
269269
?>
270270
<select id="statifyblacklist-referer-regexp" name="statify-blacklist[referer][regexp]">
271271
<option value="<?php print esc_attr( StatifyBlacklist::MODE_NORMAL ); ?>" <?php selected( StatifyBlacklist::$options['referer']['regexp'], StatifyBlacklist::MODE_NORMAL ); ?>>
@@ -296,7 +296,7 @@ public static function option_referer_regexp() {
296296
*
297297
* @return void
298298
*/
299-
public static function option_referer_blacklist() {
299+
public static function option_referer_blacklist(): void {
300300
?>
301301
<textarea id="statifyblacklist-referer-blacklist" name="statify-blacklist[referer][blacklist]" cols="40" rows="5"><?php
302302
print esc_html( implode( "\r\n", array_keys( StatifyBlacklist::$options['referer']['blacklist'] ) ) );
@@ -312,7 +312,7 @@ public static function option_referer_blacklist() {
312312
*
313313
* @return void
314314
*/
315-
public static function option_target_active() {
315+
public static function option_target_active(): void {
316316
?>
317317
<fieldset>
318318
<legend class="screen-reader-text"><?php esc_html_e( 'Activate live filter', 'statify-blacklist' ); ?></legend>
@@ -332,7 +332,7 @@ public static function option_target_active() {
332332
*
333333
* @return void
334334
*/
335-
public static function option_target_cron() {
335+
public static function option_target_cron(): void {
336336
?>
337337
<fieldset>
338338
<legend class="screen-reader-text"><?php esc_html_e( 'CronJob execution', 'statify-blacklist' ); ?></legend>
@@ -352,7 +352,7 @@ public static function option_target_cron() {
352352
*
353353
* @return void
354354
*/
355-
public static function option_target_regexp() {
355+
public static function option_target_regexp(): void {
356356
?>
357357
<select id="statifyblacklist-target-regexp" name="statify-blacklist[target][regexp]">
358358
<option value="<?php print esc_attr( StatifyBlacklist::MODE_NORMAL ); ?>" <?php selected( StatifyBlacklist::$options['target']['regexp'], StatifyBlacklist::MODE_NORMAL ); ?>>
@@ -378,7 +378,7 @@ public static function option_target_regexp() {
378378
*
379379
* @return void
380380
*/
381-
public static function option_target_blacklist() {
381+
public static function option_target_blacklist(): void {
382382
?>
383383
<textarea id="statifyblacklist-target-blacklist" name="statify-blacklist[target][blacklist]" cols="40" rows="5"><?php
384384
print esc_html( implode( "\r\n", array_keys( StatifyBlacklist::$options['target']['blacklist'] ) ) );
@@ -394,7 +394,7 @@ public static function option_target_blacklist() {
394394
*
395395
* @return void
396396
*/
397-
public static function option_ip_active() {
397+
public static function option_ip_active(): void {
398398
?>
399399
<fieldset>
400400
<legend class="screen-reader-text"><?php esc_html_e( 'Activate live filter', 'statify-blacklist' ); ?></legend>
@@ -416,7 +416,7 @@ public static function option_ip_active() {
416416
*
417417
* @return void
418418
*/
419-
public static function option_ip_blacklist() {
419+
public static function option_ip_blacklist(): void {
420420
?>
421421
<textarea id="statifyblacklist-ip-blacklist" name="statify-blacklist[ip][blacklist]" cols="40" rows="5"><?php
422422
print esc_html( implode( "\r\n", StatifyBlacklist::$options['ip']['blacklist'] ) );
@@ -433,7 +433,7 @@ public static function option_ip_blacklist() {
433433
*
434434
* @return void
435435
*/
436-
public static function option_ua_active() {
436+
public static function option_ua_active(): void {
437437
?>
438438
<label for="statifyblacklist-ua-active">
439439
<input id="statifyblacklist-ua-active" name="statify-blacklist[ua][active]" type="checkbox" value="1" <?php checked( StatifyBlacklist::$options['ua']['active'], 1 ); ?>>
@@ -453,7 +453,7 @@ public static function option_ua_active() {
453453
*
454454
* @return void
455455
*/
456-
public static function option_ua_regexp() {
456+
public static function option_ua_regexp(): void {
457457
?>
458458
<select id="statifyblacklist-ua-regexp" name="statify-blacklist[ua][regexp]">
459459
<option value="<?php print esc_attr( StatifyBlacklist::MODE_NORMAL ); ?>" <?php selected( StatifyBlacklist::$options['ua']['regexp'], StatifyBlacklist::MODE_NORMAL ); ?>>
@@ -484,7 +484,7 @@ public static function option_ua_regexp() {
484484
*
485485
* @return void
486486
*/
487-
public static function option_ua_blacklist() {
487+
public static function option_ua_blacklist(): void {
488488
?>
489489
<textarea name="statify-blacklist[ua][blacklist]" id="statifyblacklist-ua-blacklist" cols="40" rows="5"><?php
490490
print esc_html( implode( "\r\n", StatifyBlacklist::$options['ua']['blacklist'] ) );
@@ -503,7 +503,7 @@ public static function option_ua_blacklist() {
503503
*
504504
* @return array Validated and sanitized options.
505505
*/
506-
public static function sanitize_options( $options ) {
506+
public static function sanitize_options( array $options ): array {
507507
// Extract filter lists from multi-line inputs.
508508
$referer = self::parse_multiline_option( $options['referer']['blacklist'] );
509509
$target = self::parse_multiline_option( $options['target']['blacklist'] );
@@ -553,7 +553,7 @@ public static function sanitize_options( $options ) {
553553
*
554554
* @since 1.7.0
555555
*/
556-
private static function sanitize_referer_options( &$options ) {
556+
private static function sanitize_referer_options( array &$options ): void {
557557
$referer_given = $options['blacklist'];
558558
$referer_invalid = array();
559559
if ( StatifyBlacklist::MODE_NORMAL === $options['regexp'] ) {
@@ -596,7 +596,7 @@ private static function sanitize_referer_options( &$options ) {
596596
*
597597
* @since 1.7.0
598598
*/
599-
private static function sanitize_target_options( &$options ) {
599+
private static function sanitize_target_options( array &$options ): void {
600600
$target_given = $options['blacklist'];
601601
$target_sanitized = $target_given;
602602
if ( StatifyBlacklist::MODE_REGEX === $options['regexp'] || StatifyBlacklist::MODE_REGEX_CI === $options['regexp'] ) {
@@ -626,7 +626,7 @@ private static function sanitize_target_options( &$options ) {
626626
*
627627
* @since 1.7.0
628628
*/
629-
private static function sanitize_ip_options( &$options ) {
629+
private static function sanitize_ip_options( array &$options ): void {
630630
$given_ip = $options['blacklist'];
631631
$sanitized_ip = self::sanitize_ips( $given_ip );
632632
$ip_diff = array_diff( $given_ip, $sanitized_ip );
@@ -654,7 +654,7 @@ private static function sanitize_ip_options( &$options ) {
654654
* @since 1.1.1
655655
* @since 1.7.0 moved from StatifyBlacklist_Admin to StatifyBlacklist_Settings.
656656
*/
657-
private static function sanitize_urls( $urls ) {
657+
private static function sanitize_urls( array $urls ): array {
658658
return array_flip(
659659
array_filter(
660660
array_map(
@@ -677,7 +677,7 @@ function ( $r ) {
677677
* @since 1.4.0
678678
* @since 1.7.0 moved from StatifyBlacklist_Admin to StatifyBlacklist_Settings.
679679
*/
680-
private static function sanitize_ips( $ips ) {
680+
private static function sanitize_ips( array $ips ): array {
681681
return array_values(
682682
array_unique(
683683
array_filter(
@@ -713,7 +713,7 @@ function ( $ip ) {
713713
* @since 1.5.0 #13
714714
* @since 1.7.0 moved from StatifyBlacklist_Admin to StatifyBlacklist_Settings.
715715
*/
716-
private static function sanitize_regex( $expressions ) {
716+
private static function sanitize_regex( array $expressions ): array {
717717
return array_filter(
718718
array_flip( $expressions ),
719719
function ( $re ) {
@@ -732,7 +732,7 @@ function ( $re ) {
732732
*
733733
* @return array Parsed options.
734734
*/
735-
private static function parse_multiline_option( $raw ) {
735+
private static function parse_multiline_option( string $raw ): array {
736736
if ( empty( trim( $raw ) ) ) {
737737
return array();
738738
} else {

inc/class-statifyblacklist-system.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class StatifyBlacklist_System extends StatifyBlacklist {
3030
*
3131
* @return void
3232
*/
33-
public static function install( $network_wide = false ) {
33+
public static function install( bool $network_wide = false ): void {
3434
// Create tables for each site in a network.
3535
if ( $network_wide && is_multisite() ) {
3636
if ( function_exists( 'get_sites' ) ) {
@@ -66,8 +66,8 @@ public static function install( $network_wide = false ) {
6666
*
6767
* @return void
6868
*/
69-
public static function install_site( $site_id ) {
70-
switch_to_blog( (int) $site_id );
69+
public static function install_site( int $site_id ): void {
70+
switch_to_blog( $site_id );
7171
add_option(
7272
'statify-blacklist',
7373
self::default_options()
@@ -83,7 +83,7 @@ public static function install_site( $site_id ) {
8383
*
8484
* @return void
8585
*/
86-
public static function uninstall() {
86+
public static function uninstall(): void {
8787
if ( is_multisite() ) {
8888
$old = get_current_blog_id();
8989

@@ -117,9 +117,9 @@ public static function uninstall() {
117117
*
118118
* @return void
119119
*/
120-
public static function uninstall_site( $site_id ) {
120+
public static function uninstall_site( int $site_id ): void {
121121
$old = get_current_blog_id();
122-
switch_to_blog( (int) $site_id );
122+
switch_to_blog( $site_id );
123123
delete_option( 'statify-blacklist' );
124124
switch_to_blog( $old );
125125
}
@@ -131,7 +131,7 @@ public static function uninstall_site( $site_id ) {
131131
*
132132
* @return void
133133
*/
134-
public static function upgrade() {
134+
public static function upgrade(): void {
135135
self::update_options();
136136
// Check if config array is not associative (pre 1.2.0).
137137
if ( array_keys( self::$options['referer'] ) === range( 0, count( self::$options['referer'] ) - 1 ) ) {

0 commit comments

Comments
 (0)