Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint PHP by removing unnecessary local vars #1316

Merged
merged 1 commit into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ function qtranxf_decode_json_name_value( $value ): ?array {
* @see qtranxf_collect_translations
*/
function qtranxf_collect_translations_posted() {
$edit_lang = null;
if ( isset( $_REQUEST['qtranslate-fields'] ) ) {
$edit_lang = qtranxf_get_edit_language();
foreach ( $_REQUEST['qtranslate-fields'] as $name => &$qfields ) {
Expand Down Expand Up @@ -454,7 +453,7 @@ function qtranxf_admin_footer() {
<?php
echo 'var qTranslateConfig=' . json_encode( $config ) . ';' . PHP_EOL;
// each script entry may define javascript code to be injected
foreach ( $page_config['js'] as $key => $js ) {
foreach ( $page_config['js'] as $js ) {
if ( isset( $js['javascript'] ) && ! empty( $js['javascript'] ) ) {
echo $js['javascript'];
}
Expand Down Expand Up @@ -787,9 +786,7 @@ function qtranxf_admin_home_url( $url, $path, $orig_scheme, $blog_id ) {
} else {
$lang = $q_config['default_language'];
}
$url = qtranxf_get_url_for_language( $url, $lang, ! $q_config['hide_default_language'] || $lang != $q_config['default_language'] );

return $url;
return qtranxf_get_url_for_language( $url, $lang, ! $q_config['hide_default_language'] || $lang != $q_config['default_language'] );
}

function qtranxf_admin_footer_text( $text ) {
Expand Down
2 changes: 1 addition & 1 deletion src/admin/admin_options_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ function qtranxf_reset_config(): void {
foreach ( $qtranslate_options['default_value'] as $nm => $def ) {
delete_option( 'qtranslate_' . $nm );
}
foreach ( $qtranslate_options['languages'] as $nm => $opn ) {
foreach ( $qtranslate_options['languages'] as $opn ) {
delete_option( $opn );
}

Expand Down
2 changes: 1 addition & 1 deletion src/admin/admin_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ private function add_general_section(): void {
<table id="qtranxs-enabled-languages">
<?php
$flag_location = qtranxf_flag_location();
foreach ( qtranxf_getSortedLanguages() as $key => $language ) {
foreach ( qtranxf_getSortedLanguages() as $language ) {
echo '<tr>';
echo '<td><label title="' . $q_config['language_name'][ $language ] . '"><input type="radio" name="default_language" value="' . $language . '"';
checked( $language, $q_config['default_language'] );
Expand Down
4 changes: 1 addition & 3 deletions src/admin/admin_taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,7 @@ function qtranxf_admin_list_cats( string $text ): string {
return $text;
}
$texts = qtranxf_split_blocks( $blocks );
$text = qtranxf_join_b( $texts ); // with closing tag

return $text;
return qtranxf_join_b( $texts ); // with closing tag
default:
return qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage( $text );
}
Expand Down
6 changes: 3 additions & 3 deletions src/admin/admin_utils_db.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ function qtranxf_split_database_file( string $ifp, array $languages_to_keep ): s
$lfh = fopen( $lfp, 'a+' );
if ( ! $lfh || ! $dfh ) {
fclose( $ifh );
foreach ( $files as $lang_file => &$file ) {
foreach ( $files as &$file ) {
if ( ! isset( $file['fh'] ) ) {
continue;
}
Expand Down Expand Up @@ -398,7 +398,7 @@ function qtranxf_split_database_file( string $ifp, array $languages_to_keep ): s
fputs( $files[ $lang ]['fh'], $ln . PHP_EOL );
}
} else {
foreach ( $files as $lang => &$file ) {
foreach ( $files as &$file ) {
fputs( $file['fh'], $s );
}
if ( $mfh ) {
Expand All @@ -407,7 +407,7 @@ function qtranxf_split_database_file( string $ifp, array $languages_to_keep ): s
}
}
fclose( $ifh );
foreach ( $files as $lang => &$file ) {
foreach ( $files as &$file ) {
fclose( $file['fh'] );
}
if ( $mfh ) {
Expand Down
8 changes: 2 additions & 6 deletions src/admin/block_editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ public function rest_prepare( WP_REST_Response $response, WP_Post $post, WP_REST
// TODO allow user to select editor lang with buttons
$editor_lang = $q_config['url_info']['language'];

$response = $this->select_raw_response_language( $response, $editor_lang );

return $response;
return $this->select_raw_response_language( $response, $editor_lang );
}

/**
Expand Down Expand Up @@ -159,9 +157,7 @@ public function rest_request_after_callbacks( $response, array $handler, WP_REST
return $response;
}

$response = $this->select_raw_response_language( $response, $editor_lang );

return $response;
return $this->select_raw_response_language( $response, $editor_lang );
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/date_time.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ function qxtranxf_intl_strftime( string $format, $timestamp = null, ?string $loc
}
}, $format );

$out = str_replace( '%%', '%', $out );

return $out;
return str_replace( '%%', '%', $out );
}

/**
Expand Down
12 changes: 3 additions & 9 deletions src/frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,7 @@ function qtranxf_translate_deep( $value, $lang ) {

return serialize( $value );
}
$lang_value = qtranxf_use_language( $lang, $value );

return $lang_value;
return qtranxf_use_language( $lang, $value );
} else if ( is_array( $value ) ) {
foreach ( $value as $k => $v ) {
$value[ $k ] = qtranxf_translate_deep( $v, $lang );
Expand Down Expand Up @@ -639,9 +637,7 @@ function qtranxf_get_attachment_image_attributes( $attr, $attachment = null, $si
function qtranxf_home_url( $url, $path, $orig_scheme, $blog_id ): string {
global $q_config;
$lang = $q_config['language'];
$url = qtranxf_get_url_for_language( $url, $lang, ! $q_config['hide_default_language'] || $lang != $q_config['default_language'] );

return $url;
return qtranxf_get_url_for_language( $url, $lang, ! $q_config['hide_default_language'] || $lang != $q_config['default_language'] );
}

function qtranxf_esc_html( $text ) {
Expand Down Expand Up @@ -836,9 +832,7 @@ function qtranxf_checkCanonical( string $redirect_url, string $requested_url ):
global $q_config;
$lang = $q_config['language'];
// fix canonical conflicts with language urls
$redirect_url_lang = qtranxf_convertURL( $redirect_url, $lang );

return $redirect_url_lang;
return qtranxf_convertURL( $redirect_url, $lang );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/language_blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function qtranxf_getAvailableLanguages( $text ) {
function qtranxf_allthesame( array $texts ): ?string {
$text = null;
// take first not empty
foreach ( $texts as $lang => $lang_text ) {
foreach ( $texts as $lang_text ) {
if ( ! $lang_text || $lang_text == '' ) {
continue;
}
Expand All @@ -190,7 +190,7 @@ function qtranxf_allthesame( array $texts ): ?string {
if ( empty( $text ) ) {
return '';
}
foreach ( $texts as $lang => $lang_text ) {
foreach ( $texts as $lang_text ) {
if ( $lang_text != $text ) {
return null;
}
Expand Down
12 changes: 3 additions & 9 deletions src/modules/gravity-forms/loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,27 +102,21 @@ public function gform_form_tag( string $tag ): string {
if ( ! $this->isEnabled() ) {
return $tag;
}
$tag = preg_replace_callback( "|action='([^']+)'|", array( &$this, 'gform_form_action_attribute' ), $tag );

return $tag;
return preg_replace_callback( "|action='([^']+)'|", array( &$this, 'gform_form_action_attribute' ), $tag );
}

public function gform_savecontinue_link( string $save_button, array $form ) {
if ( ! $this->isEnabled() ) {
return $save_button;
}
$save_button = $this->translate( $save_button );

return $save_button;
return $this->translate( $save_button );
}

public function gform_confirmation( $confirmation, $form, $lead, bool $ajax ) {
if ( ! $this->isEnabled() ) {
return $confirmation;
}
$confirmation = $this->translate( $confirmation );

return $confirmation;
return $this->translate( $confirmation );
}

public function gform_pre_send_email( array $email ): array {
Expand Down
4 changes: 1 addition & 3 deletions src/url.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ function qtranxf_convertURL( string $url = '', string $lang = '', bool $forceadm

$url = apply_filters( 'qtranslate_convert_url', $url, $lang );

$complete = qtranxf_get_url_for_language( $url, $lang, $showLanguage );

return $complete;
return qtranxf_get_url_for_language( $url, $lang, $showLanguage );
}

function qtranxf_convertURLs( $url, string $lang = '', bool $forceadmin = false, bool $showDefaultLanguage = false ) {
Expand Down