Skip to content

Commit

Permalink
refactor: add type hints to interfaces and base classes
Browse files Browse the repository at this point in the history
  • Loading branch information
stklcode committed Mar 18, 2024
1 parent 260756e commit 1c9219c
Show file tree
Hide file tree
Showing 32 changed files with 95 additions and 95 deletions.
14 changes: 7 additions & 7 deletions src/GeneralOptions/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ abstract class Base implements Controllable {
*
* @return string
*/
public static function get_slug() {
public static function get_slug(): string {
return static::$slug;
}

Expand Down Expand Up @@ -75,7 +75,7 @@ public static function init() {
* @return array Updated options.
* @since 3.0.0
*/
public static function add_general_option( $options ) {
public static function add_general_option( array $options ): array {
$options[] = static::class;

return $options;
Expand All @@ -88,7 +88,7 @@ public static function add_general_option( $options ) {
*
* @return mixed|null
*/
public static function is_active( $type = 'general' ) {
public static function is_active( string $type = 'general' ) {
return Settings::get_option( static::get_option_name( 'active' ), $type );
}

Expand All @@ -98,7 +98,7 @@ public static function is_active( $type = 'general' ) {
*
* @return bool
*/
public static function only_print_custom_options() {
public static function only_print_custom_options(): bool {
return static::$only_custom_options;
}

Expand All @@ -107,7 +107,7 @@ public static function only_print_custom_options() {
*
* @return string[]
*/
public static function get_supported_types() {
public static function get_supported_types(): array {
return [ 'general' ];
}

Expand All @@ -116,7 +116,7 @@ public static function get_supported_types() {
*
* @return string
*/
public static function get_type() {
public static function get_type(): string {
return static::$type;
}

Expand All @@ -127,7 +127,7 @@ public static function get_type() {
* @param string $name Name suffix.
* @return string Corresponding option name
*/
public static function get_option_name( $name ) {
public static function get_option_name( string $name ): string {
$type = static::get_type();
$slug = static::get_slug();
$option_name = "{$type}_{$slug}_{$name}";
Expand Down
4 changes: 2 additions & 2 deletions src/GeneralOptions/DeleteOldSpam.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DeleteOldSpam extends Base {
*
* @return string
*/
public static function get_name() {
public static function get_name(): string {
return __( 'Delete old spam', 'antispam-bee' );
}

Expand Down Expand Up @@ -56,7 +56,7 @@ public static function get_description() {
*
* @return array
*/
public static function get_options() {
public static function get_options(): array {
return [
[
'type' => 'inline',
Expand Down
2 changes: 1 addition & 1 deletion src/GeneralOptions/IgnoreLinkbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class IgnoreLinkbacks extends Base {
*
* @return string
*/
public static function get_name() {
public static function get_name(): string {
return __( 'Linkbacks', 'antispam-bee' );
}

Expand Down
2 changes: 1 addition & 1 deletion src/GeneralOptions/Statistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Statistics extends Base {
*
* @return string
*/
public static function get_name() {
public static function get_name(): string {
return __( 'Statistics', 'antispam-bee' );
}

Expand Down
2 changes: 1 addition & 1 deletion src/GeneralOptions/Uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Uninstall extends Base {
*
* @return string
*/
public static function get_name() {
public static function get_name(): string {
return __( 'Uninstall', 'antispam-bee' );
}

Expand Down
16 changes: 8 additions & 8 deletions src/Interfaces/Controllable.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface Controllable {
*
* @return string
*/
public static function get_name();
public static function get_name(): string;

/**
* Get element label (optional).
Expand Down Expand Up @@ -54,7 +54,7 @@ public static function get_description();
* ]
* ]
*
* @return mixed
* @return array|null
*/
public static function get_options();

Expand All @@ -66,36 +66,36 @@ public static function get_options();
*
* @return mixed|null
*/
public static function is_active( $type );
public static function is_active( string $type );

/**
* Only print custom options?
* If enabled, the default options will not be generated.
*
* @return bool
*/
public static function only_print_custom_options();
public static function only_print_custom_options(): bool;

/**
* Get a list of supported types.
*
* @return string[]
*/
public static function get_supported_types();
public static function get_supported_types(): array;

/**
* Get type of the controllable.
*
* @return string
*/
public static function get_type();
public static function get_type(): string;

/**
* Get controllable slug.
*
* @return string
*/
public static function get_slug();
public static function get_slug(): string;

/**
* Get option name.
Expand All @@ -104,5 +104,5 @@ public static function get_slug();
* @param string $name Name suffix.
* @return string Corresponding option name
*/
public static function get_option_name( $name );
public static function get_option_name( string $name ): string;
}
8 changes: 4 additions & 4 deletions src/Interfaces/PostProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@ interface PostProcessor {
* @param array $item Item to process.
* @return array Processed item.
*/
public static function process( $item );
public static function process( array $item ): array;

/**
* Get post processor slug.
*
* @return string The slug.
*/
public static function get_slug();
public static function get_slug(): string;

/**
* Get a list of supported types.
*
* @return string[]
*/
public static function get_supported_types();
public static function get_supported_types(): array;

/**
* Does this processor mark am element as deleted?
*
* @return bool
*/
public static function marks_as_delete();
public static function marks_as_delete(): bool;
}
2 changes: 1 addition & 1 deletion src/Interfaces/SpamReason.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ interface SpamReason {
*
* @return string
*/
public static function get_reason_text();
public static function get_reason_text(): string;
}
10 changes: 5 additions & 5 deletions src/Interfaces/Verifiable.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,34 @@ interface Verifiable {
* @param array $item Item to verify.
* @return int Weighted result.
*/
public static function verify( $item );
public static function verify( array $item ): int;

/**
* Get rule weight.
* This value can be used to tweak the overall results. Will be user as a multiplier of the verification result.
*
* @return int Weight factor.
*/
public static function get_weight();
public static function get_weight(): int;

/**
* Get element slug.
*
* @return string The slug.
*/
public static function get_slug();
public static function get_slug(): string;

/**
* Get a list of supported types.
*
* @return string[]
*/
public static function get_supported_types();
public static function get_supported_types(): array;

/**
* It this rule final?
*
* @return bool
*/
public static function is_final();
public static function is_final(): bool;
}
8 changes: 4 additions & 4 deletions src/PostProcessors/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static function init() {
*
* @return PostProcessor[] Updated list of post processors.
*/
public static function add_post_processor( $post_processors ) {
public static function add_post_processor( array $post_processors ): array {
$post_processors[] = static::class;

return $post_processors;
Expand All @@ -63,7 +63,7 @@ public static function add_post_processor( $post_processors ) {
*
* @return string The slug.
*/
public static function get_slug() {
public static function get_slug(): string {
return static::$slug;
}

Expand All @@ -72,7 +72,7 @@ public static function get_slug() {
*
* @return string[]
*/
public static function get_supported_types() {
public static function get_supported_types(): array {
// @todo: add filter
return static::$supported_types;
}
Expand All @@ -82,7 +82,7 @@ public static function get_supported_types() {
*
* @return bool
*/
public static function marks_as_delete() {
public static function marks_as_delete(): bool {
return static::$marks_as_delete;
}
}
8 changes: 4 additions & 4 deletions src/PostProcessors/ControllableBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ abstract class ControllableBase extends Base implements Controllable {
*
* @return mixed|null
*/
public static function is_active( $type ) {
public static function is_active( string $type ) {
return Settings::get_option( static::get_option_name( 'active' ), $type );
}

Expand All @@ -56,7 +56,7 @@ public static function get_options() {
*
* @return bool
*/
public static function only_print_custom_options() {
public static function only_print_custom_options(): bool {
return static::$only_print_custom_options;
}

Expand All @@ -65,7 +65,7 @@ public static function only_print_custom_options() {
*
* @return string
*/
public static function get_type() {
public static function get_type(): string {
return static::$type;
}

Expand All @@ -76,7 +76,7 @@ public static function get_type() {
* @param string $name Name suffix.
* @return string Corresponding option name
*/
public static function get_option_name( $name ) {
public static function get_option_name( string $name ): string {
$type = static::get_type();
$slug = static::get_slug();
$option_name = "{$type}_{$slug}_{$name}";
Expand Down
4 changes: 2 additions & 2 deletions src/PostProcessors/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Delete extends ControllableBase {
* @param array $item Item to process.
* @return array Processed item.
*/
public static function process( $item ) {
public static function process( array $item ): array {
$item['asb_marked_as_delete'] = true;

return $item;
Expand All @@ -43,7 +43,7 @@ public static function process( $item ) {
*
* @return string
*/
public static function get_name() {
public static function get_name(): string {
return __( 'Delete spam', 'antispam-bee' );
}

Expand Down
4 changes: 2 additions & 2 deletions src/PostProcessors/DeleteForReasons.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class DeleteForReasons extends ControllableBase {
* @param array $item Item to process.
* @return array Processed item.
*/
public static function process( $item ) {
public static function process( array $item ): array {
if ( isset( $item['asb_marked_as_delete'] ) && true === $item['asb_marked_as_delete'] ) {
return $item;
}
Expand All @@ -58,7 +58,7 @@ public static function process( $item ) {
*
* @return string
*/
public static function get_name() {
public static function get_name(): string {
return __( 'Delete by reasons', 'antispam-bee' );
}

Expand Down
4 changes: 2 additions & 2 deletions src/PostProcessors/SaveReason.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SaveReason extends ControllableBase {
* @param array $item Item to process.
* @return array Processed item.
*/
public static function process( $item ) {
public static function process( array $item ): array {
if ( isset( $item['asb_marked_as_delete'] ) && true === $item['asb_marked_as_delete'] ) {
return $item;
}
Expand Down Expand Up @@ -55,7 +55,7 @@ function ( $comment_id ) use ( $item ) {
*
* @return string
*/
public static function get_name() {
public static function get_name(): string {
return __( 'Save reasons', 'antispam-bee' );
}

Expand Down
4 changes: 2 additions & 2 deletions src/PostProcessors/SendEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SendEmail extends ControllableBase {
* @param array $item Item to process.
* @return array Processed item.
*/
public static function process( $item ) {
public static function process( array $item ): array {
if ( isset( $item['asb_marked_as_delete'] ) && true === $item['asb_marked_as_delete'] ) {
return $item;
}
Expand Down Expand Up @@ -85,7 +85,7 @@ function ( $id ) use ( $item ) {
*
* @return string
*/
public static function get_name() {
public static function get_name(): string {
return __( 'Send email', 'antispam-bee' );
}

Expand Down
Loading

0 comments on commit 1c9219c

Please sign in to comment.