Skip to content

Commit

Permalink
Fix add_filter type hints in all files.
Browse files Browse the repository at this point in the history
  • Loading branch information
kagg-design committed Jul 27, 2023
1 parent 19e4d80 commit 899aa44
Show file tree
Hide file tree
Showing 34 changed files with 244 additions and 209 deletions.
24 changes: 12 additions & 12 deletions src/php/ACFE/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,16 @@ public function add_hcaptcha( array $field ) {
/**
* Remove reCaptcha verify filter.
*
* @param bool $valid Whether field is valid.
* @param string $value Field Value.
* @param array $field Field.
* @param string $input Input name.
* @param bool|mixed $valid Whether field is valid.
* @param string $value Field Value.
* @param array $field Field.
* @param string $input Input name.
*
* @return bool
* @return bool|mixed
* @noinspection PhpUnusedParameterInspection
* @noinspection PhpUndefinedFunctionInspection
*/
public function remove_recaptcha_verify( bool $valid, string $value, array $field, string $input ): bool {
public function remove_recaptcha_verify( $valid, string $value, array $field, string $input ) {
$recaptcha = acf_get_field_type( 'acfe_recaptcha' );

remove_filter( self::VALIDATION_HOOK, [ $recaptcha, 'validate_value' ] );
Expand All @@ -133,15 +133,15 @@ public function remove_recaptcha_verify( bool $valid, string $value, array $fiel
/**
* Verify request.
*
* @param bool $valid Whether field is valid.
* @param string $value Field Value.
* @param array $field Field.
* @param string $input Input name.
* @param bool|mixed $valid Whether field is valid.
* @param string $value Field Value.
* @param array $field Field.
* @param string $input Input name.
*
* @return bool
* @return bool|mixed
* @noinspection PhpUnusedParameterInspection
*/
public function verify( bool $valid, string $value, array $field, string $input ): bool {
public function verify( $valid, string $value, array $field, string $input ) {
if ( ! $field['required'] ) {
return $valid;
}
Expand Down
13 changes: 7 additions & 6 deletions src/php/Asgaros/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ private function init_hooks() {
/**
* Add captcha to the new topic form.
*
* @param string $output Shortcode output.
* @param string|mixed $output Shortcode output.
* @param string $tag Shortcode name.
* @param array|string $attr Shortcode attributes array or empty string.
* @param array $m Regular expression match array.
*
* @return string|mixed
* @noinspection PhpUnusedParameterInspection
* @noinspection RegExpUnnecessaryNonCapturingGroup
*/
public function add_captcha( string $output, string $tag, $attr, array $m ) {
public function add_captcha( $output, string $tag, $attr, array $m ) {
if ( 'forum' !== $tag ) {
return $output;
}
Expand All @@ -66,18 +67,18 @@ public function add_captcha( string $output, string $tag, $attr, array $m ) {
'</div>' .
'</div>' .
$search,
$output
(string) $output
);
}

/**
* Verify new topic captcha.
*
* @param bool $verified Verified.
* @param bool|mixed $verified Verified.
*
* @return bool
* @return bool|mixed
*/
public function verify( bool $verified ): bool {
public function verify( $verified ) {
global $asgarosforum;

$error_message = hcaptcha_get_verify_message(
Expand Down
6 changes: 3 additions & 3 deletions src/php/AutoVerify/AutoVerify.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ private function init_hooks() {
/**
* Filter page content and register the form for auto verification.
*
* @param string $content Content.
* @param string|mixed $content Content.
*
* @return string
* @return string|mixed
*/
public function content_filter( string $content ): string {
public function content_filter( $content ) {
if ( ! $this->is_frontend() ) {
return $content;
}
Expand Down
6 changes: 3 additions & 3 deletions src/php/Avada/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ public function add_hcaptcha( string $html, array $args ): string {
/**
* Verify request.
*
* @param bool $demo_mode Demo mode.
* @param bool|mixed $demo_mode Demo mode.
*
* @return bool|void
* @return bool|mixed|void
*/
public function verify( bool $demo_mode ) {
public function verify( $demo_mode ) {

// Nonce is checked by Avada.
// phpcs:disable WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Missing
Expand Down
11 changes: 5 additions & 6 deletions src/php/BeaverBuilder/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,19 @@ public function init_hooks() {
/**
* Filters the Beaver Builder Contact Form submit button html and adds hcaptcha.
*
* @param string $out Button html.
* @param string|mixed $out Button html.
* @param FLButtonModule $module Button module.
*
* @return string
* @return string|mixed
* @noinspection PhpUnusedParameterInspection
*/
public function add_hcaptcha( string $out, FLButtonModule $module ): string {

public function add_hcaptcha( $out, FLButtonModule $module ) {
// Process contact form only.
if ( false === strpos( $out, '<form class="fl-contact-form"' ) ) {
if ( false === strpos( (string) $out, '<form class="fl-contact-form"' ) ) {
return $out;
}

return $this->add_hcap_form( $out, $module );
return $this->add_hcap_form( (string) $out, $module );
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/php/BeaverBuilder/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,27 @@ protected function init_hooks() {
/**
* Filters the Beaver Builder Login Form submit button html and adds hcaptcha.
*
* @param string $out Button html.
* @param string|mixed $out Button html.
* @param FLButtonModule $module Button module.
*
* @return string
* @return string|mixed
*/
public function add_hcaptcha( string $out, FLButtonModule $module ): string {
public function add_hcaptcha( $out, FLButtonModule $module ) {
if ( ! $this->is_login_limit_exceeded() ) {
return $out;
}

// Process login form only.
if ( false === strpos( $out, '<div class="fl-login-form' ) ) {
if ( false === strpos( (string) $out, '<div class="fl-login-form' ) ) {
return $out;
}

// Do not show hCaptcha on logout form.
if ( preg_match( '/<div class="fl-login-form.+?logout.*?>/', $out ) ) {
if ( preg_match( '/<div class="fl-login-form.+?logout.*?>/', (string) $out ) ) {
return $out;
}

return $this->add_hcap_form( $out, $module );
return $this->add_hcap_form( (string) $out, $module );
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/php/Brizy/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ private function init_hooks() {
/**
* Add captcha to the form.
*
* @param string $content Content of the current post.
* @param string|mixed $content Content of the current post.
* @param Brizy_Editor_Project $project Brizy project.
* @param WP_Post $post Post.
* @param string $type Type of the content.
*
* @return string|mixed
* @noinspection PhpUnusedParameterInspection
*/
public function add_captcha( string $content, Brizy_Editor_Project $project, WP_Post $post, string $type = '' ) {
public function add_captcha( $content, Brizy_Editor_Project $project, WP_Post $post, string $type = '' ) {
if ( 'body' !== $type ) {
return $content;
}
Expand All @@ -66,7 +67,7 @@ public function add_captcha( string $content, Brizy_Editor_Project $project, WP_
'</div>' .
$search;

return str_replace( $search, $replace, $content );
return str_replace( $search, $replace, (string) $content );
}

/**
Expand Down
15 changes: 8 additions & 7 deletions src/php/CF7/CF7.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,22 @@ public function init_hooks() {
/**
* Add hCaptcha to CF7 form.
*
* @param string $output Shortcode output.
* @param string|mixed $output Shortcode output.
* @param string $tag Shortcode name.
* @param array|string $attr Shortcode attributes array or empty string.
* @param array $m Regular expression match array.
*
* @return string
* @return string|mixed
* @noinspection PhpUnusedParameterInspection
*/
public function wpcf7_shortcode( string $output, string $tag, $attr, array $m ): string {
public function wpcf7_shortcode( $output, string $tag, $attr, array $m ) {
if ( 'contact-form-7' !== $tag ) {
return $output;
}

remove_filter( 'do_shortcode_tag', [ $this, 'wpcf7_shortcode' ], 20 );

$output = (string) $output;
$form_id = isset( $attr['id'] ) ? (int) $attr['id'] : 0;

if ( has_shortcode( $output, self::SHORTCODE ) ) {
Expand Down Expand Up @@ -178,13 +179,13 @@ class="<?php echo esc_attr( HCaptcha::HCAPTCHA_WIDGET_ID ); ?>"
/**
* Verify CF7 recaptcha.
*
* @param WPCF7_Validation $result Result.
* @param WPCF7_FormTag $tag Tag.
* @param WPCF7_Validation|mixed $result Result.
* @param WPCF7_FormTag $tag Tag.
*
* @return WPCF7_Validation
* @return WPCF7_Validation|mixed
* @noinspection PhpUnusedParameterInspection
*/
public function verify_hcaptcha( WPCF7_Validation $result, WPCF7_FormTag $tag ): WPCF7_Validation {
public function verify_hcaptcha( $result, WPCF7_FormTag $tag ) {
$submission = WPCF7_Submission::get_instance();

if ( null === $submission ) {
Expand Down
14 changes: 7 additions & 7 deletions src/php/ClassifiedListing/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ public function add_captcha() {
/**
* Verify login form.
*
* @param WP_Error $validation_error Validation error.
* @param string $email Email.
* @param string $username Username.
* @param string $password Password.
* @param array $post $_POST array.
* @param WP_Error|mixed $validation_error Validation error.
* @param string $email Email.
* @param string $username Username.
* @param string $password Password.
* @param array $post $_POST array.
*
* @return WP_Error
* @return WP_Error|mixed
* @noinspection PhpUnusedParameterInspection
*/
public function verify( WP_Error $validation_error, string $email, string $username, string $password, array $post ): WP_Error {
public function verify( $validation_error, string $email, string $username, string $password, array $post ) {
// phpcs:disable WordPress.Security.NonceVerification.Missing
$rtcl_register = isset( $_POST['rtcl-register'] ) ?
sanitize_text_field( wp_unslash( $_POST['rtcl-register'] ) ) :
Expand Down
2 changes: 1 addition & 1 deletion src/php/Divi/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private function init_hooks() {
* @noinspection PhpUndefinedFunctionInspection
*/
public function add_captcha( $output, string $module_slug ) {
if ( et_core_is_fb_enabled() || false !== strpos( $output, 'h-captcha' ) ) {
if ( ! is_string( $output ) || false !== strpos( $output, 'h-captcha' || et_core_is_fb_enabled() ) ) {
// Do not add captcha in frontend builder or if it already added by \HCaptcha\WP\Comment class.

return $output;
Expand Down
23 changes: 12 additions & 11 deletions src/php/Divi/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ private function init_hooks() {
* @noinspection PhpUnusedParameterInspection
* @noinspection PhpUndefinedFunctionInspection
*/
public function add_captcha( $output, $module_slug ) {
if ( et_core_is_fb_enabled() ) {
public function add_captcha( $output, string $module_slug ) {
if ( ! is_string( $output ) || et_core_is_fb_enabled() ) {
// Do not add captcha in frontend builder.

return $output;
Expand Down Expand Up @@ -116,14 +116,15 @@ public function add_captcha( $output, $module_slug ) {
* Verify hcaptcha.
* We use shortcode tag filter to make verification.
*
* @param false|string $return Short-circuit return value. Either false or the value to replace the shortcode with.
* @param string|false $return Short-circuit return value. Either false or the value to replace the shortcode with.
* @param string $tag Shortcode name.
* @param array|string $attr Shortcode attributes array or empty string.
* @param array $m Regular expression match array.
*
* @return string|false
* @noinspection PhpUnusedParameterInspection
*/
public function verify( $return, $tag, $attr, $m ) {
public function verify( $return, string $tag, $attr, array $m ) {
if ( self::TAG !== $tag ) {
return $return;
}
Expand Down Expand Up @@ -169,17 +170,17 @@ static function ( $item ) {
/**
* Filters Module Props.
*
* @param array $props Array of processed props.
* @param array $attrs Array of original shortcode attrs.
* @param string $slug Module slug.
* @param string $_address Module Address.
* @param string $content Module content.
* @param array|mixed $props Array of processed props.
* @param array $attrs Array of original shortcode attrs.
* @param string $slug Module slug.
* @param string $_address Module Address.
* @param string $content Module content.
*
* @return array
* @return array|mixed
*
* @noinspection PhpUnusedParameterInspection
*/
public function shortcode_attributes( $props, $attrs, $slug, $_address, $content ): array {
public function shortcode_attributes( $props, array $attrs, string $slug, string $_address, string $content ) {
if ( self::TAG !== $slug ) {
return $props;
}
Expand Down
10 changes: 5 additions & 5 deletions src/php/Divi/EmailOptin.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ protected function init_hooks() {
/**
* Add hCaptcha to the email optin form.
*
* @param string $html Submit button html.
* @param string $single_name_field Whether a single name field is being used.
* Only applicable when "$field" is 'name'.
* @param string|mixed $html Submit button html.
* @param string $single_name_field Whether a single name field is being used.
* Only applicable when "$field" is 'name'.
*
* @return string
* @noinspection PhpUnusedParameterInspection
*/
public function add_captcha( string $html, string $single_name_field ): string {
public function add_captcha( $html, string $single_name_field ): string {
$args = [
'action' => self::ACTION,
'name' => self::NONCE,
Expand All @@ -69,7 +69,7 @@ public function add_captcha( string $html, string $single_name_field ): string {
$replace = HCaptcha::form( $args ) . "\n" . $search;

// Insert hCaptcha.
return str_replace( $search, $replace, $html );
return str_replace( $search, $replace, (string) $html );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/php/Divi/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ protected function init_hooks() {
* @param string|string[] $output Module output.
* @param string $module_slug Module slug.
*
* @return string
* @return string|string[]
* @noinspection PhpUnusedParameterInspection
* @noinspection PhpUndefinedFunctionInspection
*/
public function add_captcha( $output, string $module_slug ) {
if ( et_core_is_fb_enabled() ) {
if ( ! is_string( $output ) || et_core_is_fb_enabled() ) {
// Do not add captcha in frontend builder.

return $output;
Expand Down
Loading

0 comments on commit 899aa44

Please sign in to comment.