Skip to content

Commit

Permalink
add type hints to method signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
stklcode committed Apr 26, 2024
1 parent e114362 commit 265e1c6
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 64 deletions.
12 changes: 6 additions & 6 deletions inc/class-statifyblacklist-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class StatifyBlacklist_Admin extends StatifyBlacklist {
*
* @since 1.5.0
*/
public static function init() {
public static function init(): void {
// Add actions.
add_action( 'wpmu_new_blog', array( 'StatifyBlacklist_System', 'install_site' ) );
add_action( 'delete_blog', array( 'StatifyBlacklist_System', 'uninstall_site' ) );
Expand Down Expand Up @@ -55,7 +55,7 @@ public static function init() {
*
* @since 1.0.0
*/
public static function add_menu_page() {
public static function add_menu_page(): void {
$title = __( 'Statify Filter', 'statify-blacklist' );
if ( self::$multisite ) {
add_options_page(
Expand Down Expand Up @@ -86,7 +86,7 @@ public static function add_menu_page() {
*
* @since 1.0.0
*/
public static function plugin_meta_link( $links, $file ) {
public static function plugin_meta_link( array $links, string $file ): array {
if ( STATIFYBLACKLIST_BASE === $file ) {
$links[] = '<a href="https://github.com/stklcode/statify-blacklist">GitHub</a>';
}
Expand All @@ -104,7 +104,7 @@ public static function plugin_meta_link( $links, $file ) {
*
* @since 1.0.0
*/
public static function plugin_actions_links( $links, $file ) {
public static function plugin_actions_links( array $links, string $file ): array {
$base = self::$multisite ? network_admin_url( 'settings.php' ) : admin_url( 'options-general.php' );

if ( STATIFYBLACKLIST_BASE === $file && current_user_can( 'manage_options' ) ) {
Expand All @@ -124,7 +124,7 @@ public static function plugin_actions_links( $links, $file ) {
*
* @global wpdb $wpdb WordPress database.
*/
public static function cleanup_database() {
public static function cleanup_database(): void {
// Check user permissions.
if ( ! current_user_can( 'manage_options' ) && ! ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
die( esc_html__( 'Are you sure you want to do this?', 'statify-blacklist' ) );
Expand Down Expand Up @@ -206,7 +206,7 @@ public static function cleanup_database() {
*
* @since 1.1.1
*/
private static function sanitize_urls( $urls ) {
private static function sanitize_urls( array $urls ): array {
return array_flip(
array_filter(
array_map(
Expand Down
46 changes: 23 additions & 23 deletions inc/class-statifyblacklist-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class StatifyBlacklist_Settings extends StatifyBlacklist {
*
* @return void
*/
public static function register_settings() {
public static function register_settings(): void {
register_setting(
'statify-blacklist',
'statify-blacklist',
Expand Down Expand Up @@ -166,7 +166,7 @@ public static function register_settings() {
*
* @return void
*/
public static function create_settings_page() {
public static function create_settings_page(): void {
?>
<div class="wrap">
<h1><?php esc_html_e( 'Statify Filter', 'statify-blacklist' ); ?></h1>
Expand Down Expand Up @@ -225,7 +225,7 @@ public static function create_settings_page() {
*
* @return void
*/
public static function option_referer_active() {
public static function option_referer_active(): void {
?>
<fieldset>
<legend class="screen-reader-text"><?php esc_html_e( 'Activate live filter', 'statify-blacklist' ); ?></legend>
Expand All @@ -245,7 +245,7 @@ public static function option_referer_active() {
*
* @return void
*/
public static function option_referer_cron() {
public static function option_referer_cron(): void {
?>
<fieldset>
<legend class="screen-reader-text"><?php esc_html_e( 'CronJob execution', 'statify-blacklist' ); ?></legend>
Expand All @@ -265,7 +265,7 @@ public static function option_referer_cron() {
*
* @return void
*/
public static function option_referer_regexp() {
public static function option_referer_regexp(): void {
?>
<select id="statifyblacklist-referer-regexp" name="statify-blacklist[referer][regexp]">
<option value="<?php print esc_attr( StatifyBlacklist::MODE_NORMAL ); ?>" <?php selected( StatifyBlacklist::$options['referer']['regexp'], StatifyBlacklist::MODE_NORMAL ); ?>>
Expand Down Expand Up @@ -296,7 +296,7 @@ public static function option_referer_regexp() {
*
* @return void
*/
public static function option_referer_blacklist() {
public static function option_referer_blacklist(): void {
?>
<textarea id="statifyblacklist-referer-blacklist" name="statify-blacklist[referer][blacklist]" cols="40" rows="5"><?php
print esc_html( implode( "\r\n", array_keys( StatifyBlacklist::$options['referer']['blacklist'] ) ) );
Expand All @@ -312,7 +312,7 @@ public static function option_referer_blacklist() {
*
* @return void
*/
public static function option_target_active() {
public static function option_target_active(): void {
?>
<fieldset>
<legend class="screen-reader-text"><?php esc_html_e( 'Activate live filter', 'statify-blacklist' ); ?></legend>
Expand All @@ -332,7 +332,7 @@ public static function option_target_active() {
*
* @return void
*/
public static function option_target_cron() {
public static function option_target_cron(): void {
?>
<fieldset>
<legend class="screen-reader-text"><?php esc_html_e( 'CronJob execution', 'statify-blacklist' ); ?></legend>
Expand All @@ -352,7 +352,7 @@ public static function option_target_cron() {
*
* @return void
*/
public static function option_target_regexp() {
public static function option_target_regexp(): void {
?>
<select id="statifyblacklist-target-regexp" name="statify-blacklist[target][regexp]">
<option value="<?php print esc_attr( StatifyBlacklist::MODE_NORMAL ); ?>" <?php selected( StatifyBlacklist::$options['target']['regexp'], StatifyBlacklist::MODE_NORMAL ); ?>>
Expand All @@ -378,7 +378,7 @@ public static function option_target_regexp() {
*
* @return void
*/
public static function option_target_blacklist() {
public static function option_target_blacklist(): void {
?>
<textarea id="statifyblacklist-target-blacklist" name="statify-blacklist[target][blacklist]" cols="40" rows="5"><?php
print esc_html( implode( "\r\n", array_keys( StatifyBlacklist::$options['target']['blacklist'] ) ) );
Expand All @@ -394,7 +394,7 @@ public static function option_target_blacklist() {
*
* @return void
*/
public static function option_ip_active() {
public static function option_ip_active(): void {
?>
<fieldset>
<legend class="screen-reader-text"><?php esc_html_e( 'Activate live filter', 'statify-blacklist' ); ?></legend>
Expand All @@ -416,7 +416,7 @@ public static function option_ip_active() {
*
* @return void
*/
public static function option_ip_blacklist() {
public static function option_ip_blacklist(): void {
?>
<textarea id="statifyblacklist-ip-blacklist" name="statify-blacklist[ip][blacklist]" cols="40" rows="5"><?php
print esc_html( implode( "\r\n", StatifyBlacklist::$options['ip']['blacklist'] ) );
Expand All @@ -433,7 +433,7 @@ public static function option_ip_blacklist() {
*
* @return void
*/
public static function option_ua_active() {
public static function option_ua_active(): void {
?>
<label for="statifyblacklist-ua-active">
<input id="statifyblacklist-ua-active" name="statify-blacklist[ua][active]" type="checkbox" value="1" <?php checked( StatifyBlacklist::$options['ua']['active'], 1 ); ?>>
Expand All @@ -453,7 +453,7 @@ public static function option_ua_active() {
*
* @return void
*/
public static function option_ua_regexp() {
public static function option_ua_regexp(): void {
?>
<select id="statifyblacklist-ua-regexp" name="statify-blacklist[ua][regexp]">
<option value="<?php print esc_attr( StatifyBlacklist::MODE_NORMAL ); ?>" <?php selected( StatifyBlacklist::$options['ua']['regexp'], StatifyBlacklist::MODE_NORMAL ); ?>>
Expand Down Expand Up @@ -484,7 +484,7 @@ public static function option_ua_regexp() {
*
* @return void
*/
public static function option_ua_blacklist() {
public static function option_ua_blacklist(): void {
?>
<textarea name="statify-blacklist[ua][blacklist]" id="statifyblacklist-ua-blacklist" cols="40" rows="5"><?php
print esc_html( implode( "\r\n", StatifyBlacklist::$options['ua']['blacklist'] ) );
Expand All @@ -503,7 +503,7 @@ public static function option_ua_blacklist() {
*
* @return array Validated and sanitized options.
*/
public static function sanitize_options( $options ) {
public static function sanitize_options( array $options ): array {
// Extract filter lists from multi-line inputs.
$referer = self::parse_multiline_option( $options['referer']['blacklist'] );
$target = self::parse_multiline_option( $options['target']['blacklist'] );
Expand Down Expand Up @@ -553,7 +553,7 @@ public static function sanitize_options( $options ) {
*
* @since 1.7.0
*/
private static function sanitize_referer_options( &$options ) {
private static function sanitize_referer_options( array &$options ): void {
$referer_given = $options['blacklist'];
$referer_invalid = array();
if ( StatifyBlacklist::MODE_NORMAL === $options['regexp'] ) {
Expand Down Expand Up @@ -596,7 +596,7 @@ private static function sanitize_referer_options( &$options ) {
*
* @since 1.7.0
*/
private static function sanitize_target_options( &$options ) {
private static function sanitize_target_options( array &$options ): void {
$target_given = $options['blacklist'];
$target_sanitized = $target_given;
if ( StatifyBlacklist::MODE_REGEX === $options['regexp'] || StatifyBlacklist::MODE_REGEX_CI === $options['regexp'] ) {
Expand Down Expand Up @@ -626,7 +626,7 @@ private static function sanitize_target_options( &$options ) {
*
* @since 1.7.0
*/
private static function sanitize_ip_options( &$options ) {
private static function sanitize_ip_options( array &$options ): void {
$given_ip = $options['blacklist'];
$sanitized_ip = self::sanitize_ips( $given_ip );
$ip_diff = array_diff( $given_ip, $sanitized_ip );
Expand Down Expand Up @@ -654,7 +654,7 @@ private static function sanitize_ip_options( &$options ) {
* @since 1.1.1
* @since 1.7.0 moved from StatifyBlacklist_Admin to StatifyBlacklist_Settings.
*/
private static function sanitize_urls( $urls ) {
private static function sanitize_urls( array $urls ): array {
return array_flip(
array_filter(
array_map(
Expand All @@ -677,7 +677,7 @@ function ( $r ) {
* @since 1.4.0
* @since 1.7.0 moved from StatifyBlacklist_Admin to StatifyBlacklist_Settings.
*/
private static function sanitize_ips( $ips ) {
private static function sanitize_ips( array $ips ): array {
return array_values(
array_unique(
array_filter(
Expand Down Expand Up @@ -713,7 +713,7 @@ function ( $ip ) {
* @since 1.5.0 #13
* @since 1.7.0 moved from StatifyBlacklist_Admin to StatifyBlacklist_Settings.
*/
private static function sanitize_regex( $expressions ) {
private static function sanitize_regex( array $expressions ): array {
return array_filter(
array_flip( $expressions ),
function ( $re ) {
Expand All @@ -732,7 +732,7 @@ function ( $re ) {
*
* @return array Parsed options.
*/
private static function parse_multiline_option( $raw ) {
private static function parse_multiline_option( string $raw ): array {
if ( empty( trim( $raw ) ) ) {
return array();
} else {
Expand Down
14 changes: 7 additions & 7 deletions inc/class-statifyblacklist-system.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class StatifyBlacklist_System extends StatifyBlacklist {
*
* @return void
*/
public static function install( $network_wide = false ) {
public static function install( bool $network_wide = false ): void {
// Create tables for each site in a network.
if ( $network_wide && is_multisite() ) {
if ( function_exists( 'get_sites' ) ) {
Expand Down Expand Up @@ -66,8 +66,8 @@ public static function install( $network_wide = false ) {
*
* @return void
*/
public static function install_site( $site_id ) {
switch_to_blog( (int) $site_id );
public static function install_site( int $site_id ): void {
switch_to_blog( $site_id );
add_option(
'statify-blacklist',
self::default_options()
Expand All @@ -83,7 +83,7 @@ public static function install_site( $site_id ) {
*
* @return void
*/
public static function uninstall() {
public static function uninstall(): void {
if ( is_multisite() ) {
$old = get_current_blog_id();

Expand Down Expand Up @@ -117,9 +117,9 @@ public static function uninstall() {
*
* @return void
*/
public static function uninstall_site( $site_id ) {
public static function uninstall_site( int $site_id ): void {
$old = get_current_blog_id();
switch_to_blog( (int) $site_id );
switch_to_blog( $site_id );
delete_option( 'statify-blacklist' );
switch_to_blog( $old );
}
Expand All @@ -131,7 +131,7 @@ public static function uninstall_site( $site_id ) {
*
* @return void
*/
public static function upgrade() {
public static function upgrade(): void {
self::update_options();
// Check if config array is not associative (pre 1.2.0).
if ( array_keys( self::$options['referer'] ) === range( 0, count( self::$options['referer'] ) - 1 ) ) {
Expand Down
Loading

0 comments on commit 265e1c6

Please sign in to comment.