Skip to content

Commit

Permalink
Use PHP 7 new features.
Browse files Browse the repository at this point in the history
  • Loading branch information
kagg-design committed Jul 19, 2023
1 parent 9b4ef71 commit 2c2065f
Show file tree
Hide file tree
Showing 68 changed files with 201 additions and 180 deletions.
12 changes: 6 additions & 6 deletions src/php/ACFE/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function init_hooks() {
*
* @return void
*/
public function before_fields( $args ) {
public function before_fields( array $args ) {
$this->form_id = $args['ID'];
}

Expand All @@ -71,7 +71,7 @@ public function before_fields( $args ) {
* @return void
* @noinspection PhpUndefinedFunctionInspection
*/
public function remove_recaptcha_render( $field ) {
public function remove_recaptcha_render( array $field ) {
if ( ! $this->is_recaptcha( $field ) ) {
return;
}
Expand All @@ -88,7 +88,7 @@ public function remove_recaptcha_render( $field ) {
*
* @return void
*/
public function add_hcaptcha( $field ) {
public function add_hcaptcha( array $field ) {
if ( ! $this->is_recaptcha( $field ) ) {
return;
}
Expand Down Expand Up @@ -122,7 +122,7 @@ public function add_hcaptcha( $field ) {
* @noinspection PhpUnusedParameterInspection
* @noinspection PhpUndefinedFunctionInspection
*/
public function remove_recaptcha_verify( $valid, $value, $field, $input ): bool {
public function remove_recaptcha_verify( bool $valid, string $value, array $field, string $input ): bool {
$recaptcha = acf_get_field_type( 'acfe_recaptcha' );

remove_filter( self::VALIDATION_HOOK, [ $recaptcha, 'validate_value' ] );
Expand All @@ -141,7 +141,7 @@ public function remove_recaptcha_verify( $valid, $value, $field, $input ): bool
* @return bool
* @noinspection PhpUnusedParameterInspection
*/
public function verify( $valid, $value, $field, $input ): bool {
public function verify( bool $valid, string $value, array $field, string $input ): bool {
if ( ! $field['required'] ) {
return $valid;
}
Expand Down Expand Up @@ -185,7 +185,7 @@ public function enqueue_scripts() {
*
* @return bool
*/
private function is_recaptcha( $field ): bool {
private function is_recaptcha( array $field ): bool {
return isset( $field['type'] ) && 'acfe_recaptcha' === $field['type'];
}
}
4 changes: 2 additions & 2 deletions src/php/Abstracts/LoginBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function init_hooks() {
* @return void
* @noinspection PhpUnusedParameterInspection
*/
public function login( $user_login, $user ) {
public function login( string $user_login, WP_User $user ) {
unset( $this->login_data[ $this->ip ] );

update_option( self::LOGIN_DATA, $this->login_data );
Expand All @@ -85,7 +85,7 @@ public function login( $user_login, $user ) {
* @return void
* @noinspection PhpUnusedParameterInspection
*/
public function login_failed( $username, $error = null ) {
public function login_failed( string $username, WP_Error $error = null ) {
$this->login_data[ $this->ip ][] = time();

update_option( self::LOGIN_DATA, $this->login_data );
Expand Down
2 changes: 1 addition & 1 deletion src/php/Abstracts/LostPasswordBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function add_captcha() {
*
* @return void
*/
public function verify( $error ) {
public function verify( WP_Error $error ) {
// phpcs:disable WordPress.Security.NonceVerification.Missing
$post_value = isset( $_POST[ static::POST_KEY ] ) ?
sanitize_text_field( wp_unslash( $_POST[ static::POST_KEY ] ) ) :
Expand Down
4 changes: 2 additions & 2 deletions src/php/Asgaros/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private function init_hooks() {
* @noinspection PhpUnusedParameterInspection
* @noinspection RegExpUnnecessaryNonCapturingGroup
*/
public function add_captcha( $output, $tag, $attr, $m ) {
public function add_captcha( string $output, string $tag, $attr, array $m ) {
if ( 'forum' !== $tag ) {
return $output;
}
Expand Down Expand Up @@ -77,7 +77,7 @@ public function add_captcha( $output, $tag, $attr, $m ) {
*
* @return bool
*/
public function verify( $verified ): bool {
public function verify( bool $verified ): bool {
global $asgarosforum;

$error_message = hcaptcha_get_verify_message(
Expand Down
20 changes: 10 additions & 10 deletions src/php/AutoVerify/AutoVerify.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private function init_hooks() {
*
* @return string
*/
public function content_filter( $content ): string {
public function content_filter( string $content ): string {
if ( ! $this->is_frontend() ) {
return $content;
}
Expand Down Expand Up @@ -182,7 +182,7 @@ private function is_cli(): bool {
*
* @param array $forms Forms found in the content.
*/
private function register_forms( $forms ) {
private function register_forms( array $forms ) {
$forms_data = [];

foreach ( $forms as $form ) {
Expand Down Expand Up @@ -210,7 +210,7 @@ private function register_forms( $forms ) {
*
* @return string
*/
private function get_form_action( $form ): string {
private function get_form_action( string $form ): string {
$form_action = '';

if ( preg_match( '#<form [\S\s]*?action="(.*?)"[\S\s]*?>#', $form, $m ) ) {
Expand All @@ -235,7 +235,7 @@ private function get_form_action( $form ): string {
*
* @return array
*/
private function get_visible_input_names( $form ): array {
private function get_visible_input_names( string $form ): array {
$names = [];

if ( ! preg_match_all( '#<input[\S\s]+?>#', $form, $matches ) ) {
Expand Down Expand Up @@ -266,7 +266,7 @@ private function get_visible_input_names( $form ): array {
*
* @return bool
*/
private function is_input_visible( $input ): bool {
private function is_input_visible( string $input ): bool {
return ! preg_match( '#type\s*?=\s*?["\']hidden["\']#', $input );
}
Expand All @@ -277,7 +277,7 @@ private function is_input_visible( $input ): bool {
*
* @return string|null
*/
private function get_input_name( $input ) {
private function get_input_name( string $input ) {
if ( preg_match( '#name\s*?=\s*?["\'](.+?)["\']#', $input, $matches ) ) {
return $matches[1];
}
Expand All @@ -292,7 +292,7 @@ private function get_input_name( $input ) {
*
* @return string|null
*/
private function get_form_auto( $form ) {
private function get_form_auto( string $form ) {
if ( preg_match( '#class="h-captcha"[\S\s]+?data-auto="(.*)"[\S\s]*?>#', $form, $matches ) ) {
return $matches[1];
}
Expand All @@ -307,7 +307,7 @@ private function get_form_auto( $form ) {
*
* @return bool
*/
private function is_form_auto( $form ): bool {
private function is_form_auto( string $form ): bool {
return 'true' === $this->get_form_auto( $form );
}

Expand All @@ -316,7 +316,7 @@ private function is_form_auto( $form ): bool {
*
* @param array $forms_data Forms data to update in transient.
*/
private function update_transient( $forms_data ) {
private function update_transient( array $forms_data ) {
$transient = get_transient( self::TRANSIENT );
$registered_forms = $transient ?: [];

Expand Down Expand Up @@ -359,7 +359,7 @@ private function update_transient( $forms_data ) {
*
* @return bool
*/
private function is_form_registered( $request_uri ): bool {
private function is_form_registered( string $request_uri ): bool {
$registered_forms = get_transient( self::TRANSIENT );

if ( empty( $registered_forms ) ) {
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 @@ -48,7 +48,7 @@ public function init_hooks() {
* @return void
* @noinspection PhpUnusedParameterInspection
*/
public function form_after_open( $args, $params ) {
public function form_after_open( array $args, array $params ) {
$this->form_id = isset( $params['id'] ) ? (int) $params['id'] : 0;
}

Expand All @@ -61,7 +61,7 @@ public function form_after_open( $args, $params ) {
* @return string
* @noinspection PhpUnusedParameterInspection
*/
public function add_hcaptcha( $html, $args ): string {
public function add_hcaptcha( string $html, array $args ): string {
if ( false === strpos( $html, '<button type="submit"' ) ) {
return $html;
}
Expand All @@ -83,7 +83,7 @@ public function add_hcaptcha( $html, $args ): string {
*
* @return bool|void
*/
public function verify( $demo_mode ) {
public function verify( bool $demo_mode ) {

// Nonce is checked by Avada.
// phpcs:disable WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Missing
Expand Down
6 changes: 3 additions & 3 deletions src/php/BackInStockNotifier/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function init_hooks() {
* @return void
* @noinspection PhpUnusedParameterInspection
*/
public function after_email_field( $product_id, $variation_id ) {
public function after_email_field( int $product_id, int $variation_id ) {
$this->form_id = $product_id;

ob_start();
Expand All @@ -80,7 +80,7 @@ public function after_email_field( $product_id, $variation_id ) {
* @return void
* @noinspection PhpUnusedParameterInspection
*/
public function after_submit_button( $product_id, $variation_id ) {
public function after_submit_button( int $product_id, int $variation_id ) {
$output = ob_get_clean();

$args = [
Expand Down Expand Up @@ -108,7 +108,7 @@ public function after_submit_button( $product_id, $variation_id ) {
*
* @return void
*/
public function verify( $post_data, $rest_api ) {
public function verify( array $post_data, bool $rest_api ) {

$hcaptcha_response = $post_data['h-captcha-response'] ?? '';

Expand Down
2 changes: 1 addition & 1 deletion src/php/BeaverBuilder/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function init_hooks() {
* @return string
* @noinspection PhpUnusedParameterInspection
*/
protected function add_hcap_form( $out, $module ): string {
protected function add_hcap_form( string $out, FLButtonModule $module ): string {
$form_id = false !== strpos( static::ACTION, 'login' ) ? 'login' : 'contact';
$args = [
'action' => static::ACTION,
Expand Down
4 changes: 2 additions & 2 deletions src/php/BeaverBuilder/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function init_hooks() {
* @return string
* @noinspection PhpUnusedParameterInspection
*/
public function add_hcaptcha( $out, $module ): string {
public function add_hcaptcha( string $out, FLButtonModule $module ): string {

// Process contact form only.
if ( false === strpos( $out, '<form class="fl-contact-form"' ) ) {
Expand All @@ -67,7 +67,7 @@ public function add_hcaptcha( $out, $module ): string {
* @return void
* @noinspection PhpUnusedParameterInspection
*/
public function verify( $mailto, $subject, $template, $headers, $settings ) {
public function verify( string $mailto, string $subject, string $template, array $headers, stdClass $settings ) {

$result = hcaptcha_verify_post( self::NONCE, self::ACTION );

Expand Down
4 changes: 2 additions & 2 deletions src/php/BeaverBuilder/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function init_hooks() {
*
* @return string
*/
public function add_hcaptcha( $out, $module ): string {
public function add_hcaptcha( string $out, FLButtonModule $module ): string {
if ( ! $this->is_login_limit_exceeded() ) {
return $out;
}
Expand Down Expand Up @@ -73,7 +73,7 @@ public function add_hcaptcha( $out, $module ): string {
* @return WP_User|WP_Error
* @noinspection PhpUnusedParameterInspection
*/
public function verify( $user, $password ) {
public function verify( $user, string $password ) {
// phpcs:ignore WordPress.Security.NonceVerification.Missing
$action = isset( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';

Expand Down
2 changes: 1 addition & 1 deletion src/php/Brizy/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private function init_hooks() {
*
* @noinspection PhpUnusedParameterInspection
*/
public function add_captcha( $content, $project, $post, $type = '' ) {
public function add_captcha( string $content, Brizy_Editor_Project $project, WP_Post $post, string $type = '' ) {
if ( 'body' !== $type ) {
return $content;
}
Expand Down
10 changes: 5 additions & 5 deletions src/php/CF7/CF7.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function init_hooks() {
* @return string
* @noinspection PhpUnusedParameterInspection
*/
public function wpcf7_shortcode( $output, $tag, $attr, $m ): string {
public function wpcf7_shortcode( string $output, string $tag, $attr, array $m ): string {
if ( 'contact-form-7' !== $tag ) {
return $output;
}
Expand Down Expand Up @@ -89,7 +89,7 @@ public function wpcf7_shortcode( $output, $tag, $attr, $m ): string {
* @return string
* @noinspection PhpUnusedParameterInspection
*/
public function cf7_hcaptcha_shortcode( $attr = [] ): string {
public function cf7_hcaptcha_shortcode( array $attr = [] ): string {
$settings = hcaptcha()->settings();
$hcaptcha_site_key = $settings->get_site_key();
$hcaptcha_theme = $settings->get( 'theme' );
Expand Down Expand Up @@ -183,7 +183,7 @@ class="<?php echo esc_attr( HCaptcha::HCAPTCHA_WIDGET_ID ); ?>"
* @return WPCF7_Validation
* @noinspection PhpUnusedParameterInspection
*/
public function verify_hcaptcha( $result, $tag ): WPCF7_Validation {
public function verify_hcaptcha( WPCF7_Validation $result, WPCF7_FormTag $tag ): WPCF7_Validation {
$submission = WPCF7_Submission::get_instance();

if ( null === $submission ) {
Expand All @@ -209,7 +209,7 @@ public function verify_hcaptcha( $result, $tag ): WPCF7_Validation {
*
* @return WPCF7_Validation
*/
private function get_invalidated_result( $result, $captcha_result = '' ): WPCF7_Validation {
private function get_invalidated_result( WPCF7_Validation $result, string $captcha_result = '' ): WPCF7_Validation {
if ( '' === $captcha_result ) {
$captcha_result = hcap_get_error_messages()['empty'];
}
Expand Down Expand Up @@ -253,7 +253,7 @@ public function enqueue_scripts() {
*
* @return string
*/
private function add_form_id_to_cf7_hcap_shortcode( $output, $form_id ): string {
private function add_form_id_to_cf7_hcap_shortcode( string $output, int $form_id ): string {
$cf7_hcap_sc_regex = get_shortcode_regex( [ self::SHORTCODE ] );

if ( ! preg_match( "/$cf7_hcap_sc_regex/", $output, $matches ) ) {
Expand Down
6 changes: 3 additions & 3 deletions src/php/ClassifiedListing/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private function init_hooks() {
* @return void
* @noinspection PhpUnusedParameterInspection
*/
public function before_template_part( $template_name, $located, $template_args ) {
public function before_template_part( string $template_name, string $located, array $template_args ) {
if ( 'listing/email-to-seller-form' !== $template_name ) {
return;
}
Expand All @@ -71,7 +71,7 @@ public function before_template_part( $template_name, $located, $template_args )
* @return void
* @noinspection PhpUnusedParameterInspection
*/
public function after_template_part( $template_name, $located, $template_args ) {
public function after_template_part( string $template_name, string $located, array $template_args ) {
if ( 'listing/email-to-seller-form' !== $template_name ) {
return;
}
Expand Down Expand Up @@ -104,7 +104,7 @@ public function after_template_part( $template_name, $located, $template_args )
* @return void
* @noinspection PhpUnusedParameterInspection
*/
public function verify( $error, $data ) {
public function verify( WP_Error $error, array $data ) {
$error_message = hcaptcha_verify_post(
static::NONCE,
static::ACTION
Expand Down
2 changes: 1 addition & 1 deletion src/php/ClassifiedListing/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function add_captcha() {
* @return WP_User|WP_Error
* @noinspection PhpUnusedParameterInspection
*/
public function verify( $user, $password ) {
public function verify( $user, string $password ) {
// phpcs:disable WordPress.Security.NonceVerification.Missing
$rtcl_login = isset( $_POST['rtcl-login'] ) ?
sanitize_text_field( wp_unslash( $_POST['rtcl-login'] ) ) :
Expand Down
2 changes: 1 addition & 1 deletion src/php/ClassifiedListing/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function add_captcha() {
* @return WP_Error
* @noinspection PhpUnusedParameterInspection
*/
public function verify( $validation_error, $email, $username, $password, $post ): WP_Error {
public function verify( WP_Error $validation_error, string $email, string $username, string $password, array $post ): WP_Error {
// 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/ColorlibCustomizer/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ public function login_head() {
*
* @return string
*/
abstract protected function get_style( $hcaptcha_size ): string;
abstract protected function get_style( string $hcaptcha_size ): string;
}
Loading

0 comments on commit 2c2065f

Please sign in to comment.